Function sway_libs::merkle::binary::verify_proof
pub fn verify_proof(
key: u64,
merkle_leaf: b256,
merkle_root: MerkleRoot,
num_leaves: u64,
proof: ProofSet,
) -> bool
Expand description
This function will take a Merkle leaf and proof and return whether the corresponding root
matches the root given.
Arguments
key
: [u64] - The key or index of the leaf to verify.merkle_leaf
: [b256] - The hash of a leaf on the Merkle Tree.merkle_root
: [MerkleRoot] - The pre-computed Merkle root that will be used to verify the leaf and proof.- ‘num_leaves’: [u64] - The number of leaves in the Merkle Tree.
proof
: [ProofSet] - The Merkle proof that will be used to traverse the Merkle Tree and compute a root.
Returns
- [bool] -
true
if the computed root matches the provided root, otherwise ‘false’.
Reverts
- When an incorrect proof length is provided.
- When there is one or no leaves and a proof is provided.
- When the key is greater than or equal to the number of leaves.
- When the computed height gets larger than the proof.
Examples
use sway_libs::merkle::{binary::verify_proof, common::{MerkleRoot, ProofSet}};
fn foo() {
let key = 0;
let leaf = b256::zero();
let num_leaves = 3;
let mut proof = ProofSet::new();
proof.push(0xb51fc5c7f5b6393a5b13bb6068de2247ac09df1d3b1bec17627502cb1d1a6ac6);
let root = 0xed84ee783dcb8999206160218e4fe8a1dc5ccb056e3b98f0a6fa633ca5896a47;
assert(verify_proof(key, leaf, root, num_leaves, proof) == true);
}