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.

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