#mpt #starknet #stark-net #key-value #trie #tree-root #merkle-patricia-trie

sn-merkle-trie

Minimal starknet merkle patricia trie implementation

1 unstable release

0.1.0 Sep 11, 2024

#777 in Algorithms

Download history 143/week @ 2024-09-06 51/week @ 2024-09-13 18/week @ 2024-09-20 37/week @ 2024-09-27 12/week @ 2024-10-04 11/week @ 2024-10-11 4/week @ 2024-10-18 33/week @ 2024-10-25 25/week @ 2024-11-01

75 downloads per month
Used in 2 crates (via sn-trie-proofs)

Custom license

45KB
844 lines

sn-merkle-trie

Crates.io Documentation License: MIT

Minimal implelementation of a StarkNet MPT.

Heavily rely on pathfinder's merkle tree implementation, but target to make it easy port as external dependency + sync primitives with type-rs.

Usage

  • tx trie

fn main() {
    // transaction tree either pedersen or poseidon
    let mut tree = TransactionMerkleTree::Pedersen(MerkleTree::default());
    let key1 = from_felt_to_bits(&Felt::from_hex_unchecked("0x0")); // 0b01
    let value_1 = Felt::from_hex_unchecked("0x2");
    // insert key and value
    tree.set(key1.clone(), value_1).unwrap();
    // commit tree to get root
    let (root, root_idx) = tree.commit().unwrap();
    // get proof of inclusion/non-inclusion
    let proof = tree.get_proof(root_idx, key1.clone()).unwrap().unwrap();
    // verify return membership proof
    let mem = tree.verify_proof(root, &key1, value_1, &proof);
}

Dependencies

~4.5MB
~86K SLoC