miden_crypto::merkle

Struct Mmr

source
pub struct Mmr { /* private fields */ }
Expand description

A fully materialized Merkle Mountain Range, with every tree in the forest and all their elements.

Since this is a full representation of the MMR, elements are never removed and the MMR will grow roughly O(2n) in number of leaf elements.

Implementations§

source§

impl Mmr

source

pub fn new() -> Mmr

Constructor for an empty Mmr.

source

pub const fn forest(&self) -> usize

Returns the MMR forest representation.

The forest value has the following interpretations:

  • its value is the number of elements in the forest
  • bit count corresponds to the number of trees in the forest
  • each true bit position determines the depth of a tree in the forest
source

pub fn open( &self, pos: usize, target_forest: usize, ) -> Result<MmrProof, MmrError>

Given a leaf position, returns the Merkle path to its corresponding peak. If the position is greater-or-equal than the tree size an error is returned.

Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.

source

pub fn get(&self, pos: usize) -> Result<RpoDigest, MmrError>

Returns the leaf value at position pos.

Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.

source

pub fn add(&mut self, el: RpoDigest)

Adds a new element to the MMR.

source

pub fn peaks(&self, forest: usize) -> Result<MmrPeaks, MmrError>

Returns an peaks of the MMR for the version specified by forest.

source

pub fn get_delta( &self, from_forest: usize, to_forest: usize, ) -> Result<MmrDelta, MmrError>

Compute the required update to original_forest.

The result is a packed sequence of the authentication elements required to update the trees that have been merged together, followed by the new peaks of the Mmr.

source

pub fn inner_nodes(&self) -> MmrNodes<'_>

An iterator over inner nodes in the MMR. The order of iteration is unspecified.

Trait Implementations§

source§

impl Clone for Mmr

source§

fn clone(&self) -> Mmr

Returns a copy of the value. Read more
1.6.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Mmr

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Mmr

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: KvMap<RpoDigest, StoreNode>> From<&Mmr> for MerkleStore<T>

source§

fn from(value: &Mmr) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Mmr
where T: IntoIterator<Item = RpoDigest>,

source§

fn from(values: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Mmr

§

impl RefUnwindSafe for Mmr

§

impl Send for Mmr

§

impl Sync for Mmr

§

impl Unpin for Mmr

§

impl UnwindSafe for Mmr

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V