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.

81 lines
2.2 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::{KZGMultilinearPC, MultilinearCommitmentScheme, PCSErrors};
  6. use std::time::Instant;
  7. fn main() -> Result<(), PCSErrors> {
  8. bench_pcs()
  9. }
  10. fn bench_pcs() -> Result<(), PCSErrors> {
  11. let mut rng = test_rng();
  12. // normal polynomials
  13. let uni_params = KZGMultilinearPC::<Bls12_381>::setup(&mut rng, 18)?;
  14. for nv in 4..19 {
  15. let repetition = if nv < 10 {
  16. 100
  17. } else if nv < 20 {
  18. 50
  19. } else {
  20. 10
  21. };
  22. let poly = DenseMultilinearExtension::rand(nv, &mut rng);
  23. let (ck, vk) = uni_params.trim(nv)?;
  24. let point: Vec<_> = (0..nv).map(|_| Fr::rand(&mut rng)).collect();
  25. // commit
  26. let com = {
  27. let start = Instant::now();
  28. for _ in 0..repetition {
  29. let _commit = KZGMultilinearPC::commit(&ck, &poly)?;
  30. }
  31. println!(
  32. "KZG commit for {} variables: {} ns",
  33. nv,
  34. start.elapsed().as_nanos() / repetition as u128
  35. );
  36. KZGMultilinearPC::commit(&ck, &poly)?
  37. };
  38. // open
  39. let proof = {
  40. let start = Instant::now();
  41. for _ in 0..repetition {
  42. let _open = KZGMultilinearPC::open(&ck, &poly, &point)?;
  43. }
  44. println!(
  45. "KZG open for {} variables: {} ns",
  46. nv,
  47. start.elapsed().as_nanos() / repetition as u128
  48. );
  49. KZGMultilinearPC::open(&ck, &poly, &point)?
  50. };
  51. let value = poly.evaluate(&point).unwrap();
  52. // verify
  53. {
  54. let start = Instant::now();
  55. for _ in 0..repetition {
  56. assert!(KZGMultilinearPC::verify(&vk, &com, &point, value, &proof)?);
  57. }
  58. println!(
  59. "KZG verify for {} variables: {} ns",
  60. nv,
  61. start.elapsed().as_nanos() / repetition as u128
  62. );
  63. }
  64. println!("====================================");
  65. }
  66. Ok(())
  67. }