Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23 permutation checks #32

Merged
merged 14 commits into from
Jun 14, 2022
98 changes: 93 additions & 5 deletions poly-iop/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use ark_bls12_381::Fr;
use ark_std::test_rng;
use poly_iop::{PolyIOP, PolyIOPErrors, SumCheck, VirtualPolynomial, ZeroCheck};
use std::time::Instant;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::{test_rng, UniformRand};
use poly_iop::{
identity_permutation_mle, PermutationCheck, PolyIOP, PolyIOPErrors, SumCheck, VPAuxInfo,
VirtualPolynomial, ZeroCheck,
};
use std::{marker::PhantomData, time::Instant};

fn main() -> Result<(), PolyIOPErrors> {
bench_permutation_check()?;
println!("\n\n");
bench_sum_check()?;
println!("\n\n");
bench_zero_check()
Expand Down Expand Up @@ -105,13 +111,14 @@ fn bench_zero_check() -> Result<(), PolyIOPErrors> {
let mut transcript = <PolyIOP<Fr> as ZeroCheck<Fr>>::init_transcript();
transcript.append_message(b"testing", b"initializing transcript for testing")?;
let subclaim =
<PolyIOP<Fr> as ZeroCheck<Fr>>::verify(&proof, &poly_info, &mut transcript)?.0;
<PolyIOP<Fr> as ZeroCheck<Fr>>::verify(&proof, &poly_info, &mut transcript)?
.sum_check_sub_claim;
assert!(
poly.evaluate(&subclaim.point)? == subclaim.expected_evaluation,
"wrong subclaim"
);
println!(
"zero check verification time for {} variables and {} degree:: {} ns",
"zero check verification time for {} variables and {} degree: {} ns",
nv,
degree,
start.elapsed().as_nanos() / repetition as u128
Expand All @@ -123,3 +130,84 @@ fn bench_zero_check() -> Result<(), PolyIOPErrors> {
}
Ok(())
}

fn bench_permutation_check() -> Result<(), PolyIOPErrors> {
let mut rng = test_rng();

for nv in 4..20 {
let repetition = if nv < 10 {
100
} else if nv < 20 {
50
} else {
10
};

let w = DenseMultilinearExtension::rand(nv, &mut rng);

// s_perm is the identity map
let s_perm = identity_permutation_mle(nv);

let proof = {
let start = Instant::now();
let mut transcript = <PolyIOP<Fr> as PermutationCheck<Fr>>::init_transcript();
transcript.append_message(b"testing", b"initializing transcript for testing")?;

let mut challenge =
<PolyIOP<Fr> as PermutationCheck<Fr>>::generate_challenge(&mut transcript)?;

let prod_x_and_aux = <PolyIOP<Fr> as PermutationCheck<Fr>>::compute_products(
&challenge, &w, &w, &s_perm,
)?;

let prod_x_binding = mock_commit(&prod_x_and_aux[0]);

<PolyIOP<Fr> as PermutationCheck<Fr>>::update_challenge(
&mut challenge,
&mut transcript,
&prod_x_binding,
)?;

let proof = <PolyIOP<Fr> as PermutationCheck<Fr>>::prove(
&prod_x_and_aux,
&challenge,
&mut transcript,
)?;

println!(
"permutation check proving time for {} variables: {} ns",
nv,
start.elapsed().as_nanos() / repetition as u128
);
proof
};

{
chancharles92 marked this conversation as resolved.
Show resolved Hide resolved
let poly_info = VPAuxInfo {
max_degree: 2,
num_variables: nv,
phantom: PhantomData::default(),
};

let start = Instant::now();
let mut transcript = <PolyIOP<Fr> as PermutationCheck<Fr>>::init_transcript();
transcript.append_message(b"testing", b"initializing transcript for testing")?;
let _subclaim =
<PolyIOP<Fr> as PermutationCheck<Fr>>::verify(&proof, &poly_info, &mut transcript)?;
println!(
"permutation check verification time for {} variables: {} ns",
nv,
start.elapsed().as_nanos() / repetition as u128
);
}

println!("====================================");
}

Ok(())
}

fn mock_commit(_f: &DenseMultilinearExtension<Fr>) -> Fr {
let mut rng = test_rng();
Fr::rand(&mut rng)
}
3 changes: 2 additions & 1 deletion poly-iop/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Poly IOP
Implements the following protocols

- [x] sum checks
- [x] zero checks
- [x] zero checks
- [x] permutation checks
6 changes: 5 additions & 1 deletion poly-iop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ mod virtual_poly;
mod zero_check;

pub use errors::PolyIOPErrors;
pub use perm_check::{
util::{identity_permutation_mle, random_permutation_mle},
PermutationCheck,
};
pub use sum_check::SumCheck;
pub use virtual_poly::VirtualPolynomial;
pub use virtual_poly::{VPAuxInfo, VirtualPolynomial};
pub use zero_check::ZeroCheck;

#[derive(Clone, Debug, Default, Copy)]
Expand Down
Loading