Skip to content

Commit 45970c2

Browse files
committed
fix(rust): Interpret max_depth in proof specs as 128 if left to 0
1 parent 6302484 commit 45970c2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

rust/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ mod verify;
1414
mod ics23 {
1515
include!("cosmos.ics23.v1.rs");
1616

17+
impl ProofSpec {
18+
pub const DEFAULT_MAX_DEPTH: i32 = 128;
19+
}
20+
1721
#[cfg(feature = "serde")]
1822
include!("cosmos.ics23.v1.serde.rs");
1923
}

rust/src/verify.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use anyhow::{bail, ensure};
99
use crate::api::{ensure_inner_prefix, ensure_leaf_prefix};
1010
use crate::helpers::Result;
1111
use crate::host_functions::HostFunctionsProvider;
12-
use crate::ics23;
1312
use crate::ops::do_hash;
1413
use crate::ops::{apply_inner, apply_leaf};
14+
use crate::{ics23, ProofSpec};
1515

1616
pub type CommitmentRoot = Vec<u8>;
1717

@@ -118,6 +118,13 @@ fn check_existence_spec(proof: &ics23::ExistenceProof, spec: &ics23::ProofSpec)
118118
if let (Some(leaf), Some(leaf_spec)) = (&proof.leaf, &spec.leaf_spec) {
119119
ensure_leaf_prefix(&leaf.prefix, spec)?;
120120
ensure_leaf(leaf, leaf_spec)?;
121+
122+
let max_depth = if spec.max_depth == 0 {
123+
ProofSpec::DEFAULT_MAX_DEPTH
124+
} else {
125+
spec.max_depth
126+
};
127+
121128
// ensure min/max depths
122129
if spec.min_depth != 0 {
123130
ensure!(
@@ -126,7 +133,7 @@ fn check_existence_spec(proof: &ics23::ExistenceProof, spec: &ics23::ProofSpec)
126133
proof.path.len(),
127134
);
128135
ensure!(
129-
proof.path.len() <= spec.max_depth as usize,
136+
proof.path.len() <= max_depth as usize,
130137
"Too many InnerOps: {}",
131138
proof.path.len(),
132139
);

0 commit comments

Comments
 (0)