6 releases
0.3.3 | Jul 12, 2021 |
---|---|
0.3.2 | Jul 10, 2021 |
0.2.1 | Jul 9, 2021 |
0.1.0 | Jul 8, 2021 |
#1748 in Data structures
19KB
387 lines
Exclusion Complete Binary Merkle Tree
A merkle tree based on Nervos Complete Binary Merkle Tree to support verifiing a leaf is not on a certain tree.
Example Usage
type StrKey = &'static str;
type StrLeaf = SimpleLeaf<StrKey>;
type StrRangeLeaf = SimpleRangeLeaf<StrKey, Blake2bHasher>;
// A helper to compute root and build proof
type StrExCBMT = SimpleExclusionCBMT<StrKey, Blake2bHasher, MergeBlake2bH256>;
// Can be seen as a black list
let all_leaves: Vec<StrLeaf> = vec!["b", "e", "g", "x"]
.into_iter()
.map(StrLeaf::new_with_key)
.collect();
let root = StrExCBMT::compute_root(&all_leaves);
// The keys not in the black list
let excluded_keys = vec!["f", "y", "z", "a"];
let proof = StrExCBMT::build_proof(&all_leaves, &excluded_keys).unwrap();
assert_eq!(
proof
.range_leaves()
.iter()
.map(|l| (*l.key(), *l.next_key()))
.collect::<Vec<_>>(),
vec![("e", "g"), ("x", "b")]
);
assert!(proof
.verify_exclusion(&root, &excluded_keys)
.is_ok());
Dependencies
~23KB