From 113df52148668eb6c2d1a9534692ff89c2c5969a Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Fri, 20 Dec 2024 13:17:28 +0000 Subject: [PATCH 1/2] fix error due to chunk size being defined differently in proving and preprocessing --- plonkish_backend/src/accumulation/protostar/hyperplonk.rs | 1 + plonkish_backend/src/backend/hyperplonk.rs | 2 ++ plonkish_backend/src/backend/hyperplonk/preprocessor.rs | 8 ++++---- plonkish_backend/src/backend/hyperplonk/prover.rs | 3 +-- plonkish_backend/src/backend/hyperplonk/util.rs | 6 ++++-- plonkish_backend/src/backend/unihyperplonk.rs | 1 + 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plonkish_backend/src/accumulation/protostar/hyperplonk.rs b/plonkish_backend/src/accumulation/protostar/hyperplonk.rs index 221cab44..1472ad44 100644 --- a/plonkish_backend/src/accumulation/protostar/hyperplonk.rs +++ b/plonkish_backend/src/accumulation/protostar/hyperplonk.rs @@ -458,6 +458,7 @@ where ] .collect_vec(); let permutation_z_polys = permutation_z_polys::<_, BinaryField>( + pp.max_degree -1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys, diff --git a/plonkish_backend/src/backend/hyperplonk.rs b/plonkish_backend/src/backend/hyperplonk.rs index 48c8296a..9cce8343 100644 --- a/plonkish_backend/src/backend/hyperplonk.rs +++ b/plonkish_backend/src/backend/hyperplonk.rs @@ -44,6 +44,7 @@ where F: PrimeField, Pcs: PolynomialCommitmentScheme, { + pub(crate) max_degree: usize, pub(crate) pcs: Pcs::ProverParam, pub(crate) num_instances: Vec, pub(crate) num_witness_polys: Vec, @@ -190,6 +191,7 @@ where let timer = start_timer(|| format!("permutation_z_polys-{}", pp.permutation_polys.len())); let permutation_z_polys = permutation_z_polys::<_, BinaryField>( + pp.max_degree -1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys, diff --git a/plonkish_backend/src/backend/hyperplonk/preprocessor.rs b/plonkish_backend/src/backend/hyperplonk/preprocessor.rs index 6aa7bc05..1c9e1f76 100644 --- a/plonkish_backend/src/backend/hyperplonk/preprocessor.rs +++ b/plonkish_backend/src/backend/hyperplonk/preprocessor.rs @@ -50,7 +50,6 @@ pub(crate) fn preprocess>( let batch_size = batch_size(circuit_info); // Trim the parameters for the PCS to those necessary for the size of the circuit let (pcs_pp, pcs_vp) = Pcs::trim(param, poly_size, batch_size)?; - // Compute preprocesses comms let preprocess_polys = circuit_info .preprocess_polys @@ -70,7 +69,7 @@ pub(crate) fn preprocess>( let (permutation_polys, permutation_comms) = batch_commit(&pcs_pp, permutation_polys)?; // Compose an expression for all the constraints - let (num_permutation_z_polys, expression) = compose(circuit_info); + let (num_permutation_z_polys, expression, max_degree) = compose(circuit_info); // Setup parameters for verifier and prover let vp = HyperPlonkVerifierParam { pcs: pcs_vp, @@ -89,6 +88,7 @@ pub(crate) fn preprocess>( .collect(), }; let pp = HyperPlonkProverParam { + max_degree, pcs: pcs_pp, num_instances: circuit_info.num_instances.clone(), num_witness_polys: circuit_info.num_witness_polys.clone(), @@ -112,7 +112,7 @@ pub(crate) fn preprocess>( // compose all constraints pub(crate) fn compose( circuit_info: &PlonkishCircuitInfo, -) -> (usize, Expression) { +) -> (usize, Expression, usize) { //total number of challenges let challenge_offset = circuit_info.num_challenges.iter().sum::(); // Generates three extra challenges beta, gamma, alpha @@ -150,7 +150,7 @@ pub(crate) fn compose( ) }; - (num_permutation_z_polys, expression) + (num_permutation_z_polys, expression, max_degree) } pub(super) fn max_degree( diff --git a/plonkish_backend/src/backend/hyperplonk/prover.rs b/plonkish_backend/src/backend/hyperplonk/prover.rs index 52fd4462..cafcc257 100644 --- a/plonkish_backend/src/backend/hyperplonk/prover.rs +++ b/plonkish_backend/src/backend/hyperplonk/prover.rs @@ -262,6 +262,7 @@ pub(super) fn lookup_h_poly( // Generates equality constraint polynomials pub(crate) fn permutation_z_polys>( + chunk_size: usize, num_chunks: usize, permutation_polys: &[(usize, MultilinearPolynomial)], polys: &[impl Borrow>], @@ -272,7 +273,6 @@ pub(crate) fn permutation_z_polys>( return Vec::new(); } // permutation polys are split into chunks due to maximum constraint degree - let chunk_size = div_ceil(permutation_polys.len(), num_chunks); let polys = polys.iter().map(Borrow::borrow).collect_vec(); let num_vars = polys[0].num_vars(); @@ -387,7 +387,6 @@ pub(crate) fn prove_sum_check( sum, transcript, )?; - // Set of all polynomial queries in the expression let pcs_query = pcs_query(expression, num_instance_poly); let point_offset = point_offset(&pcs_query); diff --git a/plonkish_backend/src/backend/hyperplonk/util.rs b/plonkish_backend/src/backend/hyperplonk/util.rs index 96d1d995..bf37b940 100644 --- a/plonkish_backend/src/backend/hyperplonk/util.rs +++ b/plonkish_backend/src/backend/hyperplonk/util.rs @@ -56,7 +56,7 @@ pub fn vanilla_plonk_expression(num_vars: usize) -> Expression Default::default(), vec![vec![(6, 1)], vec![(7, 1)], vec![(8, 1)]], ); - let (num_permutation_z_polys, expression) = compose(&circuit_info); + let (num_permutation_z_polys, expression, _) = compose(&circuit_info); assert_eq!(num_permutation_z_polys, 1); expression } @@ -93,7 +93,7 @@ pub fn vanilla_plonk_w_lookup_expression(num_vars: usize) -> Expr Default::default(), vec![vec![(10, 1)], vec![(11, 1)], vec![(12, 1)]], ); - let (num_permutation_z_polys, expression) = compose(&circuit_info); + let (num_permutation_z_polys, expression, _) = compose(&circuit_info); assert_eq!(num_permutation_z_polys, 1); expression } @@ -190,6 +190,7 @@ pub fn rand_vanilla_plonk_assignment>( let permutation_polys = permutation_polys(num_vars, &[6, 7, 8], &permutations); let permutation_z_polys = permutation_z_polys::<_, R>( + 3, 1, &[6, 7, 8] .into_iter() @@ -348,6 +349,7 @@ pub fn rand_vanilla_plonk_w_lookup_assignment( + 3, 1, &[10, 11, 12] .into_iter() diff --git a/plonkish_backend/src/backend/unihyperplonk.rs b/plonkish_backend/src/backend/unihyperplonk.rs index d8737c45..f3fbca8f 100644 --- a/plonkish_backend/src/backend/unihyperplonk.rs +++ b/plonkish_backend/src/backend/unihyperplonk.rs @@ -193,6 +193,7 @@ where let timer = start_timer(|| format!("permutation_z_polys-{}", pp.permutation_polys.len())); let permutation_z_polys = permutation_z_polys::<_, Lexical>( + pp.max_degree -1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys, From 70082214ea9587b0e33a81a3b042a7822dbf7b0b Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Fri, 20 Dec 2024 13:31:09 +0000 Subject: [PATCH 2/2] fix: linting error --- plonkish_backend/src/accumulation/protostar/hyperplonk.rs | 2 +- plonkish_backend/src/backend/hyperplonk.rs | 2 +- plonkish_backend/src/backend/unihyperplonk.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plonkish_backend/src/accumulation/protostar/hyperplonk.rs b/plonkish_backend/src/accumulation/protostar/hyperplonk.rs index 1472ad44..afb11bea 100644 --- a/plonkish_backend/src/accumulation/protostar/hyperplonk.rs +++ b/plonkish_backend/src/accumulation/protostar/hyperplonk.rs @@ -458,7 +458,7 @@ where ] .collect_vec(); let permutation_z_polys = permutation_z_polys::<_, BinaryField>( - pp.max_degree -1, + pp.max_degree - 1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys, diff --git a/plonkish_backend/src/backend/hyperplonk.rs b/plonkish_backend/src/backend/hyperplonk.rs index 9cce8343..7dab750f 100644 --- a/plonkish_backend/src/backend/hyperplonk.rs +++ b/plonkish_backend/src/backend/hyperplonk.rs @@ -191,7 +191,7 @@ where let timer = start_timer(|| format!("permutation_z_polys-{}", pp.permutation_polys.len())); let permutation_z_polys = permutation_z_polys::<_, BinaryField>( - pp.max_degree -1, + pp.max_degree - 1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys, diff --git a/plonkish_backend/src/backend/unihyperplonk.rs b/plonkish_backend/src/backend/unihyperplonk.rs index f3fbca8f..68a14cb0 100644 --- a/plonkish_backend/src/backend/unihyperplonk.rs +++ b/plonkish_backend/src/backend/unihyperplonk.rs @@ -193,7 +193,7 @@ where let timer = start_timer(|| format!("permutation_z_polys-{}", pp.permutation_polys.len())); let permutation_z_polys = permutation_z_polys::<_, Lexical>( - pp.max_degree -1, + pp.max_degree - 1, pp.num_permutation_z_polys, &pp.permutation_polys, &polys,