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.

127 lines
3.5 KiB

PST/SQRT + Benches (#35) * first version of the sqrt PST without the MIPP * snarkpack integration * snarkpack integration * adding mipp as submodule directly * snarkpack integration * finalizing * snarkpack integration * update mipp with latestest optimisations and add preliminary documentation * improve codebase documentation * remove unused imports and apply cargo fix changes * passing v0.4 * adding gh action * correct workflow item * correct working dir and msrv * remove unnecessary stuff * wip * wip * remove circuit in fq as it's not needed now * done for tonight * wip * wip * sip * prallelise commitment and groth16 verification * finalise comments for mipp * wip * finalise comments * wip * compiling but test failing * putting back non random blinds * using absorb when we can * absorbing scalar * with bls12-381 * stuff * trying to bring ark-blst to testudo * correcting random implementation * with square in place * works with blst * works with blst * fix: don't require nightly Rust With removing the `test` feature, it can also be built with a stable Rust release and don't require a nightly Rust version. * using ark-blst main branch * started cleanup and added testudo benchmark * add testudo snark and nizk in separate files * rename functions that perform setups and add comments * prototyping * explain testudo-nizk * add support for odd case in sqrt_pst * add missing constraints and correct proof size for benchmarks * add support for odd case in sqrt_pst * fix typo in comment * Documentation #31 * fix typo in comment * Fix Cargo.toml and add benchmark for sqrt pst (#34) * add benchmark for sqrt pst * fix typo in comment * add README * comment from readme not executing --------- Co-authored-by: Mara Mihali <maramihali@google.com> Co-authored-by: Mara Mihali <mihalimara22@gmail.com> Co-authored-by: Volker Mische <volker.mische@gmail.com>
1 year ago
  1. use std::time::Instant;
  2. use ark_crypto_primitives::sponge::poseidon::PoseidonConfig;
  3. use ark_crypto_primitives::sponge::Absorb;
  4. use ark_ec::pairing::Pairing;
  5. use ark_ff::PrimeField;
  6. use ark_serialize::*;
  7. use libtestudo::parameters::PoseidonConfiguration;
  8. use libtestudo::{
  9. poseidon_transcript::PoseidonTranscript,
  10. testudo_snark::{TestudoSnark, TestudoSnarkGens},
  11. Instance,
  12. };
  13. use serde::Serialize;
  14. #[derive(Default, Clone, Serialize)]
  15. struct BenchmarkResults {
  16. power: usize,
  17. input_constraints: usize,
  18. testudo_proving_time: u128,
  19. testudo_verification_time: u128,
  20. sat_proof_size: usize,
  21. eval_proof_size: usize,
  22. total_proof_size: usize,
  23. }
  24. fn main() {
  25. bench_with_bls12_377();
  26. // bench_with_bls12_381();
  27. // bench_with_ark_blst();
  28. }
  29. fn bench_with_ark_blst() {
  30. let params = ark_blst::Scalar::poseidon_params();
  31. testudo_snark_bench::<ark_blst::Bls12>(params, "testudo_blst");
  32. }
  33. fn bench_with_bls12_377() {
  34. let params = ark_bls12_377::Fr::poseidon_params();
  35. testudo_snark_bench::<ark_bls12_377::Bls12_377>(params, "testudo_bls12_377");
  36. }
  37. fn bench_with_bls12_381() {
  38. let params = ark_bls12_381::Fr::poseidon_params();
  39. testudo_snark_bench::<ark_bls12_381::Bls12_381>(params, "testudo_bls12_381");
  40. }
  41. fn testudo_snark_bench<E>(params: PoseidonConfig<E::ScalarField>, file_name: &str)
  42. where
  43. E: Pairing,
  44. E::ScalarField: PrimeField,
  45. E::ScalarField: Absorb,
  46. {
  47. let mut writer = csv::Writer::from_path(file_name).expect("unable to open csv writer");
  48. for &s in [4, 5, 10, 12, 14, 16, 18, 20, 22, 24, 26].iter() {
  49. println!("Running for {} inputs", s);
  50. let mut br = BenchmarkResults::default();
  51. let num_vars = (2_usize).pow(s as u32);
  52. let num_cons = num_vars;
  53. br.power = s;
  54. br.input_constraints = num_cons;
  55. let num_inputs = 10;
  56. let (inst, vars, inputs) =
  57. Instance::<E::ScalarField>::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  58. let mut prover_transcript = PoseidonTranscript::new(&params.clone());
  59. let gens =
  60. TestudoSnarkGens::<E>::setup(num_cons, num_vars, num_inputs, num_cons, params.clone());
  61. let (comm, decomm) = TestudoSnark::<E>::encode(&inst, &gens);
  62. let start = Instant::now();
  63. let proof = TestudoSnark::prove(
  64. &inst,
  65. &comm,
  66. &decomm,
  67. vars,
  68. &inputs,
  69. &gens,
  70. &mut prover_transcript,
  71. params.clone(),
  72. )
  73. .unwrap();
  74. let duration = start.elapsed().as_millis();
  75. br.testudo_proving_time = duration;
  76. let mut sat_proof = Vec::<u8>::new();
  77. proof
  78. .r1cs_verifier_proof
  79. .serialize_with_mode(&mut sat_proof, Compress::Yes)
  80. .unwrap();
  81. br.sat_proof_size = sat_proof.len();
  82. let mut eval_proof = Vec::<u8>::new();
  83. proof
  84. .r1cs_eval_proof
  85. .serialize_with_mode(&mut eval_proof, Compress::Yes)
  86. .unwrap();
  87. br.eval_proof_size = eval_proof.len();
  88. let mut total_proof = Vec::<u8>::new();
  89. proof
  90. .serialize_with_mode(&mut total_proof, Compress::Yes)
  91. .unwrap();
  92. br.total_proof_size = total_proof.len();
  93. let mut verifier_transcript = PoseidonTranscript::new(&params.clone());
  94. let start = Instant::now();
  95. let res = proof.verify(
  96. &gens,
  97. &comm,
  98. &inputs,
  99. &mut verifier_transcript,
  100. params.clone(),
  101. );
  102. assert!(res.is_ok());
  103. let duration = start.elapsed().as_millis();
  104. br.testudo_verification_time = duration;
  105. writer
  106. .serialize(br)
  107. .expect("unable to write results to csv");
  108. writer.flush().expect("wasn't able to flush");
  109. }
  110. }