pub struct SimpleSmt { /* private fields */ }
Expand description

A sparse Merkle tree with 64-bit keys and 4-element leaf values, without compaction.

The root of the tree is recomputed on each new leaf update.

Implementations§

source§

impl SimpleSmt

source

pub const MIN_DEPTH: u8 = 1u8

Minimum supported depth.

source

pub const MAX_DEPTH: u8 = 64u8

Maximum supported depth.

source

pub const EMPTY_VALUE: [BaseElement; 4] = super::EMPTY_WORD

Value of an empty leaf.

source

pub fn new(depth: u8) -> Result<SimpleSmt, MerkleError>

Returns a new SimpleSmt instantiated with the specified depth.

All leaves in the returned tree are set to [ZERO; 4].

Errors

Returns an error if the depth is 0 or is greater than 64.

source

pub fn with_leaves<R, I>( depth: u8, entries: R ) -> Result<SimpleSmt, MerkleError>where R: IntoIterator<IntoIter = I>, I: Iterator<Item = (u64, [BaseElement; 4])> + ExactSizeIterator,

Returns a new SimpleSmt instantiated with the specified depth and with leaves set as specified by the provided entries.

All leaves omitted from the entries list are set to [ZERO; 4].

Errors

Returns an error if:

  • If the depth is 0 or is greater than 64.
  • The number of entries exceeds the maximum tree capacity, that is 2^{depth}.
  • The provided entries contain multiple values for the same key.
source

pub const fn root(&self) -> RpoDigest

Returns the root of this Merkle tree.

source

pub const fn depth(&self) -> u8

Returns the depth of this Merkle tree.

source

pub fn get_node(&self, index: NodeIndex) -> Result<RpoDigest, MerkleError>

Returns a node at the specified index.

Errors

Returns an error if the specified index has depth set to 0 or the depth is greater than the depth of this Merkle tree.

source

pub fn get_leaf(&self, index: u64) -> Result<[BaseElement; 4], MerkleError>

Returns a value of the leaf at the specified index.

Errors

Returns an error if the index is greater than the maximum tree capacity, that is 2^{depth}.

source

pub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>

Returns a Merkle path from the node at the specified index to the root.

The node itself is not included in the path.

Errors

Returns an error if the specified index has depth set to 0 or the depth is greater than the depth of this Merkle tree.

source

pub fn get_leaf_path(&self, index: u64) -> Result<MerklePath, MerkleError>

Return a Merkle path from the leaf at the specified index to the root.

The leaf itself is not included in the path.

Errors

Returns an error if the index is greater than the maximum tree capacity, that is 2^{depth}.

source

pub fn leaves(&self) -> impl Iterator<Item = (u64, &[BaseElement; 4])>

Returns an iterator over the leaves of this SimpleSmt.

source

pub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo>

Returns an iterator over the inner nodes of this Merkle tree.

source

pub fn update_leaf( &mut self, index: u64, value: [BaseElement; 4] ) -> Result<[BaseElement; 4], MerkleError>

Updates value of the leaf at the specified index returning the old leaf value.

This also recomputes all hashes between the leaf and the root, updating the root itself.

Errors

Returns an error if the index is greater than the maximum tree capacity, that is 2^{depth}.

Trait Implementations§

source§

impl Clone for SimpleSmt

source§

fn clone(&self) -> SimpleSmt

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 SimpleSmt

source§

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

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

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

source§

fn from(value: &SimpleSmt) -> MerkleStore<T>

Converts to this type from the input type.
source§

impl PartialEq for SimpleSmt

source§

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

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

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

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

impl TryApplyDiff<RpoDigest, StoreNode> for SimpleSmt

§

type Error = MerkleError

An error type that can be returned if the changes cannot be applied.
§

type DiffType = MerkleTreeDelta

The type that describes the difference between two objects.
source§

fn try_apply(&mut self, diff: MerkleTreeDelta) -> Result<(), MerkleError>

Applies the provided changes described by Self::DiffType to the object implementing this trait. Returns an error if the changes cannot be applied.
source§

impl Eq for SimpleSmt

source§

impl StructuralEq for SimpleSmt

source§

impl StructuralPartialEq for SimpleSmt

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.