Skip to content

clabby/alloy-merkle-tree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alloy-merkle-tree

Minimal Merkle Tree implementation

  • type compatible with alloy-primitives
  • keccak hash as native hash
  • support features: insert, proof, verify

Quick Start

alloy-merkle-tree = { version = "0.1.0" }

Example

  • Insert
 let mut tree = MerkleTree::new();
// Should be 2 ^ N leaves
let num_leaves = 16;
for i in 0..num_leaves {
    tree.insert(B256::from(Uint::from(i)));
}
  • Finish finalize tree, meaning calculate root and layers
let mut tree = MerkleTree::new();
// fill elements with insertion
tree.finish();
  • Create Proof & Verify

Create proof is base on layer, so tree need to be finalized before.

let mut tree = MerkleTree::new();
// fill elements with insertion
tree.finish();
for i in 0..num_leaves {
    let proof = tree.create_proof(&B256::from(Uint::from(i))).unwrap();
    assert!(MerkleTree::verify_proof(&proof));
}

reference

About

Minimal Merkle Tree implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%