-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
123 additions
and
5 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
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,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(¶ms, &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); |
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
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