Skip to content

Efficient Merkle tree calculation function and state machine.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

rust-cc/rcmerkle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Version Latest Version

rcmerkle

Calculate the root of the Merkle Tree

Supported In Two ways:

  • Send all hashed lists in the old fashioned way.
  • Imagine you have 2^64 (18446744073709551616) data needs to be calculated, you might encounter the OOM problem. In order to solve that problem, we maintain a temporary state to store the previous calulation and it will simultaneously change from one step to the next step until it meets our goal.

Example:

use rcmerkle::{BetterMerkleTreeSHA256, Hash, MerkleTreeSHA256, SHA256};

let list = [
   "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
];
let hashed_list: Vec<SHA256> = list.iter().map(|v| SHA256::hash(v.as_bytes())).collect();

let mut better_merkle = BetterMerkleTreeSHA256::new();

for i in 0..hashed_list.len() {
   let root1 = MerkleTreeSHA256::root(hashed_list[0..i + 1].to_vec());
   let root2 = better_merkle.root(hashed_list[i].clone());
   assert_eq!(root1, root2);
}

License

This project is licensed under, it's your choice.

About

Efficient Merkle tree calculation function and state machine.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages