Skip to main content

verify_path

Function verify_path 

Source
pub fn verify_path(
    leaf: &[u8; 32],
    path: &[[u8; 32]],
    leaf_index: usize,
    key_count: u32,
    expected_root: &[u8; 32],
) -> bool
Expand description

Verify an inclusion path against a commitment of size key_count.

leaf_index is the responder’s position of this leaf in the sorted leaf set; the commitment’s key_count comes from StorageCommitment.key_count. At each level of the path, if the current index is even, the current hash is the left child and we compute node_hash(self, sibling); otherwise it is the right child and we compute node_hash(sibling, self).

Returns true iff:

  • leaf_index < key_count (rejects out-of-range claims), AND
  • path.len() == ceil(log2(key_count)) for key_count > 1, or path.is_empty() for key_count == 1 (rejects wrong-shape paths before doing any hashing), AND
  • the recomputed root equals expected_root.