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.

52 lines
1.7 KiB

  1. #![allow(non_snake_case)]
  2. #![allow(clippy::assertions_on_result_states)]
  3. extern crate libspartan;
  4. extern crate merlin;
  5. extern crate rand;
  6. use ark_serialize::*;
  7. use libspartan::parameters::poseidon_params;
  8. use libspartan::poseidon_transcript::PoseidonTranscript;
  9. use libspartan::{Instance, NIZKGens, NIZK};
  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. let params = poseidon_params();
  27. // produce a proof of satisfiability
  28. let mut prover_transcript = PoseidonTranscript::new(&params);
  29. let proof = NIZK::prove(&inst, vars, &inputs, &gens, &mut prover_transcript);
  30. let mut proof_encoded = Vec::new();
  31. proof.serialize(&mut proof_encoded).unwrap();
  32. let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
  33. print(&msg_proof_len);
  34. // verify the proof of satisfiability
  35. let mut verifier_transcript = PoseidonTranscript::new(&params);
  36. assert!(proof
  37. .verify(&inst, &inputs, &mut verifier_transcript, &gens)
  38. .is_ok());
  39. println!();
  40. }
  41. }