|
|
@ -1,11 +1,7 @@ |
|
|
|
#[macro_use]
|
|
|
|
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 r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
|
|
|
|
|
|
|
@ -15,7 +11,7 @@ use rand::{thread_rng, Rng}; |
|
|
|
type TestProofSystem = Gm17<Bls12_377, Bench<Fr>, Fr>;
|
|
|
|
|
|
|
|
struct Bench<F: Field> {
|
|
|
|
inputs: Vec<Option<F>>,
|
|
|
|
inputs: Vec<Option<F>>,
|
|
|
|
num_constraints: usize,
|
|
|
|
}
|
|
|
|
|
|
|
@ -40,8 +36,8 @@ impl ConstraintSynthesizer for Bench { |
|
|
|
let new_entry = {
|
|
|
|
let (input_1_val, input_1_var) = variables[i];
|
|
|
|
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(
|
|
|
|
|| format!("Result {}", i),
|
|
|
|
|| result_val.ok_or(SynthesisError::AssignmentMissing),
|
|
|
@ -70,7 +66,16 @@ fn gm17_setup(c: &mut Criterion) { |
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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| {
|
|
|
|
b.iter(|| TestProofSystem::prove(¶ms.0, Bench { inputs: inputs.clone(), num_constraints }, rng).unwrap())
|
|
|
|
b.iter(|| {
|
|
|
|
TestProofSystem::prove(
|
|
|
|
¶ms.0,
|
|
|
|
Bench {
|
|
|
|
inputs: inputs.clone(),
|
|
|
|
num_constraints,
|
|
|
|
},
|
|
|
|
rng,
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|