Skip to content

Commit

Permalink
Merge pull request #12 from EYBlockchain/lyd/chunkSizeError
Browse files Browse the repository at this point in the history
fix error due to chunk size being defined differently in proving and …
  • Loading branch information
Michael-EY authored Dec 20, 2024
2 parents c633374 + 7008221 commit e4455b0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions plonkish_backend/src/accumulation/protostar/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plonkish_backend/src/backend/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
F: PrimeField,
Pcs: PolynomialCommitmentScheme<F>,
{
pub(crate) max_degree: usize,
pub(crate) pcs: Pcs::ProverParam,
pub(crate) num_instances: Vec<usize>,
pub(crate) num_witness_polys: Vec<usize>,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions plonkish_backend/src/backend/hyperplonk/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub(crate) fn preprocess<F: PrimeField, Pcs: PolynomialCommitmentScheme<F>>(
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
Expand All @@ -70,7 +69,7 @@ pub(crate) fn preprocess<F: PrimeField, Pcs: PolynomialCommitmentScheme<F>>(
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,
Expand All @@ -89,6 +88,7 @@ pub(crate) fn preprocess<F: PrimeField, Pcs: PolynomialCommitmentScheme<F>>(
.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(),
Expand All @@ -112,7 +112,7 @@ pub(crate) fn preprocess<F: PrimeField, Pcs: PolynomialCommitmentScheme<F>>(
// compose all constraints
pub(crate) fn compose<F: PrimeField>(
circuit_info: &PlonkishCircuitInfo<F>,
) -> (usize, Expression<F>) {
) -> (usize, Expression<F>, usize) {
//total number of challenges
let challenge_offset = circuit_info.num_challenges.iter().sum::<usize>();
// Generates three extra challenges beta, gamma, alpha
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) fn compose<F: PrimeField>(
)
};

(num_permutation_z_polys, expression)
(num_permutation_z_polys, expression, max_degree)
}

pub(super) fn max_degree<F: PrimeField>(
Expand Down
3 changes: 1 addition & 2 deletions plonkish_backend/src/backend/hyperplonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ pub(super) fn lookup_h_poly<F: PrimeField + Hash>(

// Generates equality constraint polynomials
pub(crate) fn permutation_z_polys<F: PrimeField, R: Rotatable + From<usize>>(
chunk_size: usize,
num_chunks: usize,
permutation_polys: &[(usize, MultilinearPolynomial<F>)],
polys: &[impl Borrow<MultilinearPolynomial<F>>],
Expand All @@ -269,7 +270,6 @@ pub(crate) fn permutation_z_polys<F: PrimeField, R: Rotatable + From<usize>>(
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();

Expand Down Expand Up @@ -384,7 +384,6 @@ pub(crate) fn prove_sum_check<F: PrimeField>(
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);
Expand Down
6 changes: 4 additions & 2 deletions plonkish_backend/src/backend/hyperplonk/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn vanilla_plonk_expression<F: PrimeField>(num_vars: usize) -> Expression<F>
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
}
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn vanilla_plonk_w_lookup_expression<F: PrimeField>(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
}
Expand Down Expand Up @@ -190,6 +190,7 @@ pub fn rand_vanilla_plonk_assignment<F: PrimeField, R: Rotatable + From<usize>>(

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()
Expand Down Expand Up @@ -348,6 +349,7 @@ pub fn rand_vanilla_plonk_w_lookup_assignment<F: PrimeField + Hash, R: Rotatable

let permutation_polys = permutation_polys(num_vars, &[10, 11, 12], &permutations);
let permutation_z_polys = permutation_z_polys::<_, R>(
3,
1,
&[10, 11, 12]
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions plonkish_backend/src/backend/unihyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e4455b0

Please sign in to comment.