-
Notifications
You must be signed in to change notification settings - Fork 13
/
membership_bp_60.rs
146 lines (137 loc) · 4.84 KB
/
membership_bp_60.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use accumulator::group::Rsa2048;
use accumulator::{group::Group, AccumulatorWithoutHashToPrime};
use cpsnarks_set::{
commitments::Commitment,
parameters::Parameters,
protocols::{
hash_to_prime::{bp::Protocol as HPProtocol, CRSSize},
membership::{
transcript::{TranscriptProverChannel, TranscriptVerifierChannel},
Protocol, Statement, Witness,
},
},
};
use criterion::{criterion_group, criterion_main, Criterion};
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
use merlin::Transcript;
use rand::thread_rng;
use rug::rand::RandState;
use rug::Integer;
use std::cell::RefCell;
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;
println!(
"crs size: {:?}",
crs.crs_hash_to_prime.hash_to_prime_parameters.crs_size()
);
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,
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();
println!(
"proof size: {}",
proof.proof_hash_to_prime.serialized_size()
);
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 proving", |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,
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();
})
});
c.bench_function("membership_bp_60 protocol verification", |b| {
b.iter(|| {
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();
})
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);