Skip to content

Commit

Permalink
implemented benches for proof and multiproof
Browse files Browse the repository at this point in the history
  • Loading branch information
intx4 committed Jan 18, 2024
1 parent d08af2a commit e93e622
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
30 changes: 18 additions & 12 deletions benches/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod bytes_mt_benches {
.collect();

c.bench_function("Merkle Tree Verify Proof (Leaves as [u8])", move |b| {
b.iter(move || {
b.iter(|| {
for (proof, leaf) in zip(proofs.clone(), leaves.clone()) {
proof
.verify(&leaf_crh_params, &two_to_one_params, &root, leaf.as_slice())
Expand Down Expand Up @@ -143,12 +143,15 @@ mod bytes_mt_benches {
&leaves,
)
.unwrap();
c.bench_function("Merkle Tree Generate Multi Proof (Leaves as [u8])", move |b| {
b.iter(|| {
tree.generate_multi_proof((0..leaves.len()).collect::<Vec<_>>())
.unwrap();
})
});
c.bench_function(
"Merkle Tree Generate Multi Proof (Leaves as [u8])",
move |b| {
b.iter(|| {
tree.generate_multi_proof((0..leaves.len()).collect::<Vec<_>>())
.unwrap();
})
},
);
}

pub fn merkle_tree_verify_multi_proof(c: &mut Criterion) {
Expand Down Expand Up @@ -177,11 +180,14 @@ mod bytes_mt_benches {
.generate_multi_proof((0..leaves.len()).collect::<Vec<_>>())
.unwrap();

c.bench_function("Merkle Tree Verify Multi Proof (Leaves as [u8])", move |b| {
b.iter(|| {
multi_proof.verify(&leaf_crh_params, &two_to_one_params, &root, leaves.clone())
})
});
c.bench_function(
"Merkle Tree Verify Multi Proof (Leaves as [u8])",
move |b| {
b.iter(|| {
multi_proof.verify(&leaf_crh_params, &two_to_one_params, &root, leaves.clone())
})
},
);
}

criterion_group! {
Expand Down
6 changes: 5 additions & 1 deletion src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<P: Config> MultiPath<P> {
// Incrementally reconstruct all the paths
let mut curr_path = self.auth_paths_suffixes[0].clone();
let mut auth_paths = (0..self.leaf_indexes.len())
.map(|_| Vec::new())
.map(|_| Vec::with_capacity(curr_path.len()))
.collect::<Vec<Vec<P::InnerDigest>>>();
auth_paths[0] = self.auth_paths_suffixes[0].clone();

Expand Down Expand Up @@ -611,6 +611,10 @@ impl<P: Config> MerkleTree<P> {
/// Returns a MultiPath (multiple authentication paths in compressed form, with Front Incremental Encoding),
/// from every leaf to root.
/// Note that for compression efficiency, the indexes are internally sorted.
/// For sorted indexes, MultiPath contains:
/// `2*( (num_leaves.log2()-1).pow(2) - (num_leaves.log2()-2) )`
/// instead of
/// `num_leaves*(num_leaves.log2()-1)`
/// When verifying the proof, leaves hashes should be supplied in order, that is:
/// let ordered_leaves: Vec<_> = self.leaf_indexes.into_iter().map(|i| leaves[i]).collect();
pub fn generate_multi_proof(
Expand Down

0 comments on commit e93e622

Please sign in to comment.