Skip to content

Commit

Permalink
More suggestiosn
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Nov 8, 2024
1 parent cd55879 commit 9397b06
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
6 changes: 3 additions & 3 deletions mpcs/benches/basefold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::{Itertools, chain};
use mpcs::{
Basefold, BasefoldBasecodeParams, BasefoldRSParams, Evaluation, PolynomialCommitmentScheme,
test_util::{
commit_polys_individually, gen_rand_poly_base, gen_rand_poly_ext, gen_rand_polys_general,
commit_polys_individually, gen_rand_poly_base, gen_rand_poly_ext, gen_rand_polys,
get_point_from_challenge, get_points_from_challenge, setup_pcs,
},
util::plonky2_util::log2_ceil,
Expand Down Expand Up @@ -141,7 +141,7 @@ fn bench_batch_commit_open_verify_goldilocks<Pcs: PolynomialCommitmentScheme<E>>
.collect_vec();

let mut transcript = T::new(b"BaseFold");
let polys = gen_rand_polys_general(
let polys = gen_rand_polys(
|i| num_vars - log2_ceil((i >> 1) + 1),
batch_size,
switch.gen_rand_poly,
Expand Down Expand Up @@ -247,7 +247,7 @@ fn bench_simple_batch_commit_open_verify_goldilocks<Pcs: PolynomialCommitmentSch
let batch_size = 1 << batch_size_log;
let (pp, vp) = setup_pcs::<E, Pcs>(num_vars);
let mut transcript = T::new(b"BaseFold");
let polys = gen_rand_polys_general(|_| num_vars, batch_size, switch.gen_rand_poly);
let polys = gen_rand_polys(|_| num_vars, batch_size, switch.gen_rand_poly);
let comm = Pcs::batch_commit_and_write(&pp, &polys, &mut transcript).unwrap();

group.bench_function(
Expand Down
60 changes: 43 additions & 17 deletions mpcs/src/basefold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@ mod test {
use crate::{
basefold::Basefold,
test_util::{
run_batch_commit_open_verify, run_commit_open_verify,
run_simple_batch_commit_open_verify,
gen_rand_poly_base, gen_rand_poly_ext, run_batch_commit_open_verify,
run_commit_open_verify, run_simple_batch_commit_open_verify,
},
};
use goldilocks::GoldilocksExt2;
Expand All @@ -1192,52 +1192,78 @@ mod test {

#[test]
fn commit_open_verify_goldilocks() {
for base in [true, false].into_iter() {
for gen_rand_poly in [gen_rand_poly_base, gen_rand_poly_ext] {
// Challenge is over extension field, poly over the base field
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(base, 10, 11);
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(gen_rand_poly, 10, 11);
// Test trivial proof with small num vars
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(base, 4, 6);
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(gen_rand_poly, 4, 6);
// Challenge is over extension field, poly over the base field
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(base, 10, 11);
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(gen_rand_poly, 10, 11);
// Test trivial proof with small num vars
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(base, 4, 6);
run_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(gen_rand_poly, 4, 6);
}
}

#[test]
fn simple_batch_commit_open_verify_goldilocks() {
for base in [true, false].into_iter() {
for gen_rand_poly in [gen_rand_poly_base, gen_rand_poly_ext] {
// Both challenge and poly are over base field
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(
base, 10, 11, 1,
gen_rand_poly,
10,
11,
1,
);
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(
base, 10, 11, 4,
gen_rand_poly,
10,
11,
4,
);
// Test trivial proof with small num vars
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(
base, 4, 6, 4,
gen_rand_poly,
4,
6,
4,
);
// Both challenge and poly are over base field
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(
base, 10, 11, 1,
gen_rand_poly,
10,
11,
1,
);
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(
base, 10, 11, 4,
gen_rand_poly,
10,
11,
4,
);
// Test trivial proof with small num vars
run_simple_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(
base, 4, 6, 4,
gen_rand_poly,
4,
6,
4,
);
}
}

#[test]
fn batch_commit_open_verify() {
for base in [true, false].iter() {
for gen_rand_poly in [gen_rand_poly_base, gen_rand_poly_ext] {
// Both challenge and poly are over base field
run_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(*base, 10, 11);
run_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(*base, 10, 11);
run_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksBaseCode>(
gen_rand_poly,
10,
11,
);
run_batch_commit_open_verify::<GoldilocksExt2, PcsGoldilocksRSCode>(
gen_rand_poly,
10,
11,
);
}
}
}
35 changes: 7 additions & 28 deletions mpcs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,7 @@ pub mod test_util {
)
}

pub fn gen_rand_poly<E: ExtensionField>(
num_vars: usize,
base: bool,
) -> DenseMultilinearExtension<E> {
if base {
gen_rand_poly_base(num_vars)
} else {
gen_rand_poly_ext(num_vars)
}
}

pub fn gen_rand_polys_general<E: ExtensionField>(
pub fn gen_rand_polys<E: ExtensionField>(
num_vars: impl Fn(usize) -> usize,
batch_size: usize,
gen_rand_poly: fn(usize) -> DenseMultilinearExtension<E>,
Expand All @@ -424,16 +413,6 @@ pub mod test_util {
.collect_vec()
}

pub fn gen_rand_polys<E: ExtensionField>(
num_vars: impl Fn(usize) -> usize,
batch_size: usize,
base: bool,
) -> Vec<DenseMultilinearExtension<E>> {
(0..batch_size)
.map(|i| gen_rand_poly(num_vars(i), base))
.collect_vec()
}

pub fn get_point_from_challenge<E: ExtensionField>(
num_vars: usize,
transcript: &mut Transcript<E>,
Expand Down Expand Up @@ -465,7 +444,7 @@ pub mod test_util {

#[cfg(test)]
pub fn run_commit_open_verify<E: ExtensionField, Pcs>(
base: bool,
gen_rand_poly: fn(usize) -> DenseMultilinearExtension<E>,
num_vars_start: usize,
num_vars_end: usize,
) where
Expand All @@ -477,7 +456,7 @@ pub mod test_util {
// Commit and open
let (comm, eval, proof, challenge) = {
let mut transcript = Transcript::new(b"BaseFold");
let poly = gen_rand_poly(num_vars, base);
let poly = gen_rand_poly(num_vars);
let comm = Pcs::commit_and_write(&pp, &poly, &mut transcript).unwrap();
let point = get_point_from_challenge(num_vars, &mut transcript);
let eval = poly.evaluate(point.as_slice());
Expand Down Expand Up @@ -506,7 +485,7 @@ pub mod test_util {

#[cfg(test)]
pub fn run_batch_commit_open_verify<E, Pcs>(
base: bool,
gen_rand_poly: fn(usize) -> DenseMultilinearExtension<E>,
num_vars_start: usize,
num_vars_end: usize,
) where
Expand All @@ -528,7 +507,7 @@ pub mod test_util {

let (comms, evals, proof, challenge) = {
let mut transcript = Transcript::new(b"BaseFold");
let polys = gen_rand_polys(|i| num_vars - (i >> 1), batch_size, base);
let polys = gen_rand_polys(|i| num_vars - (i >> 1), batch_size, gen_rand_poly);

let comms =
commit_polys_individually::<E, Pcs>(&pp, polys.as_slice(), &mut transcript);
Expand Down Expand Up @@ -587,7 +566,7 @@ pub mod test_util {

#[cfg(test)]
pub(super) fn run_simple_batch_commit_open_verify<E, Pcs>(
base: bool,
gen_rand_poly: fn(usize) -> DenseMultilinearExtension<E>,
num_vars_start: usize,
num_vars_end: usize,
batch_size: usize,
Expand All @@ -600,7 +579,7 @@ pub mod test_util {

let (comm, evals, proof, challenge) = {
let mut transcript = Transcript::new(b"BaseFold");
let polys = gen_rand_polys(|_| num_vars, batch_size, base);
let polys = gen_rand_polys(|_| num_vars, batch_size, gen_rand_poly);
let comm =
Pcs::batch_commit_and_write(&pp, polys.as_slice(), &mut transcript).unwrap();
let point = get_point_from_challenge(num_vars, &mut transcript);
Expand Down

0 comments on commit 9397b06

Please sign in to comment.