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