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.

49 lines
1.5 KiB

  1. #![allow(non_snake_case)]
  2. extern crate flate2;
  3. extern crate libspartan;
  4. extern crate merlin;
  5. extern crate rand;
  6. use libspartan::{Instance, NIZKGens, NIZK};
  7. use merlin::Transcript;
  8. use ark_serialize::*;
  9. fn print(msg: &str) {
  10. let star = "* ";
  11. println!("{:indent$}{}{}", "", star, msg, indent = 2);
  12. }
  13. pub fn main() {
  14. // the list of number of variables (and constraints) in an R1CS instance
  15. let inst_sizes = vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
  16. println!("Profiler:: NIZK");
  17. for &s in inst_sizes.iter() {
  18. let num_vars = (2_usize).pow(s as u32);
  19. let num_cons = num_vars;
  20. let num_inputs = 10;
  21. // produce a synthetic R1CSInstance
  22. let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  23. // produce public generators
  24. let gens = NIZKGens::new(num_cons, num_vars, num_inputs);
  25. // produce a proof of satisfiability
  26. let mut prover_transcript = Transcript::new(b"nizk_example");
  27. let proof = NIZK::prove(&inst, vars, &inputs, &gens, &mut prover_transcript);
  28. let mut proof_encoded = Vec::new();
  29. proof.serialize(&mut proof_encoded).unwrap();
  30. let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
  31. print(&msg_proof_len);
  32. // verify the proof of satisfiability
  33. let mut verifier_transcript = Transcript::new(b"nizk_example");
  34. assert!(proof
  35. .verify(&inst, &inputs, &mut verifier_transcript, &gens)
  36. .is_ok());
  37. println!();
  38. }
  39. }