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.

125 lines
4.4 KiB

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