Skip to content

Commit 1363533

Browse files
fix: apply default restrictions to max depth (#352)
* fix: apply fix, uncomment test * test: add test case * fix: tests * Update testdata/TestCheckAgainstSpecData.json Co-authored-by: Carlos Rodriguez <[email protected]> * chore: regen proto with comment * chore: add changelog * Update CHANGELOG.md * rm: rust proto_descriptor bin * add back rust bin --------- Co-authored-by: Carlos Rodriguez <[email protected]>
1 parent 6dbe7e3 commit 1363533

10 files changed

+692
-121
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# Unreleased
4+
5+
- fix(go): interpret max_depth in proof specs as 128 if left to 0 [#352](https://github.com/cosmos/ics23/pull/352).
6+
37
# 0.12.0
48

59
## Rust

go/fuzz_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func FuzzExistenceProofCheckAgainstSpec(f *testing.F) {
4848

4949
seedDataMap := CheckAgainstSpecTestData(f)
5050
for _, seed := range seedDataMap {
51-
if seed.IsErr {
51+
if seed.Err != "" {
5252
// Erroneous data, skip it.
5353
continue
5454
}

go/proof.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ func (p *ExistenceProof) CheckAgainstSpec(spec *ProofSpec) error {
190190
if spec.MinDepth > 0 && len(p.Path) < int(spec.MinDepth) {
191191
return fmt.Errorf("innerOps depth too short: %d", len(p.Path))
192192
}
193-
if spec.MaxDepth > 0 && len(p.Path) > int(spec.MaxDepth) {
193+
194+
maxDepth := spec.MaxDepth
195+
if maxDepth == 0 {
196+
maxDepth = 128
197+
}
198+
199+
if len(p.Path) > int(maxDepth) {
194200
return fmt.Errorf("innerOps depth too long: %d", len(p.Path))
195201
}
196202

go/proof_data_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func CheckLeafTestData(tb testing.TB) map[string]CheckLeafTestStruct {
5454
type CheckAgainstSpecTestStruct struct {
5555
Proof *ExistenceProof
5656
Spec *ProofSpec
57-
IsErr bool
57+
Err string
5858
}
5959

6060
func CheckAgainstSpecTestData(tb testing.TB) map[string]CheckAgainstSpecTestStruct {
@@ -70,6 +70,7 @@ func CheckAgainstSpecTestData(tb testing.TB) map[string]CheckAgainstSpecTestStru
7070
if err != nil {
7171
tb.Fatal(err)
7272
}
73+
7374
return cases
7475
}
7576

go/proof_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ func TestCheckLeaf(t *testing.T) {
4444
}
4545

4646
func TestCheckAgainstSpec(t *testing.T) {
47-
t.Skip()
4847
cases := CheckAgainstSpecTestData(t)
4948

5049
for name, tc := range cases {
5150
t.Run(name, func(t *testing.T) {
5251
err := tc.Proof.CheckAgainstSpec(tc.Spec)
53-
if tc.IsErr && err == nil {
54-
t.Fatal("Expected error, but got nil")
55-
} else if !tc.IsErr && err != nil {
52+
if tc.Err == "" && err != nil {
5653
t.Fatalf("Unexpected error: %v", err)
54+
} else if tc.Err != "" && tc.Err != err.Error() {
55+
t.Fatalf("Expected error: %s, got %s", tc.Err, err.Error())
5756
}
5857
})
5958
}

go/proofs.pb.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/cosmos/ics23/v1/proofs.proto

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ message ProofSpec {
163163
LeafOp leaf_spec = 1;
164164
InnerSpec inner_spec = 2;
165165
// max_depth (if > 0) is the maximum number of InnerOps allowed (mainly for fixed-depth tries)
166+
// the max_depth is interpreted as 128 if set to 0
166167
int32 max_depth = 3;
167168
// min_depth (if > 0) is the minimum number of InnerOps allowed (mainly for fixed-depth tries)
168169
int32 min_depth = 4;

rust/src/cosmos.ics23.v1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// *
23
/// ExistenceProof takes a key and a value and a set of steps to perform on it.
34
/// The result of peforming all these steps will provide a "root hash", which can
@@ -146,6 +147,7 @@ pub struct ProofSpec {
146147
#[prost(message, optional, tag = "2")]
147148
pub inner_spec: ::core::option::Option<InnerSpec>,
148149
/// max_depth (if > 0) is the maximum number of InnerOps allowed (mainly for fixed-depth tries)
150+
/// the max_depth is interpreted as 128 if set to 0
149151
#[prost(int32, tag = "3")]
150152
pub max_depth: i32,
151153
/// min_depth (if > 0) is the minimum number of InnerOps allowed (mainly for fixed-depth tries)

rust/src/proto_descriptor.bin

51 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)