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.

72 lines
2.7 KiB

  1. use std::time::Instant;
  2. use libspartan::{
  3. parameters::POSEIDON_PARAMETERS_FR_377, poseidon_transcript::PoseidonTranscript, Instance,
  4. NIZKGens, NIZK,
  5. };
  6. use serde::Serialize;
  7. #[derive(Default, Clone, Serialize)]
  8. struct BenchmarkResults {
  9. power: usize,
  10. input_constraints: usize,
  11. spartan_verifier_circuit_constraints: usize,
  12. r1cs_instance_generation_time: u128,
  13. spartan_proving_time: u128,
  14. groth16_setup_time: u128,
  15. groth16_proving_time: u128,
  16. testudo_verification_time: u128,
  17. testudo_proving_time: u128,
  18. }
  19. fn main() {
  20. let mut writer = csv::Writer::from_path("testudo.csv").expect("unable to open csv writer");
  21. // for &s in [
  22. // 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
  23. // ]
  24. // .iter()
  25. // For testing purposes we currently bench on very small instance to ensure
  26. // correctness and then on biggest one for timings.
  27. for &s in [4, 26].iter() {
  28. println!("Running for {} inputs", s);
  29. let mut br = BenchmarkResults::default();
  30. let num_vars = (2_usize).pow(s as u32);
  31. let num_cons = num_vars;
  32. br.power = s;
  33. br.input_constraints = num_cons;
  34. let num_inputs = 10;
  35. let start = Instant::now();
  36. let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  37. let duration = start.elapsed().as_millis();
  38. br.r1cs_instance_generation_time = duration;
  39. let mut prover_transcript = PoseidonTranscript::new(&POSEIDON_PARAMETERS_FR_377);
  40. let gens = NIZKGens::new(num_cons, num_vars, num_inputs);
  41. let start = Instant::now();
  42. let proof = NIZK::prove(&inst, vars, &inputs, &gens, &mut prover_transcript);
  43. let duration = start.elapsed().as_millis();
  44. br.spartan_proving_time = duration;
  45. let mut verifier_transcript = PoseidonTranscript::new(&POSEIDON_PARAMETERS_FR_377);
  46. let res = proof.verify(&inst, &inputs, &mut verifier_transcript, &gens);
  47. assert!(res.is_ok());
  48. br.spartan_verifier_circuit_constraints = res.unwrap();
  49. let mut verifier_transcript = PoseidonTranscript::new(&POSEIDON_PARAMETERS_FR_377);
  50. let res = proof.verify_groth16(&inst, &inputs, &mut verifier_transcript, &gens);
  51. assert!(res.is_ok());
  52. let (ds, dp, dv) = res.unwrap();
  53. br.groth16_setup_time = ds;
  54. br.groth16_proving_time = dp;
  55. br.testudo_proving_time = br.spartan_proving_time + br.groth16_proving_time;
  56. br.testudo_verification_time = dv;
  57. writer
  58. .serialize(br)
  59. .expect("unable to write results to csv");
  60. writer.flush().expect("wasn't able to flush");
  61. }
  62. }