Skip to main content

SparseMerkleTree

Struct SparseMerkleTree 

Source
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>
where [(); _]:, H: MerkleHasher + Default,

Source

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.

Source

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.

Trait Implementations§

Source§

impl<const BITS: u8, H: Debug> Debug for SparseMerkleTree<BITS, H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const BITS: u8, H> Forget for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> Freeze for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> RefUnwindSafe for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> Send for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> Sync for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> Unpin for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> UnsafeUnpin for SparseMerkleTree<BITS, H>

§

impl<const BITS: u8, H> UnwindSafe for SparseMerkleTree<BITS, H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.