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.

68 lines
2.3 KiB

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