miden_crypto::merkle

Struct PartialMmr

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

Partially materialized Merkle Mountain Range (MMR), used to efficiently store and update the authentication paths for a subset of the elements in a full MMR.

This structure store only the authentication path for a value, the value itself is stored separately.

Implementations§

source§

impl PartialMmr

source

pub fn from_peaks(peaks: MmrPeaks) -> Self

Returns a new PartialMmr instantiated from the specified peaks.

source

pub fn from_parts( peaks: MmrPeaks, nodes: BTreeMap<InOrderIndex, RpoDigest>, track_latest: bool, ) -> Self

Returns a new PartialMmr instantiated from the specified components.

This constructor does not check the consistency between peaks and nodes. If the specified peaks are nodes are inconsistent, the returned partial MMR may exhibit undefined behavior.

source

pub fn forest(&self) -> usize

Returns the current forest of this PartialMmr.

This value corresponds to the version of the PartialMmr and the number of leaves in the underlying MMR.

source

pub fn num_leaves(&self) -> usize

Returns the number of leaves in the underlying MMR for this PartialMmr.

source

pub fn peaks(&self) -> MmrPeaks

Returns the peaks of the MMR for this PartialMmr.

source

pub fn is_tracked(&self, pos: usize) -> bool

Returns true if this partial MMR tracks an authentication path for the leaf at the specified position.

source

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

Given a leaf position, returns the Merkle path to its corresponding peak, or None if this partial MMR does not track an authentication paths for the specified leaf.

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.

§Errors

Returns an error if the specified position is greater-or-equal than the number of leaves in the underlying MMR.

source

pub fn nodes(&self) -> impl Iterator<Item = (&InOrderIndex, &RpoDigest)>

Returns an iterator nodes of all authentication paths of this PartialMmr.

source

pub fn inner_nodes<'a, I: Iterator<Item = (usize, RpoDigest)> + 'a>( &'a self, leaves: I, ) -> impl Iterator<Item = InnerNodeInfo> + 'a

Returns an iterator over inner nodes of this PartialMmr for the specified leaves.

The order of iteration is not defined. If a leaf is not presented in this partial MMR it is silently ignored.

source

pub fn add( &mut self, leaf: RpoDigest, track: bool, ) -> Vec<(InOrderIndex, RpoDigest)>

Adds a new peak and optionally track it. Returns a vector of the authentication nodes inserted into this PartialMmr as a result of this operation.

When track is true the new leaf is tracked.

source

pub fn track( &mut self, leaf_pos: usize, leaf: RpoDigest, path: &MerklePath, ) -> Result<(), MmrError>

Adds the authentication path represented by MerklePath if it is valid.

The leaf_pos refers to the global position of the leaf in the MMR, these are 0-indexed values assigned in a strictly monotonic fashion as elements are inserted into the MMR, this value corresponds to the values used in the MMR structure.

The leaf corresponds to the value at leaf_pos, and path is the authentication path for that element up to its corresponding Mmr peak. The leaf is only used to compute the root from the authentication path to valid the data, only the authentication data is saved in the structure. If the value is required it should be stored out-of-band.

source

pub fn untrack(&mut self, leaf_pos: usize)

Removes a leaf of the PartialMmr and the unused nodes from the authentication path.

Note: leaf_pos corresponds to the position in the MMR and not on an individual tree.

source

pub fn apply( &mut self, delta: MmrDelta, ) -> Result<Vec<(InOrderIndex, RpoDigest)>, MmrError>

Applies updates to this PartialMmr and returns a vector of new authentication nodes inserted into the partial MMR.

Trait Implementations§

source§

impl Clone for PartialMmr

source§

fn clone(&self) -> PartialMmr

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

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

Performs copy-assignment from source. Read more
source§

impl Debug for PartialMmr

source§

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

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

impl Deserializable for PartialMmr

source§

fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
source§

impl From<&MmrPeaks> for PartialMmr

source§

fn from(peaks: &MmrPeaks) -> Self

Converts to this type from the input type.
source§

impl From<&PartialMmr> for MmrPeaks

source§

fn from(partial_mmr: &PartialMmr) -> Self

Converts to this type from the input type.
source§

impl From<MmrPeaks> for PartialMmr

source§

fn from(peaks: MmrPeaks) -> Self

Converts to this type from the input type.
source§

impl From<PartialMmr> for MmrPeaks

source§

fn from(partial_mmr: PartialMmr) -> Self

Converts to this type from the input type.
source§

impl PartialEq for PartialMmr

source§

fn eq(&self, other: &PartialMmr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serializable for PartialMmr

source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
source§

impl Eq for PartialMmr

source§

impl StructuralPartialEq for PartialMmr

Auto Trait Implementations§

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