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.5 KiB

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