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.
Implementations§
Source§impl PartialSmt
impl PartialSmt
Sourcepub fn new() -> PartialSmt
pub fn new() -> PartialSmt
Returns a new PartialSmt.
All leaves in the returned tree are set to Smt::EMPTY_VALUE.
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_path for all SmtProofs
in the provided iterator.
§Errors
Returns an error if:
- the new root after the insertion of a (leaf, path) tuple does not match the existing root (except if the tree was previously empty).
Sourcepub fn open(&self, key: &RpoDigest) -> Result<SmtProof, MerkleError>
pub fn open(&self, key: &RpoDigest) -> 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: &RpoDigest) -> Result<SmtLeaf, MerkleError>
pub fn get_leaf(&self, key: &RpoDigest) -> 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: &RpoDigest,
) -> Result<[BaseElement; 4], MerkleError>
pub fn get_value( &self, key: &RpoDigest, ) -> Result<[BaseElement; 4], 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: RpoDigest,
value: [BaseElement; 4],
) -> Result<[BaseElement; 4], MerkleError>
pub fn insert( &mut self, key: RpoDigest, value: [BaseElement; 4], ) -> Result<[BaseElement; 4], 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.
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: MerklePath,
) -> Result<(), MerkleError>
pub fn add_path( &mut self, leaf: SmtLeaf, path: MerklePath, ) -> Result<(), MerkleError>
Adds a leaf and its 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 (except when the first leaf is added). 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 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 = &(RpoDigest, [BaseElement; 4])>
pub fn entries(&self) -> impl Iterator<Item = &(RpoDigest, [BaseElement; 4])>
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.
Also note that this is currently an expensive operation as counting the number of entries requires iterating over all leaves of the tree.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns a boolean value indicating whether the PartialSmt is empty.
Trait Implementations§
Source§impl Clone for PartialSmt
impl Clone for PartialSmt
Source§fn clone(&self) -> PartialSmt
fn clone(&self) -> PartialSmt
1.0.0 · 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
Source§impl PartialEq for PartialSmt
impl PartialEq for PartialSmt
impl Eq for PartialSmt
impl StructuralPartialEq for PartialSmt
Auto Trait Implementations§
impl Freeze for PartialSmt
impl RefUnwindSafe for PartialSmt
impl Send for PartialSmt
impl Sync for PartialSmt
impl Unpin 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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<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