-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bowe-hopwood-size-check
- Loading branch information
Showing
12 changed files
with
186 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ Cargo.lock | |
params | ||
*.swp | ||
*.swo | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
|
||
static NUM_LEAVES: i32 = 1 << 20; | ||
|
||
mod bytes_mt_benches { | ||
use ark_crypto_primitives::crh::*; | ||
use ark_crypto_primitives::merkle_tree::*; | ||
use ark_crypto_primitives::to_uncompressed_bytes; | ||
use ark_ff::BigInteger256; | ||
use ark_serialize::CanonicalSerialize; | ||
use ark_std::{test_rng, UniformRand}; | ||
use criterion::Criterion; | ||
use std::borrow::Borrow; | ||
|
||
use crate::NUM_LEAVES; | ||
|
||
type LeafH = sha2::Sha256; | ||
type CompressH = sha2::Sha256; | ||
|
||
struct Sha256MerkleTreeParams; | ||
|
||
impl Config for Sha256MerkleTreeParams { | ||
type Leaf = [u8]; | ||
|
||
type LeafDigest = <LeafH as CRHScheme>::Output; | ||
type LeafInnerDigestConverter = ByteDigestConverter<Self::LeafDigest>; | ||
type InnerDigest = <CompressH as TwoToOneCRHScheme>::Output; | ||
|
||
type LeafHash = LeafH; | ||
type TwoToOneHash = CompressH; | ||
} | ||
type Sha256MerkleTree = MerkleTree<Sha256MerkleTreeParams>; | ||
|
||
pub fn merkle_tree_create(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(); | ||
c.bench_function("Merkle Tree Create (Leaves as [u8])", move |b| { | ||
b.iter(|| { | ||
Sha256MerkleTree::new( | ||
&leaf_crh_params.clone(), | ||
&two_to_one_params.clone(), | ||
&leaves, | ||
) | ||
.unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = mt_create; | ||
config = Criterion::default().sample_size(10); | ||
targets = merkle_tree_create | ||
} | ||
} | ||
|
||
criterion_main!(crate::bytes_mt_benches::mt_create,); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.