Struct miden_objects::crypto::merkle::Smt
source · pub struct Smt { /* private fields */ }Expand description
Sparse Merkle tree mapping 256-bit keys to 256-bit values. Both keys and values are represented by 4 field elements.
All leaves sit at depth 64. The most significant element of the key is used to identify the leaf to which the key maps.
A leaf is either empty, or holds one or more key-value pairs. An empty leaf hashes to the empty word. Otherwise, a leaf hashes to the hash of its key-value pairs, ordered by key first, value second.
Implementations§
source§impl Smt
impl Smt
sourcepub const EMPTY_VALUE: [BaseElement; 4] = _
pub const EMPTY_VALUE: [BaseElement; 4] = _
The default value used to compute the hash of empty leaves
sourcepub fn new() -> Smt
pub fn new() -> Smt
Returns a new Smt.
All leaves in the returned tree are set to Self::EMPTY_VALUE.
sourcepub fn with_entries(
entries: impl IntoIterator<Item = (RpoDigest, [BaseElement; 4])>
) -> Result<Smt, MerkleError>
pub fn with_entries( entries: impl IntoIterator<Item = (RpoDigest, [BaseElement; 4])> ) -> Result<Smt, MerkleError>
Returns a new Smt instantiated with leaves set as specified by the provided entries.
All leaves omitted from the entries list are set to Self::EMPTY_VALUE.
§Errors
Returns an error if the provided entries contain multiple values for the same key.
sourcepub fn get_value(&self, key: &RpoDigest) -> [BaseElement; 4]
pub fn get_value(&self, key: &RpoDigest) -> [BaseElement; 4]
Returns the value associated with key
sourcepub fn open(&self, key: &RpoDigest) -> SmtProof
pub fn open(&self, key: &RpoDigest) -> SmtProof
Returns an opening of the leaf associated with key. Conceptually, an opening is a Merkle
path to the leaf, as well as the leaf itself.
sourcepub fn leaves(
&self
) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::full::{impl#0}::leaves::{opaque#0}::{constant#0}>, &SmtLeaf)>
pub fn leaves( &self ) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::full::{impl#0}::leaves::{opaque#0}::{constant#0}>, &SmtLeaf)>
Returns an iterator over the leaves of this Smt.
sourcepub fn entries(&self) -> impl Iterator<Item = &(RpoDigest, [BaseElement; 4])>
pub fn entries(&self) -> impl Iterator<Item = &(RpoDigest, [BaseElement; 4])>
Returns an iterator over the key-value pairs of this Smt.
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 Smt.
sourcepub fn insert(
&mut self,
key: RpoDigest,
value: [BaseElement; 4]
) -> [BaseElement; 4]
pub fn insert( &mut self, key: RpoDigest, value: [BaseElement; 4] ) -> [BaseElement; 4]
Inserts a value at the specified key, returning the previous value associated with that key.
Recall that by definition, any key that hasn’t been updated is associated with
Self::EMPTY_VALUE.
This also recomputes all hashes between the leaf (associated with the key) and the root, updating the root itself.
Trait Implementations§
source§impl Deserializable for Smt
impl Deserializable for Smt
source§fn read_from<R>(source: &mut R) -> Result<Smt, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<Smt, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl<T> From<&Smt> for MerkleStore<T>
impl<T> From<&Smt> for MerkleStore<T>
source§fn from(value: &Smt) -> MerkleStore<T>
fn from(value: &Smt) -> MerkleStore<T>
source§impl Serializable for Smt
impl Serializable for Smt
source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.