You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

  1. #![allow(non_snake_case)]
  2. extern crate flate2;
  3. extern crate libspartan;
  4. extern crate merlin;
  5. extern crate rand;
  6. use flate2::{write::ZlibEncoder, Compression};
  7. use libspartan::r1csinstance::R1CSInstance;
  8. use libspartan::spartan::{NIZKGens, NIZK};
  9. use libspartan::timer::Timer;
  10. use merlin::Transcript;
  11. pub fn main() {
  12. // the list of number of variables (and constraints) in an R1CS instance
  13. let inst_sizes = vec![12, 16, 20];
  14. println!("Profiler:: NIZK");
  15. for &s in inst_sizes.iter() {
  16. let num_vars = (2 as usize).pow(s as u32);
  17. let num_cons = num_vars;
  18. let num_inputs = 10;
  19. let (inst, vars, input) = R1CSInstance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  20. Timer::print(&format!("number_of_constraints {}", num_cons));
  21. // produce public generators
  22. let gens = NIZKGens::new(num_cons, num_vars);
  23. // produce a proof of satisfiability
  24. let timer_prove = Timer::new("NIZK::prove");
  25. let mut prover_transcript = Transcript::new(b"example");
  26. let proof = NIZK::prove(&inst, vars, &input, &gens, &mut prover_transcript);
  27. timer_prove.stop();
  28. let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default());
  29. bincode::serialize_into(&mut encoder, &proof).unwrap();
  30. let proof_encoded = encoder.finish().unwrap();
  31. let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
  32. Timer::print(&msg_proof_len);
  33. // verify the proof of satisfiability
  34. let timer_verify = Timer::new("NIZK::verify");
  35. let mut verifier_transcript = Transcript::new(b"example");
  36. assert!(proof
  37. .verify(&inst, &input, &mut verifier_transcript, &gens)
  38. .is_ok());
  39. timer_verify.stop();
  40. println!();
  41. }
  42. }