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.

98 lines
2.8 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_poly_commit::multilinear_pc::MultilinearPC;
  3. use ark_serialize::CanonicalSerialize;
  4. use libtestudo::{
  5. parameters::PoseidonConfiguration, poseidon_transcript::PoseidonTranscript, sqrt_pst::Polynomial,
  6. };
  7. use serde::Serialize;
  8. type F = ark_bls12_377::Fr;
  9. type E = ark_bls12_377::Bls12_377;
  10. use ark_std::UniformRand;
  11. #[derive(Default, Clone, Serialize)]
  12. struct BenchmarkResults {
  13. power: usize,
  14. commit_time: u128,
  15. opening_time: u128,
  16. verification_time: u128,
  17. proof_size: usize,
  18. commiter_key_size: usize,
  19. }
  20. fn main() {
  21. let params = ark_bls12_377::Fr::poseidon_params();
  22. let mut writer = csv::Writer::from_path("sqrt_pst.csv").expect("unable to open csv writer");
  23. for &s in [4, 5, 20, 27].iter() {
  24. println!("Running for {} inputs", s);
  25. let mut rng = ark_std::test_rng();
  26. let mut br = BenchmarkResults::default();
  27. br.power = s;
  28. let num_vars = s;
  29. let len = 2_usize.pow(num_vars as u32);
  30. let z: Vec<F> = (0..len).into_iter().map(|_| F::rand(&mut rng)).collect();
  31. let r: Vec<F> = (0..num_vars)
  32. .into_iter()
  33. .map(|_| F::rand(&mut rng))
  34. .collect();
  35. let setup_vars = (num_vars as f32 / 2.0).ceil() as usize;
  36. let gens = MultilinearPC::<E>::setup((num_vars as f32 / 2.0).ceil() as usize, &mut rng);
  37. let (ck, vk) = MultilinearPC::<E>::trim(&gens, setup_vars);
  38. let mut cks = Vec::<u8>::new();
  39. ck.serialize_with_mode(&mut cks, ark_serialize::Compress::Yes)
  40. .unwrap();
  41. br.commiter_key_size = cks.len();
  42. let mut pl = Polynomial::from_evaluations(&z.clone());
  43. let v = pl.eval(&r);
  44. let start = Instant::now();
  45. let (comm_list, t) = pl.commit(&ck);
  46. let duration = start.elapsed().as_millis();
  47. br.commit_time = duration;
  48. let mut prover_transcript = PoseidonTranscript::new(&params);
  49. let start = Instant::now();
  50. let (u, pst_proof, mipp_proof) = pl.open(&mut prover_transcript, comm_list, &ck, &r, &t);
  51. let duration = start.elapsed().as_millis();
  52. br.opening_time = duration;
  53. let mut p1 = Vec::<u8>::new();
  54. let mut p2 = Vec::<u8>::new();
  55. pst_proof
  56. .serialize_with_mode(&mut p1, ark_serialize::Compress::Yes)
  57. .unwrap();
  58. mipp_proof
  59. .serialize_with_mode(&mut p2, ark_serialize::Compress::Yes)
  60. .unwrap();
  61. br.proof_size = p1.len() + p2.len();
  62. let mut verifier_transcript = PoseidonTranscript::new(&params);
  63. let start = Instant::now();
  64. let res = Polynomial::verify(
  65. &mut verifier_transcript,
  66. &vk,
  67. &u,
  68. &r,
  69. v,
  70. &pst_proof,
  71. &mipp_proof,
  72. &t,
  73. );
  74. let duration = start.elapsed().as_millis();
  75. br.verification_time = duration;
  76. assert!(res == true);
  77. writer
  78. .serialize(br)
  79. .expect("unable to write results to csv");
  80. writer.flush().expect("wasn't able to flush");
  81. }
  82. }