Browse Source

Cargo fmt

master
howardwu 4 years ago
parent
commit
02e6b32d7d
1 changed files with 33 additions and 11 deletions
  1. +33
    -11
      crypto-primitives/benches/crypto_primitives/nizk.rs

+ 33
- 11
crypto-primitives/benches/crypto_primitives/nizk.rs

@ -1,11 +1,7 @@
#[macro_use] #[macro_use]
extern crate criterion; extern crate criterion;
use algebra::{
curves::bls12_377::Bls12_377,
fields::bls12_377::Fr,
Field,
};
use algebra::{curves::bls12_377::Bls12_377, fields::bls12_377::Fr, Field};
use crypto_primitives::nizk::*; use crypto_primitives::nizk::*;
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
@ -15,7 +11,7 @@ use rand::{thread_rng, Rng};
type TestProofSystem = Gm17<Bls12_377, Bench<Fr>, Fr>; type TestProofSystem = Gm17<Bls12_377, Bench<Fr>, Fr>;
struct Bench<F: Field> { struct Bench<F: Field> {
inputs: Vec<Option<F>>,
inputs: Vec<Option<F>>,
num_constraints: usize, num_constraints: usize,
} }
@ -40,8 +36,8 @@ impl ConstraintSynthesizer for Bench {
let new_entry = { let new_entry = {
let (input_1_val, input_1_var) = variables[i]; let (input_1_val, input_1_var) = variables[i];
let (input_2_val, input_2_var) = variables[i + 1]; let (input_2_val, input_2_var) = variables[i + 1];
let result_val = input_1_val
.and_then(|input_1| input_2_val.map(|input_2| input_1 * &input_2));
let result_val =
input_1_val.and_then(|input_1| input_2_val.map(|input_2| input_1 * &input_2));
let result_var = cs.alloc( let result_var = cs.alloc(
|| format!("Result {}", i), || format!("Result {}", i),
|| result_val.ok_or(SynthesisError::AssignmentMissing), || result_val.ok_or(SynthesisError::AssignmentMissing),
@ -70,7 +66,16 @@ fn gm17_setup(c: &mut Criterion) {
} }
c.bench_function("gm17_setup", move |b| { c.bench_function("gm17_setup", move |b| {
b.iter(|| TestProofSystem::setup(Bench::<Fr> { inputs: vec![None; num_inputs], num_constraints }, rng).unwrap())
b.iter(|| {
TestProofSystem::setup(
Bench::<Fr> {
inputs: vec![None; num_inputs],
num_constraints,
},
rng,
)
.unwrap()
})
}); });
} }
@ -83,10 +88,27 @@ fn gm17_prove(c: &mut Criterion) {
inputs.push(Some(rng.gen())); inputs.push(Some(rng.gen()));
} }
let params = TestProofSystem::setup(Bench::<Fr> { inputs: vec![None; num_inputs], num_constraints }, rng).unwrap();
let params = TestProofSystem::setup(
Bench::<Fr> {
inputs: vec![None; num_inputs],
num_constraints,
},
rng,
)
.unwrap();
c.bench_function("gm17_prove", move |b| { c.bench_function("gm17_prove", move |b| {
b.iter(|| TestProofSystem::prove(&params.0, Bench { inputs: inputs.clone(), num_constraints }, rng).unwrap())
b.iter(|| {
TestProofSystem::prove(
&params.0,
Bench {
inputs: inputs.clone(),
num_constraints,
},
rng,
)
.unwrap()
})
}); });
} }

Loading…
Cancel
Save