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.

64 lines
1.8 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. use ark_serialize::*;
  7. use libspartan::parameters::poseidon_params;
  8. use libspartan::poseidon_transcript::PoseidonTranscript;
  9. use libspartan::{Instance, SNARKGens, SNARK};
  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:: SNARK");
  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 = SNARKGens::new(num_cons, num_vars, num_inputs, num_cons);
  26. // create a commitment to R1CSInstance
  27. let (comm, decomm) = SNARK::encode(&inst, &gens);
  28. let params = poseidon_params();
  29. // produce a proof of satisfiability
  30. let mut prover_transcript = PoseidonTranscript::new(&params);
  31. let proof = SNARK::prove(
  32. &inst,
  33. &comm,
  34. &decomm,
  35. vars,
  36. &inputs,
  37. &gens,
  38. &mut prover_transcript,
  39. );
  40. let mut proof_encoded = Vec::new();
  41. proof.serialize(&mut proof_encoded).unwrap();
  42. let msg_proof_len = format!("SNARK::proof_compressed_len {:?}", proof_encoded.len());
  43. print(&msg_proof_len);
  44. // verify the proof of satisfiability
  45. let mut verifier_transcript = PoseidonTranscript::new(&params);
  46. assert!(proof
  47. .verify(&comm, &inputs, &mut verifier_transcript, &gens)
  48. .is_ok());
  49. println!();
  50. }
  51. }