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.

119 lines
4.0 KiB

  1. use std::time::Instant;
  2. use ark_bls12_381::Fr;
  3. use ark_std::test_rng;
  4. use poly_iop::{PolyIOP, PolyIOPErrors, SumCheck, VirtualPolynomial, ZeroCheck};
  5. fn main() -> Result<(), PolyIOPErrors> {
  6. bench_sum_check()?;
  7. println!("\n\n");
  8. bench_zero_check()
  9. }
  10. fn bench_sum_check() -> Result<(), PolyIOPErrors> {
  11. let mut rng = test_rng();
  12. for degree in 2..4 {
  13. for nv in 4..25 {
  14. let repetition = if nv < 10 {
  15. 100
  16. } else if nv < 20 {
  17. 50
  18. } else {
  19. 10
  20. };
  21. let (poly, asserted_sum) =
  22. VirtualPolynomial::rand(nv, (degree, degree + 1), 2, &mut rng)?;
  23. let poly_info = poly.domain_info.clone();
  24. let proof = {
  25. let start = Instant::now();
  26. let mut transcript = <PolyIOP<Fr> as SumCheck<Fr>>::init_transcript();
  27. let proof = <PolyIOP<Fr> as SumCheck<Fr>>::prove(&poly, &mut transcript)?;
  28. println!(
  29. "sum check proving time for {} variables and {} degree: {} ns",
  30. nv,
  31. degree,
  32. start.elapsed().as_nanos() / repetition as u128
  33. );
  34. proof
  35. };
  36. {
  37. let start = Instant::now();
  38. let mut transcript = <PolyIOP<Fr> as SumCheck<Fr>>::init_transcript();
  39. let subclaim = <PolyIOP<Fr> as SumCheck<Fr>>::verify(
  40. asserted_sum,
  41. &proof,
  42. &poly_info,
  43. &mut transcript,
  44. )?;
  45. assert!(
  46. poly.evaluate(&subclaim.point).unwrap() == subclaim.expected_evaluation,
  47. "wrong subclaim"
  48. );
  49. println!(
  50. "sum check verification time for {} variables: {} ns",
  51. nv,
  52. start.elapsed().as_nanos() / repetition as u128
  53. );
  54. }
  55. println!("====================================");
  56. }
  57. }
  58. Ok(())
  59. }
  60. fn bench_zero_check() -> Result<(), PolyIOPErrors> {
  61. let mut rng = test_rng();
  62. for degree in 2..4 {
  63. for nv in 4..20 {
  64. let repetition = if nv < 10 {
  65. 100
  66. } else if nv < 20 {
  67. 50
  68. } else {
  69. 10
  70. };
  71. let poly = VirtualPolynomial::rand_zero(nv, (degree, degree + 1), 2, &mut rng)?;
  72. let poly_info = poly.domain_info.clone();
  73. let proof = {
  74. let start = Instant::now();
  75. let mut transcript = <PolyIOP<Fr> as ZeroCheck<Fr>>::init_transcript();
  76. transcript.append_message(b"testing", b"initializing transcript for testing")?;
  77. let proof = <PolyIOP<Fr> as ZeroCheck<Fr>>::prove(&poly, &mut transcript)?;
  78. println!(
  79. "zero check proving time for {} variables and {} degree: {} ns",
  80. nv,
  81. degree,
  82. start.elapsed().as_nanos() / repetition as u128
  83. );
  84. proof
  85. };
  86. {
  87. let start = Instant::now();
  88. let mut transcript = <PolyIOP<Fr> as ZeroCheck<Fr>>::init_transcript();
  89. transcript.append_message(b"testing", b"initializing transcript for testing")?;
  90. let subclaim =
  91. <PolyIOP<Fr> as ZeroCheck<Fr>>::verify(&proof, &poly_info, &mut transcript)?.0;
  92. assert!(
  93. poly.evaluate(&subclaim.point)? == subclaim.expected_evaluation,
  94. "wrong subclaim"
  95. );
  96. println!(
  97. "zero check verification time for {} variables: {} ns",
  98. nv,
  99. start.elapsed().as_nanos() / repetition as u128
  100. );
  101. }
  102. println!("====================================");
  103. }
  104. }
  105. Ok(())
  106. }