Skip to content

Commit

Permalink
fix(rust): Interpret max_depth in proof specs as 128 if left to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Sep 18, 2024
1 parent 6302484 commit ec91661
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ mod verify;
mod ics23 {
include!("cosmos.ics23.v1.rs");

impl ProofSpec {
pub const DEFAULT_MAX_DEPTH: i32 = 128;
}

#[cfg(feature = "serde")]
include!("cosmos.ics23.v1.serde.rs");
}
Expand Down
9 changes: 8 additions & 1 deletion rust/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ fn check_existence_spec(proof: &ics23::ExistenceProof, spec: &ics23::ProofSpec)
if let (Some(leaf), Some(leaf_spec)) = (&proof.leaf, &spec.leaf_spec) {
ensure_leaf_prefix(&leaf.prefix, spec)?;
ensure_leaf(leaf, leaf_spec)?;

let max_depth = if spec.max_depth == 0 {
ics23::ProofSpec::DEFAULT_MAX_DEPTH
} else {
spec.max_depth
};

// ensure min/max depths
if spec.min_depth != 0 {
ensure!(
Expand All @@ -126,7 +133,7 @@ fn check_existence_spec(proof: &ics23::ExistenceProof, spec: &ics23::ProofSpec)
proof.path.len(),
);
ensure!(
proof.path.len() <= spec.max_depth as usize,
proof.path.len() <= max_depth as usize,
"Too many InnerOps: {}",
proof.path.len(),
);
Expand Down

0 comments on commit ec91661

Please sign in to comment.