pub struct PartialSmt(/* private fields */);Expand description
A partial version of an Smt.
This type can track a subset of the key-value pairs of a full Smt and allows for updating
those pairs to compute the new root of the tree, as if the updates had been done on the full
tree. This is useful so that not all leaves have to be present and loaded into memory to compute
an update.
To facilitate this, a partial SMT requires that the merkle paths of every key-value pair are added to the tree. This means this pair is considered “tracked” and can be updated.
An important caveat is that only pairs whose merkle paths were added can be updated. Attempting
to update an untracked value will result in an error. See PartialSmt::insert for more
details.
Once a partial SMT has been constructed, its root is set in stone. All subsequently added proofs or merkle paths must match that root, otherwise an error is returned.
Implementations§
Source§impl PartialSmt
impl PartialSmt
Sourcepub fn new(root: Word) -> PartialSmt
pub fn new(root: Word) -> PartialSmt
Constructs a PartialSmt from a root.
All subsequently added proofs or paths must have the same root.
Sourcepub fn from_proofs<I>(proofs: I) -> Result<PartialSmt, MerkleError>where
I: IntoIterator<Item = SmtProof>,
pub fn from_proofs<I>(proofs: I) -> Result<PartialSmt, MerkleError>where
I: IntoIterator<Item = SmtProof>,
Instantiates a new PartialSmt by calling PartialSmt::add_proof for all SmtProofs
in the provided iterator.
If the provided iterator is empty, an empty PartialSmt is returned.
§Errors
Returns an error if:
- the roots of the provided proofs are not the same.
Sourcepub fn open(&self, key: &Word) -> Result<SmtProof, MerkleError>
pub fn open(&self, key: &Word) -> Result<SmtProof, MerkleError>
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.
§Errors
Returns an error if:
- the key is not tracked by this partial SMT.
Sourcepub fn get_leaf(&self, key: &Word) -> Result<SmtLeaf, MerkleError>
pub fn get_leaf(&self, key: &Word) -> Result<SmtLeaf, MerkleError>
Returns the leaf to which key maps
§Errors
Returns an error if:
- the key is not tracked by this partial SMT.
Sourcepub fn get_value(&self, key: &Word) -> Result<Word, MerkleError>
pub fn get_value(&self, key: &Word) -> Result<Word, MerkleError>
Returns the value associated with key.
§Errors
Returns an error if:
- the key is not tracked by this partial SMT.
Sourcepub fn insert(&mut self, key: Word, value: Word) -> Result<Word, MerkleError>
pub fn insert(&mut self, key: Word, value: Word) -> Result<Word, MerkleError>
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
Smt::EMPTY_VALUE.
This also recomputes all hashes between the leaf (associated with the key) and the root, updating the root itself.
§Errors
Returns an error if:
- the key and its merkle path were not previously added (using
PartialSmt::add_path) to thisPartialSmt, which means it is almost certainly incorrect to update its value. If an error is returned the tree is in the same state as before. - inserting the key-value pair would exceed
super::MAX_LEAF_ENTRIES(1024 entries) in the leaf.
Sourcepub fn add_proof(&mut self, proof: SmtProof) -> Result<(), MerkleError>
pub fn add_proof(&mut self, proof: SmtProof) -> Result<(), MerkleError>
Adds an SmtProof to this PartialSmt.
This is a convenience method which calls Self::add_path on the proof. See its
documentation for details on errors.
Sourcepub fn add_path(
&mut self,
leaf: SmtLeaf,
path: SparseMerklePath,
) -> Result<(), MerkleError>
pub fn add_path( &mut self, leaf: SmtLeaf, path: SparseMerklePath, ) -> Result<(), MerkleError>
Adds a leaf and its sparse merkle path to this PartialSmt.
If this function was called, any key that is part of the leaf can subsequently be updated
to a new value and produce a correct new tree root.
§Errors
Returns an error if:
- the new root after the insertion of the leaf and the path does not match the existing root. If an error is returned, the tree is left in an inconsistent state.
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 the PartialSmt.
Sourcepub fn inner_node_indices(&self) -> impl Iterator<Item = (NodeIndex, InnerNode)>
pub fn inner_node_indices(&self) -> impl Iterator<Item = (NodeIndex, InnerNode)>
Returns an iterator over the [InnerNode] and the respective NodeIndex of the
PartialSmt.
Sourcepub fn leaves(
&self,
) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::partial::{impl#0}::leaves::{constant#0}>, &SmtLeaf)>
pub fn leaves( &self, ) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::partial::{impl#0}::leaves::{constant#0}>, &SmtLeaf)>
Returns an iterator over the tracked, non-empty leaves of the PartialSmt in arbitrary
order.
Sourcepub fn tracked_leaves(
&self,
) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::partial::{impl#0}::tracked_leaves::{constant#0}>, &SmtLeaf)>
pub fn tracked_leaves( &self, ) -> impl Iterator<Item = (LeafIndex<miden_crypto::::merkle::smt::partial::{impl#0}::tracked_leaves::{constant#0}>, &SmtLeaf)>
Returns an iterator over the tracked leaves of the PartialSmt in arbitrary order.
Note that this includes empty leaves.
Sourcepub fn entries(&self) -> impl Iterator<Item = &(Word, Word)>
pub fn entries(&self) -> impl Iterator<Item = &(Word, Word)>
Returns an iterator over the tracked, non-empty key-value pairs of the PartialSmt in
arbitrary order.
Sourcepub fn num_leaves(&self) -> usize
pub fn num_leaves(&self) -> usize
Returns the number of tracked leaves in this tree, which includes empty ones.
Note that this may return a different value from Self::num_entries() as a single leaf may contain more than one key-value pair.
Sourcepub fn num_entries(&self) -> usize
pub fn num_entries(&self) -> usize
Returns the number of tracked, non-empty key-value pairs in this tree.
Note that this may return a different value from Self::num_leaves() as a single leaf may contain more than one key-value pair.
Sourcepub fn tracks_leaves(&self) -> bool
pub fn tracks_leaves(&self) -> bool
Returns a boolean value indicating whether the PartialSmt tracks any leaves.
Note that if a partial SMT does not track leaves, its root is not necessarily the empty SMT root, since it could have been constructed from a different root but without tracking any leaves.
Trait Implementations§
Source§impl Clone for PartialSmt
impl Clone for PartialSmt
Source§fn clone(&self) -> PartialSmt
fn clone(&self) -> PartialSmt
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PartialSmt
impl Debug for PartialSmt
Source§impl Default for PartialSmt
impl Default for PartialSmt
Source§fn default() -> PartialSmt
fn default() -> PartialSmt
Returns a new, empty PartialSmt.
All leaves in the returned tree are set to Smt::EMPTY_VALUE.
Source§impl Deserializable for PartialSmt
impl Deserializable for PartialSmt
Source§fn read_from<R>(source: &mut R) -> Result<PartialSmt, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<PartialSmt, 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>
impl Eq for PartialSmt
Source§impl From<Smt> for PartialSmt
impl From<Smt> for PartialSmt
Source§fn from(smt: Smt) -> PartialSmt
fn from(smt: Smt) -> PartialSmt
Source§impl PartialEq for PartialSmt
impl PartialEq for PartialSmt
Source§fn eq(&self, other: &PartialSmt) -> bool
fn eq(&self, other: &PartialSmt) -> bool
self and other values to be equal, and is used by ==.Source§impl Serializable for PartialSmt
impl Serializable for PartialSmt
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.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl StructuralPartialEq for PartialSmt
Source§impl TryFrom<PartialSmt> for PartialVault
impl TryFrom<PartialSmt> for PartialVault
Auto Trait Implementations§
impl Freeze for PartialSmt
impl RefUnwindSafe for PartialSmt
impl Send for PartialSmt
impl Sync for PartialSmt
impl Unpin for PartialSmt
impl UnsafeUnpin for PartialSmt
impl UnwindSafe for PartialSmt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more