2020-08-31 09:13:39 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
|
|
|
|
2018-03-06 09:21:30 -08:00
|
|
|
use bellman::groth16::*;
|
2020-07-01 13:26:54 -07:00
|
|
|
use bls12_381::Bls12;
|
2020-08-31 09:13:39 -07:00
|
|
|
use criterion::Criterion;
|
2019-08-15 09:40:07 -07:00
|
|
|
use ff::Field;
|
2020-07-01 13:26:54 -07:00
|
|
|
use group::Group;
|
2019-07-12 20:54:59 -07:00
|
|
|
use rand_core::{RngCore, SeedableRng};
|
|
|
|
use rand_xorshift::XorShiftRng;
|
2019-08-15 09:40:07 -07:00
|
|
|
use zcash_primitives::primitives::{Diversifier, ProofGenerationKey, ValueCommitment};
|
|
|
|
use zcash_proofs::circuit::sapling::Spend;
|
2018-03-06 09:21:30 -08:00
|
|
|
|
|
|
|
const TREE_DEPTH: usize = 32;
|
|
|
|
|
2020-08-31 09:13:39 -07:00
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
2020-09-08 16:07:51 -07:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
2019-07-11 05:46:47 -07:00
|
|
|
0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2018-03-06 09:21:30 -08:00
|
|
|
|
|
|
|
let groth_params = generate_random_parameters::<Bls12, _, _>(
|
2020-07-01 13:26:54 -07:00
|
|
|
Spend {
|
2018-03-27 07:03:02 -07:00
|
|
|
value_commitment: None,
|
|
|
|
proof_generation_key: None,
|
|
|
|
payment_address: None,
|
2018-03-06 09:21:30 -08:00
|
|
|
commitment_randomness: None,
|
2018-03-27 07:03:02 -07:00
|
|
|
ar: None,
|
2018-03-27 20:31:32 -07:00
|
|
|
auth_path: vec![None; TREE_DEPTH],
|
2019-08-15 09:40:07 -07:00
|
|
|
anchor: None,
|
2018-03-06 09:21:30 -08:00
|
|
|
},
|
2020-09-08 16:07:51 -07:00
|
|
|
&mut rng,
|
2019-08-15 09:40:07 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
2018-03-06 09:21:30 -08:00
|
|
|
|
2020-08-31 09:13:39 -07:00
|
|
|
c.bench_function("sapling", |b| {
|
2020-07-01 13:26:54 -07:00
|
|
|
let value_commitment = ValueCommitment {
|
2018-03-27 07:03:02 -07:00
|
|
|
value: 1,
|
2020-09-08 16:07:51 -07:00
|
|
|
randomness: jubjub::Fr::random(&mut rng),
|
2018-03-27 07:03:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let proof_generation_key = ProofGenerationKey {
|
2021-02-03 11:46:47 -08:00
|
|
|
ak: jubjub::SubgroupPoint::random(&mut rng),
|
|
|
|
nsk: jubjub::Fr::random(&mut rng),
|
2018-03-27 07:03:02 -07:00
|
|
|
};
|
|
|
|
|
2020-07-01 13:26:54 -07:00
|
|
|
let viewing_key = proof_generation_key.to_viewing_key();
|
2018-03-27 07:03:02 -07:00
|
|
|
|
|
|
|
let payment_address;
|
|
|
|
|
|
|
|
loop {
|
2019-07-11 05:46:47 -07:00
|
|
|
let diversifier = {
|
|
|
|
let mut d = [0; 11];
|
|
|
|
rng.fill_bytes(&mut d);
|
|
|
|
Diversifier(d)
|
|
|
|
};
|
2018-03-27 07:03:02 -07:00
|
|
|
|
2020-07-01 13:26:54 -07:00
|
|
|
if let Some(p) = viewing_key.to_payment_address(diversifier) {
|
2018-03-27 07:03:02 -07:00
|
|
|
payment_address = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 16:07:51 -07:00
|
|
|
let commitment_randomness = jubjub::Fr::random(&mut rng);
|
2020-07-01 13:26:54 -07:00
|
|
|
let auth_path =
|
2020-09-08 16:07:51 -07:00
|
|
|
vec![Some((bls12_381::Scalar::random(&mut rng), rng.next_u32() % 2 != 0)); TREE_DEPTH];
|
|
|
|
let ar = jubjub::Fr::random(&mut rng);
|
|
|
|
let anchor = bls12_381::Scalar::random(&mut rng);
|
2018-03-06 09:21:30 -08:00
|
|
|
|
2020-08-31 09:13:39 -07:00
|
|
|
b.iter(|| {
|
|
|
|
create_random_proof(
|
|
|
|
Spend {
|
|
|
|
value_commitment: Some(value_commitment.clone()),
|
|
|
|
proof_generation_key: Some(proof_generation_key.clone()),
|
|
|
|
payment_address: Some(payment_address.clone()),
|
|
|
|
commitment_randomness: Some(commitment_randomness),
|
|
|
|
ar: Some(ar),
|
|
|
|
auth_path: auth_path.clone(),
|
|
|
|
anchor: Some(anchor),
|
|
|
|
},
|
|
|
|
&groth_params,
|
2020-09-08 16:07:51 -07:00
|
|
|
&mut rng,
|
2020-08-31 09:13:39 -07:00
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
2018-03-06 09:21:30 -08:00
|
|
|
}
|
2020-08-31 09:13:39 -07:00
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
name = benches;
|
|
|
|
config = Criterion::default().sample_size(10);
|
|
|
|
targets = criterion_benchmark);
|
|
|
|
criterion_main!(benches);
|