MCPcopy Create free account
hub / github.com/docknetwork/crypto / check

Function check

delegatable_credentials/src/one_of_n_proof.rs:224–257  ·  view source on GitHub ↗
(
            rng: &mut StdRng,
            size: u32,
            count_decoys: usize,
            P1: &<Bls12_381 as Pairing>::G1Affine,
            srs: &OneOfNSrs<Bls12_381>,
        )

Source from the content-addressed store, hash-verified

222 let (srs, _) = OneOfNSrs::<Bls12_381>::new(&mut rng, &P1);
223
224 fn check(
225 rng: &mut StdRng,
226 size: u32,
227 count_decoys: usize,
228 P1: &<Bls12_381 as Pairing>::G1Affine,
229 srs: &OneOfNSrs<Bls12_381>,
230 ) {
231 let actual = (0..size).map(|_| G2Affine::rand(rng)).collect::<Vec<_>>();
232 let decoys = (0..count_decoys)
233 .map(|_| (0..size).map(|_| G2Affine::rand(rng)).collect::<Vec<_>>())
234 .collect::<Vec<_>>();
235 let witness = Fr::rand(rng);
236 let instance = actual
237 .iter()
238 .map(|b| b.mul(witness).into_affine())
239 .collect::<Vec<_>>();
240
241 let d = decoys.iter().map(|d| d.as_slice()).collect::<Vec<_>>();
242
243 let start = Instant::now();
244 let proof =
245 OneOfNProof::new(rng, &actual, d.clone(), &instance, &witness, srs, P1).unwrap();
246 let proving_time = start.elapsed();
247
248 let start = Instant::now();
249 for i in 0..count_decoys {
250 let mut temp_d = d.clone();
251 temp_d.insert(i, &actual);
252 proof.verify(temp_d, &instance, srs, P1).unwrap();
253 }
254 let verifying_time = start.elapsed();
255
256 println!("For {} decoys of size {} each, proving takes {:?} and verifying takes {:?} on average", count_decoys, size, proving_time, verifying_time / (count_decoys as u32))
257 }
258
259 for i in 10..20 {
260 check(&mut rng, 5, i, &P1, &srs);

Callers 1

one_of_n_proofFunction · 0.70

Calls 6

randFunction · 0.85
mapMethod · 0.80
mulMethod · 0.80
cloneMethod · 0.80
iterMethod · 0.45
verifyMethod · 0.45

Tested by 1

one_of_n_proofFunction · 0.56