Struct miden_crypto::merkle::SimpleSmt
source · 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
impl SimpleSmt
sourcepub const EMPTY_VALUE: Word = super::EMPTY_WORD
pub const EMPTY_VALUE: Word = super::EMPTY_WORD
Value of an empty leaf.
sourcepub fn new(depth: u8) -> Result<Self, MerkleError>
pub fn new(depth: u8) -> Result<Self, MerkleError>
sourcepub fn with_leaves<R, I>(depth: u8, entries: R) -> Result<Self, MerkleError>where
R: IntoIterator<IntoIter = I>,
I: Iterator<Item = (u64, Word)> + ExactSizeIterator,
pub fn with_leaves<R, I>(depth: u8, entries: R) -> Result<Self, MerkleError>where R: IntoIterator<IntoIter = I>, I: Iterator<Item = (u64, Word)> + 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.
sourcepub fn get_node(&self, index: NodeIndex) -> Result<RpoDigest, MerkleError>
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.
sourcepub fn get_leaf(&self, index: u64) -> Result<Word, MerkleError>
pub fn get_leaf(&self, index: u64) -> Result<Word, 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}.
sourcepub fn get_path(&self, index: NodeIndex) -> Result<MerklePath, MerkleError>
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.
sourcepub fn get_leaf_path(&self, index: u64) -> Result<MerklePath, MerkleError>
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}.
sourcepub fn leaves(&self) -> impl Iterator<Item = (u64, &Word)>
pub fn leaves(&self) -> impl Iterator<Item = (u64, &Word)>
Returns an iterator over the leaves of this SimpleSmt.
sourcepub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
pub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
Returns an iterator over the inner nodes of this Merkle tree.
sourcepub fn update_leaf(
&mut self,
index: u64,
value: Word
) -> Result<Word, MerkleError>
pub fn update_leaf( &mut self, index: u64, value: Word ) -> Result<Word, 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}.