MerkleTreeTrait
MerkleTree trait defining operations for Merkle tree construction and verification.
Fully qualified path: alexandria_merkle_tree::merkle_tree::MerkleTreeTrait
#![allow(unused)] fn main() { pub trait MerkleTreeTrait<T> }
Trait functions
new
Create a new merkle tree instance.
Returns
MerkleTree<T>
- A new merkle tree with the specified hasher type
Fully qualified path: alexandria_merkle_tree::merkle_tree::MerkleTreeTrait::new
#![allow(unused)] fn main() { fn new() -> MerkleTree<T> }
compute_root
Compute the merkle root of a given proof by iteratively hashing with proof elements.
Arguments
self
- The merkle tree instancecurrent_node
- The starting leaf node (felt252 hash value)proof
- Array of sibling hashes needed to compute the root
Returns
felt252
- The computed merkle root hash
Fully qualified path: alexandria_merkle_tree::merkle_tree::MerkleTreeTrait::compute_root
#![allow(unused)] fn main() { fn compute_root(ref self: MerkleTree<T>, current_node: felt252, proof: Span<felt252>) -> felt252 }
verify
Verify that a leaf belongs to the merkle tree with the given root.
Arguments
self
- The merkle tree instanceroot
- The expected merkle root hashleaf
- The leaf value to verifyproof
- Array of sibling hashes for verification path
Returns
bool
- True if the leaf is valid for the given root, false otherwise
Fully qualified path: alexandria_merkle_tree::merkle_tree::MerkleTreeTrait::verify
#![allow(unused)] fn main() { fn verify(ref self: MerkleTree<T>, root: felt252, leaf: felt252, proof: Span<felt252>) -> bool }
compute_proof
Generate a merkle proof for a specific leaf at the given index. WARNING: This rebuilds the entire tree and is O(n) complexity. Use StoredMerkleTree for efficiency.
Arguments
self
- The merkle tree instanceleaves
- Array of all leaf values in the tree (will be sorted)index
- The index of the leaf to generate proof for
Returns
Span<felt252>
- Array of sibling hashes forming the merkle proof
Fully qualified path: alexandria_merkle_tree::merkle_tree::MerkleTreeTrait::compute_proof
#![allow(unused)] fn main() { fn compute_proof(ref self: MerkleTree<T>, leaves: Array<felt252>, index: u32) -> Span<felt252> }