Struct SparseMerkleTree

Source
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>
where [(); { _ }]:,

Source

pub fn compute_root_only<'a, Iter>(leaves: Iter) -> Option<[u8; 32]>
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.

Source

pub fn verify( root: &[u8; 32], proof: &[[u8; 32]; { _ }], leaf_index: u128, leaf: [u8; 32], ) -> bool
where [(); { _ }]:,

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.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.