Struct zk_kit_smt::smt::SMT

source ·
pub struct SMT { /* private fields */ }

Implementations§

source§

impl SMT

source

pub fn new(hash: HashFunction, big_numbers: bool) -> Self

Initializes a new instance of the Sparse Merkle Tree (SMT).

§Arguments
  • hash - The hash function used to hash the child nodes.
  • big_numbers - A flag indicating whether the SMT supports big numbers or not.
§Returns

A new instance of the SMT.

source

pub fn get(&self, key: Key) -> Option<Value>

Retrieves the value associated with the given key from the SMT.

§Arguments
  • key - The key to retrieve the value for.
§Returns

An Option containing the value associated with the key, or None if the key does not exist.

source

pub fn add(&mut self, key: Key, value: Value) -> Result<(), SMTError>

Adds a new key-value pair to the SMT.

It retrieves a matching entry or a zero node with a top-down approach and then it updates all the hashes of the nodes in the path of the new entry with a bottom up approach.

§Arguments
  • key - The key to add.
  • value - The value associated with the key.
§Returns

An Result indicating whether the operation was successful or not.

source

pub fn update(&mut self, key: Key, value: Value) -> Result<(), SMTError>

Updates the value associated with the given key in the SMT.

Also in this case, all the hashes of the nodes in the path of the updated entry are updated with a bottom up approach.

§Arguments
  • key - The key to update the value for.
  • value - The new value associated with the key.
§Returns

An Result indicating whether the operation was successful or not.

source

pub fn delete(&mut self, key: Key) -> Result<(), SMTError>

Deletes the key-value pair associated with the given key from the SMT.

Also in this case, all the hashes of the nodes in the path of the deleted entry are updated with a bottom up approach.

§Arguments
  • key - The key to delete.
§Returns

An Result indicating whether the operation was successful or not.

source

pub fn create_proof(&self, key: Key) -> MerkleProof

Creates a proof to prove the membership or the non-membership of a tree entry.

§Arguments
  • key - The key to create the proof for.
§Returns

A MerkleProof containing the proof information.

source

pub fn verify_proof(&self, merkle_proof: MerkleProof) -> bool

Verifies a membership or a non-membership proof for a given key in the SMT.

§Arguments
  • merkle_proof - The Merkle proof to verify.
§Returns

A boolean indicating whether the proof is valid or not.

Auto Trait Implementations§

§

impl Freeze for SMT

§

impl RefUnwindSafe for SMT

§

impl Send for SMT

§

impl Sync for SMT

§

impl Unpin for SMT

§

impl UnwindSafe for SMT

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.