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.

92 lines
2.4 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. #![allow(non_snake_case)]
  2. #![allow(clippy::assertions_on_result_states)]
  3. extern crate libtestudo;
  4. extern crate merlin;
  5. use ark_crypto_primitives::sponge::poseidon::PoseidonConfig;
  6. use ark_crypto_primitives::sponge::Absorb;
  7. use ark_ec::pairing::Pairing;
  8. use ark_ff::PrimeField;
  9. use ark_serialize::*;
  10. use libtestudo::parameters::PoseidonConfiguration;
  11. use libtestudo::poseidon_transcript::PoseidonTranscript;
  12. use libtestudo::{
  13. testudo_snark::{TestudoSnark, TestudoSnarkGens},
  14. Instance,
  15. };
  16. fn print(msg: &str) {
  17. let star = "* ";
  18. println!("{:indent$}{}{}", "", star, msg, indent = 2);
  19. }
  20. fn main() {
  21. let params = ark_bls12_377::Fr::poseidon_params();
  22. profiler::<ark_bls12_377::Bls12_377>(params);
  23. }
  24. fn profiler<E>(params: PoseidonConfig<E::ScalarField>)
  25. where
  26. E: Pairing,
  27. E::ScalarField: PrimeField,
  28. E::ScalarField: Absorb,
  29. {
  30. // the list of number of variables (and constraints) in an R1CS instance
  31. let inst_sizes = vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
  32. println!("Profiler:: SNARK");
  33. for &s in inst_sizes.iter() {
  34. let num_vars = (2_usize).pow(s as u32);
  35. let num_cons = num_vars;
  36. let num_inputs = 10;
  37. // produce a synthetic R1CSInstance
  38. let (inst, vars, inputs) =
  39. Instance::<E::ScalarField>::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
  40. // produce public generators
  41. let gens =
  42. TestudoSnarkGens::<E>::setup(num_cons, num_vars, num_inputs, num_cons, params.clone());
  43. // create a commitment to R1CSInstance
  44. let (comm, decomm) = TestudoSnark::encode(&inst, &gens);
  45. // produce a proof of satisfiability
  46. let mut prover_transcript = PoseidonTranscript::new(&params.clone());
  47. let proof = TestudoSnark::prove(
  48. &inst,
  49. &comm,
  50. &decomm,
  51. vars,
  52. &inputs,
  53. &gens,
  54. &mut prover_transcript,
  55. params.clone(),
  56. )
  57. .unwrap();
  58. let mut proof_encoded = Vec::new();
  59. proof
  60. .serialize_with_mode(&mut proof_encoded, Compress::Yes)
  61. .unwrap();
  62. let msg_proof_len = format!(
  63. "TestudoSnark::proof_compressed_len {:?}",
  64. proof_encoded.len()
  65. );
  66. print(&msg_proof_len);
  67. // verify the proof of satisfiability
  68. let mut verifier_transcript = PoseidonTranscript::new(&params.clone());
  69. assert!(proof
  70. .verify(
  71. &gens,
  72. &comm,
  73. &inputs,
  74. &mut verifier_transcript,
  75. params.clone()
  76. )
  77. .is_ok());
  78. println!();
  79. }
  80. }