darkfi_sdk::crypto::smt::wasmdb

Type Alias SmtWasmFp

Source
pub type SmtWasmFp = SparseMerkleTree<'static, SMT_FP_DEPTH, { _ }, Base, PoseidonFp, SmtWasmDbStorage>;

Aliased Type§

struct SmtWasmFp {
    store: SmtWasmDbStorage,
    hasher: Poseidon<Fp, 2>,
    empty_nodes: &'static [Fp; 256],
}

Fields§

§store: SmtWasmDbStorage

A map from leaf indices to leaf data stored as field elements.

§hasher: Poseidon<Fp, 2>

The hasher used to build the Merkle tree.

§empty_nodes: &'static [Fp; 256]

An array of empty hashes hashed with themselves N times.

Implementations

Source§

impl<'a, const N: usize, const M: usize, F: FieldElement, H: FieldHasher<F, 2>, S: StorageAdapter<Value = F>> SparseMerkleTree<'a, N, M, F, H, S>

Source

pub fn new(store: S, hasher: H, empty_nodes: &'a [F; M]) -> Self

Creates a new SMT

Source

pub fn insert_batch(&mut self, leaves: Vec<(F, F)>) -> ContractResult

Takes a batch of field elements, inserts these hashes into the tree, and updates the Merkle root.

Source

pub fn remove_leaves(&mut self, leaves: Vec<(F, F)>) -> ContractResult

Source

pub fn root(&self) -> F

Returns the Merkle tree root.

Source

fn recompute_tree(&mut self, dirty_idxs: &mut Vec<BigUint>) -> ContractResult

Recomputes the Merkle tree depth first from the bottom of the tree

Source

pub fn prove_membership(&self, pos: &F) -> Path<N, F, H>

Give the path leading from the leaf at index up to the root. This is a “proof” in the sense of “valid path in a Merkle tree”, not a ZK argument.

Source

pub fn get_leaf(&self, pos: &F) -> F

Fast lookup for leaf. The SMT can be used as a generic container for objects with very little overhead using this method.

Source

fn get_node(&self, idx: &BigUint) -> F

Source

fn put_node(&mut self, key: BigUint, value: F) -> ContractResult

Source

fn remove_node(&mut self, key: &BigUint) -> ContractResult

Trait Implementations

Source§

impl<'a, const N: usize, const M: usize, F: Clone + FieldElement, H: Clone + FieldHasher<F, 2>, S: Clone + StorageAdapter<Value = F>> Clone for SparseMerkleTree<'a, N, M, F, H, S>

Source§

fn clone(&self) -> SparseMerkleTree<'a, N, M, F, H, S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, const N: usize, const M: usize, F: Debug + FieldElement, H: Debug + FieldHasher<F, 2>, S: Debug + StorageAdapter<Value = F>> Debug for SparseMerkleTree<'a, N, M, F, H, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more