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.

88 lines
2.4 KiB

  1. use ark_bls12_381::{Bls12_381, Fr};
  2. use ark_ff::UniformRand;
  3. use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
  4. use ark_std::test_rng;
  5. use pcs::{
  6. prelude::{KZGMultilinearPCS, PCSErrors, PolynomialCommitmentScheme},
  7. StructuredReferenceString,
  8. };
  9. use std::time::Instant;
  10. fn main() -> Result<(), PCSErrors> {
  11. bench_pcs()
  12. }
  13. fn bench_pcs() -> Result<(), PCSErrors> {
  14. let mut rng = test_rng();
  15. // normal polynomials
  16. let uni_params = KZGMultilinearPCS::<Bls12_381>::gen_srs_for_testing(&mut rng, 18)?;
  17. for nv in 4..19 {
  18. let repetition = if nv < 10 {
  19. 100
  20. } else if nv < 20 {
  21. 50
  22. } else {
  23. 10
  24. };
  25. let poly = DenseMultilinearExtension::rand(nv, &mut rng);
  26. let (ml_ck, ml_vk) = uni_params.0.trim(nv)?;
  27. let (uni_ck, uni_vk) = uni_params.1.trim(nv)?;
  28. let ck = (ml_ck, uni_ck);
  29. let vk = (ml_vk, uni_vk);
  30. let point: Vec<_> = (0..nv).map(|_| Fr::rand(&mut rng)).collect();
  31. // commit
  32. let com = {
  33. let start = Instant::now();
  34. for _ in 0..repetition {
  35. let _commit = KZGMultilinearPCS::commit(&ck, &poly)?;
  36. }
  37. println!(
  38. "KZG commit for {} variables: {} ns",
  39. nv,
  40. start.elapsed().as_nanos() / repetition as u128
  41. );
  42. KZGMultilinearPCS::commit(&ck, &poly)?
  43. };
  44. // open
  45. let (proof, value) = {
  46. let start = Instant::now();
  47. for _ in 0..repetition {
  48. let _open = KZGMultilinearPCS::open(&ck, &poly, &point)?;
  49. }
  50. println!(
  51. "KZG open for {} variables: {} ns",
  52. nv,
  53. start.elapsed().as_nanos() / repetition as u128
  54. );
  55. KZGMultilinearPCS::open(&ck, &poly, &point)?
  56. };
  57. // verify
  58. {
  59. let start = Instant::now();
  60. for _ in 0..repetition {
  61. assert!(KZGMultilinearPCS::verify(
  62. &vk, &com, &point, &value, &proof
  63. )?);
  64. }
  65. println!(
  66. "KZG verify for {} variables: {} ns",
  67. nv,
  68. start.elapsed().as_nanos() / repetition as u128
  69. );
  70. }
  71. println!("====================================");
  72. }
  73. Ok(())
  74. }