Skip to content

Simple implementation of Merkle tree data structure

License

Notifications You must be signed in to change notification settings

dmidem/merkle_tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple implementation of Merkle tree data structure.

Merkle tree is a binary tree where the leaves are hashes of the data items, and the internal nodes are hashes of the concatenation of their child nodes. The root node of the tree is the hash of the entire tree.

See the following links for more information on Merkle tree and how it is used:

https://en.wikipedia.org/wiki/Merkle_tree:

https://en.bitcoin.it/wiki/Merged_mining_specification#Merkle_Branch

http://bittorrent.org/beps/bep_0030.html

Example of usage:

use merkle_tree::{tree::MerkleTree, hasher::SdbmHasher};

type Tree = MerkleTree<SdbmHasher>;

let tree = Tree::from_data_items(["hello", "world"].iter());

let root_hash = tree.get_root().unwrap();

let proof = tree.get_proof(0).unwrap();
assert!(Tree::verify_proof(b"hello", root_hash, &proof));
assert!(!Tree::verify_proof(b"world", root_hash, &proof));
assert!(!Tree::verify_proof(b"fake", root_hash, &proof));

let proof = tree.get_proof(1).unwrap();
assert!(!Tree::verify_proof(b"hello", root_hash, &proof));
assert!(Tree::verify_proof(b"world", root_hash, &proof));
assert!(!Tree::verify_proof(b"fake", root_hash, &proof));

assert_eq!(tree.get_proof(2), None);

About

Simple implementation of Merkle tree data structure

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages