Skip to content

Commit

Permalink
Change Blake2bHasher default
Browse files Browse the repository at this point in the history
  • Loading branch information
spartucus committed May 16, 2023
1 parent 5739f3f commit 24877c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Blake2bHasher(Blake2b);
impl Default for Blake2bHasher {
fn default() -> Self {
let blake2b = Blake2bBuilder::new(BLAKE2B_LEN)
.personal(PERSONALIZATION)
.key(BLAKE2B_KEY)
// .personal(PERSONALIZATION)
// .key(BLAKE2B_KEY)
.build();
Blake2bHasher(blake2b)
}
Expand Down
33 changes: 32 additions & 1 deletion src/tests/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ proptest! {
}

#[test]
fn test_smt_multi_leaves_small((pairs, n) in leaves(1, 50)){
fn test_smt_multi_leaves_small((pairs, n) in leaves(1, 4)){
let smt = new_smt(pairs.clone());
let keys: Vec<_> = pairs.iter().take(n).map(|(k, _v)| *k).collect();
let proof = smt.merkle_proof(keys.clone()).expect("gen proof");
Expand All @@ -448,6 +448,37 @@ proptest! {
assert!(proof.verify::<Blake2bHasher>(smt.root(), data.clone()).expect("verify proof"));
assert!(compiled_proof.verify::<Blake2bHasher>(smt.root(), data.clone()).expect("verify compiled proof"));

use core::fmt::Write;
let proof: Vec<u8> = compiled_proof.clone().into();
let mut s = String::with_capacity(2 * proof.len());
for byte in proof.clone() {
write!(s, "{:02X}", byte)?;
}
println!("proof: {}", s);
let mut r = String::with_capacity(2 * 32);
for b in smt.root().as_slice() {
write!(r, "{:02X}", b)?;
}
println!("root: {}", r);
let mut le = vec![];
for lf in &data {
let mut l = String::with_capacity(2 * 32);
let mut r = String::with_capacity(2 * 32);

let lf0: [u8; 32] = lf.0.into();
for b in lf0 {
write!(l, "{:02X}", b)?;
}

let lf1: [u8; 32] = lf.1.into();
for b in lf1 {
write!(r, "{:02X}", b)?;
}

le.push((l, r));
}
println!("leaves: {:?}", le);

test_sub_proof(&compiled_proof, &smt, &data, 20);
}

Expand Down

0 comments on commit 24877c1

Please sign in to comment.