pub struct SparseMerkleTree<const BITS: u8, H>(/* private fields */);Expand description
Sparse Merkle Tree variant that has hash-sized leaves, with most leaves being empty (all zeroes).
In contrast to a proper Balanced Merkle Tree, constant BITS here specifies the max number of
leaves hypothetically possible in a tree (2^BITS, often intractable), rather than the number of
non-empty leaves actually present.
Inner nodes are hashed with H (except when both children are empty), which is created with
Default since the number of leaves is always 2^BITS.
Implementations§
Source§impl<const BITS: u8, H> SparseMerkleTree<BITS, H>
impl<const BITS: u8, H> SparseMerkleTree<BITS, H>
Sourcepub fn compute_root_only<'a, Iter>(
leaves: Iter,
) -> Option<[u8; <H as MerkleHasher>::OUT_LEN]>where
H: 'a,
Iter: IntoIterator<Item = Leaf<'a, H>> + 'a,
pub fn compute_root_only<'a, Iter>(
leaves: Iter,
) -> Option<[u8; <H as MerkleHasher>::OUT_LEN]>where
H: 'a,
Iter: IntoIterator<Item = Leaf<'a, H>> + 'a,
Compute Merkle Tree root.
If provided iterator ends early, it means the rest of the leaves are empty.
There must be no Leaf::Occupied for empty/unoccupied leaves or else they may result in
invalid root, Leaf::Empty must be used instead.
Returns None if too many leaves were provided.
Sourcepub fn verify(
root: &[u8; <H as MerkleHasher>::OUT_LEN],
proof: &[[u8; <H as MerkleHasher>::OUT_LEN]; _],
leaf_index: u128,
leaf: [u8; <H as MerkleHasher>::OUT_LEN],
) -> bool
pub fn verify( root: &[u8; <H as MerkleHasher>::OUT_LEN], proof: &[[u8; <H as MerkleHasher>::OUT_LEN]; _], leaf_index: u128, leaf: [u8; <H as MerkleHasher>::OUT_LEN], ) -> bool
Verify previously generated proof.
Leaf can either be leaf value for a leaf that is occupied or all zeroes for a leaf that is supposed to be empty.