Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Batched Proof for multiple openings and Path Pruning #130

Merged
merged 39 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aef2cd9
implemented multipath
intx4 Jan 15, 2024
9e54b60
reverted index logic in verify
intx4 Jan 15, 2024
bd8a30d
fixed compile errors
intx4 Jan 17, 2024
97deaf8
unittests passing
intx4 Jan 17, 2024
156d43c
changed signature of generate_multi_proof to sort indexes
intx4 Jan 17, 2024
4380907
cargo fmt
intx4 Jan 17, 2024
1bfb025
implemented unit test for multi_proof internals
intx4 Jan 17, 2024
561228a
renamed multi_proof specific test
intx4 Jan 17, 2024
6a24769
cargo fmt
intx4 Jan 17, 2024
804aa03
commnts in unittest
intx4 Jan 17, 2024
3766440
changed function signatures
intx4 Jan 17, 2024
ff2de46
cargo fmt
intx4 Jan 17, 2024
5548bd7
modified use of BtreeSet and HashMap from ark_std crate
intx4 Jan 18, 2024
d849e80
modified multipath to derivative(PartialEq...)
intx4 Jan 18, 2024
42a2f45
keep leaves as iterator in multipath verify
intx4 Jan 18, 2024
46a5377
auth_paths to peekable in multipath.verify
intx4 Jan 18, 2024
2eb01db
updated syntax for iterators in multipath.verify
intx4 Jan 18, 2024
7f5ac1d
updated syntax for iterators in multipath.verify
intx4 Jan 18, 2024
387e018
updated syntax for iterators in multipath.verify
intx4 Jan 18, 2024
decf749
shortend init for multipath
intx4 Jan 18, 2024
d08af2a
fixed build issues and implementing benches
intx4 Jan 18, 2024
e93e622
implemented benches for proof and multiproof
intx4 Jan 18, 2024
8ab9692
removed extra loop in decompress
intx4 Jan 18, 2024
0719d36
removed explicit decompress and merged decompression into multipath v…
intx4 Jan 18, 2024
e303028
removed multi_path.compress and merged compression step in generate_m…
intx4 Jan 19, 2024
3d6f9be
implemented prefix_decode_path
intx4 Jan 19, 2024
fe685f8
removed redundant code with new helper functions
intx4 Jan 19, 2024
aad2785
added doc for get_leaf_sibling_hash and made it pub. Renamed compute_…
intx4 Jan 19, 2024
76846e1
cargo fmt
intx4 Jan 22, 2024
13b2593
changed multiproof.verify to use "insert_with" instead of "insert" (t…
intx4 Jan 24, 2024
c4cd0af
cargo fmt
intx4 Jan 24, 2024
97e7d51
Merge branch 'main' into main
intx4 Feb 3, 2024
f036146
Merge remote-tracking branch 'upstream/main'
intx4 Feb 15, 2024
1537337
Use iterators in prefix_encode_path
Cesar199999 Mar 23, 2024
b400a40
Allow function-specific sample size in merkle tree benches
Cesar199999 Mar 23, 2024
2d28bcf
Merge pull request #1 from HungryCatsStudio/merkle-multiproofs-optimi…
intx4 Mar 25, 2024
6fdca79
removed redundant imports (nightly build tests)
intx4 Mar 25, 2024
98efb10
cargo fmt
intx4 Mar 25, 2024
d6059c6
nightly build fix
intx4 Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 152 additions & 2 deletions crypto-primitives/benches/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod bytes_mt_benches {
use ark_std::{test_rng, UniformRand};
use criterion::Criterion;
use std::borrow::Borrow;
use std::iter::zip;

use crate::NUM_LEAVES;

Expand Down Expand Up @@ -56,11 +57,160 @@ mod bytes_mt_benches {
});
}

