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.

53 lines
1.6 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 ark_serialize::*;
  8. use libspartan::parameters::poseidon_params;
  9. use libspartan::poseidon_transcript::PoseidonTranscript;
  10. use libspartan::{Instance, NIZK};
  11. fn print(msg: &str) {
  12. let star = "* ";
  13. println!("{:indent$}{}{}", "", star, msg, indent = 2);
  14. }
  15. pub fn main() {
  16. // the list of number of variables (and constraints) in an R1CS instance
  17. let inst_sizes = vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
  18. println!("Profiler:: NIZK");
  19. for &s in inst_sizes.iter() {
  20. let num_vars = (2_usize).pow(s as u32);
  21. let num_cons = num_vars;
  22. let num_inputs = 10;
  23. // produce a synthetic R1CSInstance
  24. let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  25. // produce public generators
  26. // let gens = NIZKGens::new(num_cons, num_vars, num_inputs);
  27. let params = poseidon_params();
  28. // produce a proof of satisfiability
  29. let mut prover_transcript = PoseidonTranscript::new(&params);
  30. let proof = NIZK::prove(&inst, vars, &inputs, &mut prover_transcript);
  31. let mut proof_encoded = Vec::new();
  32. proof.serialize(&mut proof_encoded).unwrap();
  33. let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
  34. print(&msg_proof_len);
  35. // verify the proof of satisfiability
  36. let mut verifier_transcript = PoseidonTranscript::new(&params);
  37. assert!(proof
  38. .verify(&inst, &inputs, &mut verifier_transcript)
  39. .is_ok());
  40. println!();
  41. }
  42. }