Skip to main content

NullifierTreeBackend

Trait NullifierTreeBackend 

Source
pub trait NullifierTreeBackend: Sized {
    type Error: Error + Send + 'static;

    // Required methods
    fn num_entries(&self) -> usize;
    fn entries(&self) -> Box<dyn Iterator<Item = (Word, Word)> + '_>;
    fn open(&self, key: &Word) -> SmtProof;
    fn apply_mutations(
        &mut self,
        set: MutationSet<SMT_DEPTH, Word, Word>,
    ) -> Result<(), Self::Error>;
    fn compute_mutations(
        &self,
        updates: impl IntoIterator<Item = (Word, Word)>,
    ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>;
    fn insert(
        &mut self,
        key: Word,
        value: NullifierBlock,
    ) -> Result<NullifierBlock, Self::Error>;
    fn get_value(&self, key: &Word) -> NullifierBlock;
    fn root(&self) -> Word;
}
Expand description

This trait abstracts over different SMT backends (e.g., Smt and LargeSmt) to allow the NullifierTree to work with either implementation transparently.

Users should instantiate the backend directly (potentially with entries) and then pass it to NullifierTree::new_unchecked.

§Invariants

Assumes the provided SMT upholds the guarantees of the NullifierTree. Specifically:

  • Nullifiers are only spent once and their block numbers do not change.
  • Nullifier leaf values must be valid according to NullifierBlock.

Required Associated Types§

Source

type Error: Error + Send + 'static

Required Methods§

Source

fn num_entries(&self) -> usize

Returns the number of entries in the SMT.

Source

fn entries(&self) -> Box<dyn Iterator<Item = (Word, Word)> + '_>

Returns all entries in the SMT as an iterator over key-value pairs.

Source

fn open(&self, key: &Word) -> SmtProof

Opens the leaf at the given key, returning a Merkle proof.

Source

fn apply_mutations( &mut self, set: MutationSet<SMT_DEPTH, Word, Word>, ) -> Result<(), Self::Error>

Applies the given mutation set to the SMT.

Source

fn compute_mutations( &self, updates: impl IntoIterator<Item = (Word, Word)>, ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>

Computes the mutation set required to apply the given updates to the SMT.

Source

fn insert( &mut self, key: Word, value: NullifierBlock, ) -> Result<NullifierBlock, Self::Error>

Inserts a key-value pair into the SMT, returning the previous value at that key.

Source

fn get_value(&self, key: &Word) -> NullifierBlock

Returns the value associated with the given key.

Source

fn root(&self) -> Word

Returns the root of the SMT.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl NullifierTreeBackend for Smt

Source§

impl<Backend> NullifierTreeBackend for LargeSmt<Backend>
where Backend: SmtStorage,

Available on crate feature std only.