Skip to content

Simple MerkleTree implementation to generate and validate proofs

License

Notifications You must be signed in to change notification settings

tmbobbins/merkle_tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merkle tree

Simple merkle tree implementation in rust for generating root hashes, proof and validating the proof

Prerequisites

  • Rust toolkit (1.62.1)

Usage

use merkle_tree::{Keccak256Tree, Keccak256Proof, Sha256, ToHash};
fn main() -> Result<(), Box<dyn std::error::Error>> { 
    let leaves = [
        Sha256::hash("0".as_bytes()), 
        Sha256::hash("1".as_bytes()), 
        Sha256::hash("2".as_bytes()), 
        Sha256::hash("3".as_bytes()), 
        Sha256::hash("4".as_bytes()), 
    ];
    
    let mut tree = Keccak256Tree::from_leaves(&leaves);
    let hash = tree.root_hash()?;
    let proof = tree.get_proof(leaves[3])?;
    
    let proof_validator = Keccak256Proof::new(proof);
    assert!(proof_validator.validate(hash, leaves[3]));
    
    Ok(())
}

Dependencies

sha3

dependency status

About

Simple MerkleTree implementation to generate and validate proofs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages