pub struct SparseMerkleTree<const BITS: u8>;Expand description
Sparse Merkle Tree variant that has hash-sized leaves, with most leaves being empty
(have value [0u8; 32]).
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 untractable), rather than the number of
non-empty leaves actually present.
Implementations§
Source§impl<const BITS: u8> SparseMerkleTree<BITS>
impl<const BITS: u8> SparseMerkleTree<BITS>
Sourcepub fn compute_root_only<'a, Iter>(
leaves: Iter,
) -> Option<[u8; ab_blake3::OUT_LEN]>where
Iter: IntoIterator<Item = Leaf<'a>> + 'a,
pub fn compute_root_only<'a, Iter>(
leaves: Iter,
) -> Option<[u8; ab_blake3::OUT_LEN]>where
Iter: IntoIterator<Item = Leaf<'a>> + '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; ab_blake3::OUT_LEN],
proof: &[[u8; ab_blake3::OUT_LEN]; _],
leaf_index: u128,
leaf: [u8; ab_blake3::OUT_LEN],
) -> bool
pub fn verify( root: &[u8; ab_blake3::OUT_LEN], proof: &[[u8; ab_blake3::OUT_LEN]; _], leaf_index: u128, leaf: [u8; ab_blake3::OUT_LEN], ) -> bool
Verify previously generated proof.
Leaf can either be leaf value for a leaf that is occupied or [0; 32] for a leaf that is
supposed to be empty.