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

Function test_pairing_randomize

utils/src/randomized_pairing_check.rs:235–420  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233
234 #[test]
235 fn test_pairing_randomize() {
236 let mut rng = StdRng::seed_from_u64(0u64);
237 let n = 10;
238 let mut t1 = 0;
239
240 let a1 = (0..n)
241 .map(|_| G1Projective::rand(&mut rng).into_affine())
242 .collect::<Vec<_>>();
243 let b1 = (0..n)
244 .map(|_| G2Projective::rand(&mut rng).into_affine())
245 .collect::<Vec<_>>();
246 let a2 = (0..n + 5)
247 .map(|_| G1Projective::rand(&mut rng).into_affine())
248 .collect::<Vec<_>>();
249 let b2 = (0..n + 5)
250 .map(|_| G2Projective::rand(&mut rng).into_affine())
251 .collect::<Vec<_>>();
252 let a3 = (0..n - 2)
253 .map(|_| G1Projective::rand(&mut rng).into_affine())
254 .collect::<Vec<_>>();
255 let b3 = (0..n - 2)
256 .map(|_| G2Projective::rand(&mut rng).into_affine())
257 .collect::<Vec<_>>();
258
259 let start = Instant::now();
260 let out1 = Bls12_381::multi_pairing(a1.clone(), b1.clone());
261 t1 += start.elapsed().as_micros();
262
263 let start = Instant::now();
264 let out2 = Bls12_381::multi_pairing(a2.clone(), b2.clone());
265 t1 += start.elapsed().as_micros();
266
267 let start = Instant::now();
268 let out3 = Bls12_381::multi_pairing(a3.clone(), b3.clone());
269 t1 += start.elapsed().as_micros();
270
271 println!("Time taken without checker {} us", t1);
272
273 for lazy in [true, false] {
274 let start = Instant::now();
275 let mut checker = RandomizedPairingChecker::<Bls12_381>::new_using_rng(&mut rng, lazy);
276 checker.add_multiple_sources_and_target(&a1, &b1, &out1);
277 checker.add_multiple_sources_and_target(&a2, &b2, &out2);
278 checker.add_multiple_sources_and_target(&a3, &b3, &out3);
279 assert!(checker.verify());
280 let l_str = if lazy { "lazy-" } else { "" };
281 println!(
282 "Time taken with {}checker {} us",
283 l_str,
284 start.elapsed().as_micros()
285 );
286
287 // Fail on wrong output
288 let mut checker = RandomizedPairingChecker::<Bls12_381>::new_using_rng(&mut rng, lazy);
289 checker.add_multiple_sources_and_target(&a1, &b1, &out2);
290 checker.add_multiple_sources_and_target(&a2, &b2, &out1);
291 assert!(!checker.verify());
292 }

Callers

nothing calls this directly

Calls 9

randFunction · 0.85
rev_vecFunction · 0.85
mapMethod · 0.80
cloneMethod · 0.80
add_multiple_sourcesMethod · 0.80
add_sourcesMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected