Skip to content

Commit

Permalink
updates benches
Browse files Browse the repository at this point in the history
  • Loading branch information
kobigurk committed Apr 22, 2020
1 parent 7a65c80 commit b080425
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ name = "membership_prime_60"
harness = false
required-features = ["zexe"]

[[bench]]
name = "membership_bp_60"
harness = false
required-features = ["dalek"]

[[bench]]
name = "nonmembership_hash"
harness = false
Expand Down
1 change: 1 addition & 0 deletions benches/membership_bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const LARGE_PRIMES: [u64; 3] = [

pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_curve::<Scalar>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
92 changes: 92 additions & 0 deletions benches/membership_bp_60.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rug::Integer;
use std::cell::RefCell;
use curve25519_dalek::{
scalar::Scalar,
ristretto::RistrettoPoint,
};
use rand::thread_rng;
use cpsnarks_set::{
parameters::Parameters,
commitments::Commitment,
transcript::membership::{TranscriptProverChannel, TranscriptVerifierChannel},
protocols::{
membership::{Protocol, Statement, Witness},
hash_to_prime::bp::Protocol as HPProtocol,
},
};
use rug::rand::RandState;
use accumulator::group::Rsa2048;
use merlin::Transcript;
use accumulator::{AccumulatorWithoutHashToPrime, group::Group};

const LARGE_PRIMES: [u64; 3] = [
12_702_637_924_034_044_211,
378_373_571_372_703_133,
8_640_171_141_336_142_787,
];


pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_curve_and_small_prime_size::<Scalar>(60, 70).unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();

let mut crs = cpsnarks_set::protocols::membership::Protocol::<Rsa2048, RistrettoPoint, HPProtocol>::setup(&params, &mut rng1, &mut rng2).unwrap().crs;
let protocol = Protocol::<Rsa2048, RistrettoPoint, HPProtocol>::from_crs(&crs);

let value = Integer::from(Integer::u_pow_u(
2,
(crs.parameters.hash_to_prime_bits)
as u32,
)) - &Integer::from(129);
let randomness = Integer::from(5);
let commitment = protocol.crs.crs_modeq.pedersen_commitment_parameters.commit(&value, &randomness).unwrap();

let accum = accumulator::Accumulator::<Rsa2048, Integer, AccumulatorWithoutHashToPrime>::empty();
let accum = accum.add(&LARGE_PRIMES.iter().skip(1).map(|p| Integer::from(*p)).collect::<Vec<_>>());

let accum = accum.add_with_proof(&[value.clone()]);
let acc = accum.0.value;
let w = accum.1.witness.0.value;
assert_eq!(Rsa2048::exp(&w, &value), acc);


let proof_transcript = RefCell::new(Transcript::new(b"membership"));
crs.crs_hash_to_prime.hash_to_prime_parameters.transcript = Some(proof_transcript.clone());
let mut verifier_channel = TranscriptVerifierChannel::new(&crs, &proof_transcript);
let statement = Statement {
c_e_q: commitment.clone(),
c_p: acc.clone(),
};
protocol.prove(&mut verifier_channel, &mut rng1, &mut rng2, &statement, &Witness {
e: value.clone(),
r_q: randomness.clone(),
w: w.clone(),
}).unwrap();
let proof = verifier_channel.proof().unwrap();
let verification_transcript = RefCell::new(Transcript::new(b"membership"));
crs.crs_hash_to_prime.hash_to_prime_parameters.transcript = Some(verification_transcript.clone());
let mut prover_channel = TranscriptProverChannel::new(&crs, &verification_transcript, &proof);
protocol.verify(&mut prover_channel, &statement).unwrap();

c.bench_function("membership_bp_60 protocol", |b| b.iter(|| {
let proof_transcript = RefCell::new(Transcript::new(b"membership"));
crs.crs_hash_to_prime.hash_to_prime_parameters.transcript = Some(proof_transcript.clone());
let mut verifier_channel = TranscriptVerifierChannel::new(&crs, &proof_transcript);
let statement = Statement {
c_e_q: commitment.clone(),
c_p: acc.clone(),
};
protocol.prove(&mut verifier_channel, &mut rng1, &mut rng2, &statement, &Witness {
e: value.clone(),
r_q: randomness.clone(),
w: w.clone(),
}).unwrap();
}));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
3 changes: 2 additions & 1 deletion benches/membership_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const LARGE_PRIMES: [u64; 3] = [


pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_security_level(128).unwrap();
let params = Parameters::from_curve::<Fr>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
3 changes: 2 additions & 1 deletion benches/membership_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ impl HashToPrimeHashParameters for TestHashToPrimeParameters {
}

pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_security_level(128).unwrap();
let params = Parameters::from_curve::<Fr>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
3 changes: 2 additions & 1 deletion benches/membership_prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const LARGE_PRIMES: [u64; 3] = [


pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_security_level(128).unwrap();
let params = Parameters::from_curve::<Fr>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
1 change: 1 addition & 0 deletions benches/membership_prime_60.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const LARGE_PRIMES: [u64; 3] = [

pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_curve_and_small_prime_size::<Fr>(50, 70).unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
1 change: 1 addition & 0 deletions benches/nonmembership_bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const LARGE_PRIMES: [u64; 3] = [

pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_curve::<Scalar>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
3 changes: 2 additions & 1 deletion benches/nonmembership_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ impl HashToPrimeHashParameters for TestHashToPrimeParameters {
}

pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_security_level(128).unwrap();
let params = Parameters::from_curve::<Fr>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
3 changes: 2 additions & 1 deletion benches/nonmembership_prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const LARGE_PRIMES: [u64; 3] = [


pub fn criterion_benchmark(c: &mut Criterion) {
let params = Parameters::from_security_level(128).unwrap();
let params = Parameters::from_curve::<Fr>().unwrap().0;
println!("params: {}", params);
let mut rng1 = RandState::new();
rng1.seed(&Integer::from(13));
let mut rng2 = thread_rng();
Expand Down
13 changes: 13 additions & 0 deletions src/parameters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::curve::Field;
use std::fmt;

#[derive(Clone, Debug)]
pub struct Parameters {
Expand All @@ -9,6 +10,18 @@ pub struct Parameters {
pub field_size_bits: u16, // ν
}

impl fmt::Display for Parameters {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Parameters(𝜆={} (security level), 𝜆_s={} (soundness security), 𝜆_z={} (zero-knowledge security), μ={} (hash-to-prime/range bits), ν={} (field size bits)",
self.security_level,
self.security_zk,
self.security_soundness,
self.hash_to_prime_bits,
self.field_size_bits,
)
}
}

quick_error! {
#[derive(Debug)]
pub enum ParametersError {
Expand Down

0 comments on commit b080425

Please sign in to comment.