pub fn merkle_tree_generate_proof(c: &mut Criterion) {
let mut rng = test_rng();
let leaves: Vec<_> = (0..NUM_LEAVES)
.map(|_| {
let rnd = BigInteger256::rand(&mut rng);
to_uncompressed_bytes!(rnd).unwrap()
})
.collect();
let leaf_crh_params = <LeafH as CRHScheme>::setup(&mut rng).unwrap();
let two_to_one_params = <CompressH as TwoToOneCRHScheme>::setup(&mut rng)
.unwrap()
.clone();

let tree = Sha256MerkleTree::new(
&leaf_crh_params.clone(),
&two_to_one_params.clone(),
&leaves,
)
.unwrap();
c.bench_function("Merkle Tree Generate Proof (Leaves as [u8])", move |b| {
b.iter(|| {
for (i, _) in leaves.iter().enumerate() {
tree.generate_proof(i).unwrap();
}
})
});
}

pub fn merkle_tree_verify_proof(c: &mut Criterion) {
let mut rng = test_rng();
let leaves: Vec<_> = (0..NUM_LEAVES)
.map(|_| {
let rnd = BigInteger256::rand(&mut rng);
to_uncompressed_bytes!(rnd).unwrap()
})
.collect();
let leaf_crh_params = <LeafH as CRHScheme>::setup(&mut rng).unwrap();
let two_to_one_params = <CompressH as TwoToOneCRHScheme>::setup(&mut rng)
.unwrap()
.clone();

let tree = Sha256MerkleTree::new(
&leaf_crh_params.clone(),
&two_to_one_params.clone(),
&leaves,
)
.unwrap();

let root = tree.root();

let proofs: Vec<_> = leaves
.iter()
.enumerate()
.map(|(i, _)| tree.generate_proof(i).unwrap())
.collect();

c.bench_function("Merkle Tree Verify Proof (Leaves as [u8])", move |b| {
b.iter(|| {
for (proof, leaf) in zip(proofs.clone(), leaves.clone()) {
proof
.verify(&leaf_crh_params, &two_to_one_params, &root, leaf.as_slice())
.unwrap();
}
})
});
}

pub fn merkle_tree_generate_multi_proof(c: &mut Criterion) {
let mut rng = test_rng();
let leaves: Vec<_> = (0..NUM_LEAVES)
.map(|_| {
let rnd = BigInteger256::rand(&mut rng);
to_uncompressed_bytes!(rnd).unwrap()
})
.collect();
let leaf_crh_params = <LeafH as CRHScheme>::setup(&mut rng).unwrap();
let two_to_one_params = <CompressH as TwoToOneCRHScheme>::setup(&mut rng)
.unwrap()
.clone();

let tree = Sha256MerkleTree::new(
&leaf_crh_params.clone(),
&two_to_one_params.clone(),
&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();
})
},
);
}

pub fn merkle_tree_verify_multi_proof(c: &mut Criterion) {
let mut rng = test_rng();
let leaves: Vec<_> = (0..NUM_LEAVES)
.map(|_| {
let rnd = BigInteger256::rand(&mut rng);
to_uncompressed_bytes!(rnd).unwrap()
})
.collect();
let leaf_crh_params = <LeafH as CRHScheme>::setup(&mut rng).unwrap();
let two_to_one_params = <CompressH as TwoToOneCRHScheme>::setup(&mut rng)
.unwrap()
.clone();

let tree = Sha256MerkleTree::new(
&leaf_crh_params.clone(),
&two_to_one_params.clone(),
&leaves,
)
.unwrap();

let root = tree.root();

let multi_proof = tree
.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())
})
},
);
}

criterion_group! {
name = mt_create;
config = Criterion::default().sample_size(10);
config = Criterion::default().sample_size(100);
targets = merkle_tree_create
}

criterion_group! {
name = mt_proof;
config = Criterion::default().sample_size(100);
targets = merkle_tree_generate_proof, merkle_tree_generate_multi_proof
}

criterion_group! {
name = mt_verify;
config = Criterion::default().sample_size(10);
targets = merkle_tree_verify_proof, merkle_tree_verify_multi_proof
}
}

criterion_main!(crate::bytes_mt_benches::mt_create,);
criterion_main!(
bytes_mt_benches::mt_create,
bytes_mt_benches::mt_proof,
bytes_mt_benches::mt_verify
);
Loading
Loading