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

Function check

saver/src/saver_groth16.rs:290–373  ·  view source on GitHub ↗
(chunk_bit_size: u8)

Source from the content-addressed store, hash-verified

288 #[test]
289 fn encrypt_and_snark_verification() {
290 fn check(chunk_bit_size: u8) {
291 let mut rng = StdRng::seed_from_u64(0u64);
292 let gens = EncryptionGens::<Bls12_381>::new_using_rng(&mut rng);
293 let n = chunks_count::<Fr>(chunk_bit_size);
294 // Get random numbers that are of chunk_bit_size at most
295 let msgs = gen_messages(&mut rng, n as u32, chunk_bit_size);
296 let msgs_as_field_elems = msgs.iter().map(|m| Fr::from(*m as u64)).collect::<Vec<_>>();
297
298 let circuit = BitsizeCheckCircuit::new(chunk_bit_size, Some(n), None, true);
299 let snark_srs = generate_srs::<Bls12_381, _, _>(circuit, &gens, &mut rng).unwrap();
300
301 println!(
302 "For chunk_bit_size {}, Snark SRS has compressed size {} and uncompressed size {}",
303 chunk_bit_size,
304 snark_srs.compressed_size(),
305 snark_srs.uncompressed_size()
306 );
307
308 let g_i = get_gs_for_encryption(&snark_srs.pk.vk);
309 let (sk, ek, dk) = keygen(
310 &mut rng,
311 chunk_bit_size,
312 &gens,
313 g_i,
314 &snark_srs.pk.delta_g1,
315 &snark_srs.gamma_g1,
316 )
317 .unwrap();
318
319 println!("For chunk_bit_size {}, encryption key has compressed size {} and uncompressed size {}", chunk_bit_size, ek.compressed_size(), ek.uncompressed_size());
320
321 let start = Instant::now();
322 let (ct, r) =
323 Encryption::encrypt_decomposed_message(&mut rng, msgs.clone(), &ek, g_i).unwrap();
324 println!("Time taken to encrypt: {:?}", start.elapsed());
325
326 let start = Instant::now();
327 let (m_, _) = Encryption::decrypt_to_chunks(
328 &ct[0],
329 &ct[1..n as usize + 1],
330 &sk,
331 dk,
332 g_i,
333 chunk_bit_size,
334 )
335 .unwrap();
336 println!("Time taken to decrypt: {:?}", start.elapsed());
337
338 assert_eq!(m_, msgs);
339
340 let circuit =
341 BitsizeCheckCircuit::new(chunk_bit_size, Some(n), Some(msgs_as_field_elems), true);
342
343 let start = Instant::now();
344 let proof = create_proof(circuit, &r, &snark_srs, &ek, &mut rng).unwrap();
345 println!(
346 "Time taken to create Groth16 proof with chunk_bit_size {}: {:?}",
347 chunk_bit_size,

Callers 2

rerandomize_encryptionFunction · 0.70

Calls 11

gen_messagesFunction · 0.85
randFunction · 0.85
mapMethod · 0.80
cloneMethod · 0.80
get_gs_for_encryptionFunction · 0.70
keygenFunction · 0.70
create_proofFunction · 0.70
verify_proofFunction · 0.70
iterMethod · 0.45

Tested by 2

rerandomize_encryptionFunction · 0.56