Skip to content

scroll-tech/zktrie-ng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zkTrie-ng

book docs CI Status

Full-featured zkTrie implementation in Rust.

Example

use zktrie_ng::{
    trie,
    hash::{
        key_hasher::NoCacheHasher,
        poseidon::Poseidon,
    },
    db::{HashMapDb, SledDb},
};

// A ZkTrie using Poseidon hash scheme,
// HashMap as backend kv database and NoCacheHasher as key hasher.
type ZkTrie = trie::ZkTrie<Poseidon, HashMapDb, NoCacheHasher>;
// Or you can store the zkTrie data in a sled database.
// type ZkTrie = trie::ZkTrie<Poseidon, SledDb, NoCacheHasher>;

fn main() {
    let mut trie = ZkTrie::new(HashMapDb::new(), NoCacheHasher);
    // or this is default mode
    // let mut trie = ZkTrie::default();

    trie.raw_update(&[1u8; 32], vec![[1u8; 32]], 1).unwrap();

    let values: [[u8; 32]; 1] = trie.get(&[1u8; 32]).unwrap();
    assert_eq!(values[0], [1u8; 32]);

    // zkTrie is lazy, won't update the backend database until `commit` is called.
    assert!(trie.is_dirty());

    trie.commit().unwrap();let mut trie = ZkTrie::new(HashMapDb::new(), NoCacheHasher);
    // or this is default mode
    // let mut trie = ZkTrie::default();

    trie.raw_update(&[1u8; 32], vec![[1u8; 32]], 1).unwrap();

    let values: [[u8; 32]; 1] = trie.get(&[1u8; 32]).unwrap();
    assert_eq!(values[0], [1u8; 32]);

    // zkTrie is lazy, won't update the backend database until `commit` is called.
    assert!(trie.is_dirty());

    trie.commit().unwrap();
}

Check the documentation for more details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages