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 45970c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
11 changes: 9 additions & 2 deletions rust/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use anyhow::{bail, ensure};
use crate::api::{ensure_inner_prefix, ensure_leaf_prefix};
use crate::helpers::Result;
use crate::host_functions::HostFunctionsProvider;
use crate::ics23;
use crate::ops::do_hash;
use crate::ops::{apply_inner, apply_leaf};
use crate::{ics23, ProofSpec};

pub type CommitmentRoot = Vec<u8>;

Expand Down 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 {
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 45970c2

Please sign in to comment.