Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 committed Oct 21, 2023
1 parent ca985fc commit 1803a74
Show file tree
Hide file tree
Showing 7 changed files with 743 additions and 752 deletions.
2 changes: 1 addition & 1 deletion benchmark/benches/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn bench_hyperplonk<C: CircuitExt<Fr>>(k: usize) {

fn bench_unihyperplonk<C: CircuitExt<Fr>>(k: usize) {
type UnivariateKzg = univariate::UnivariateKzg<Bn256>;
type UniHyperPlonk = backend::unihyperplonk::UniHyperPlonk<UnivariateKzg>;
type UniHyperPlonk = backend::unihyperplonk::UniHyperPlonk<UnivariateKzg, true>;
bench_plonkish_backend::<UniHyperPlonk, C>(System::UniHyperPlonk, k)
}

Expand Down
67 changes: 5 additions & 62 deletions plonkish_backend/src/backend/hyperplonk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
backend::{
hyperplonk::{
preprocessor::{batch_size, compose, permutation_polys},
preprocessor::{batch_size, preprocess},
prover::{
instance_polys, lookup_compressed_polys, lookup_h_polys, lookup_m_polys,
permutation_z_polys, prove_zero_check,
Expand Down Expand Up @@ -101,67 +101,10 @@ where
param: &Pcs::Param,
circuit_info: &PlonkishCircuitInfo<F>,
) -> Result<(Self::ProverParam, Self::VerifierParam), Error> {
assert!(circuit_info.is_well_formed());

let num_vars = circuit_info.k;
let poly_size = 1 << num_vars;
let batch_size = batch_size(circuit_info);
let (pcs_pp, pcs_vp) = Pcs::trim(param, poly_size, batch_size)?;

// Compute preprocesses comms
let preprocess_polys = circuit_info
.preprocess_polys
.iter()
.cloned()
.map(MultilinearPolynomial::new)
.collect_vec();
let preprocess_comms = Pcs::batch_commit(&pcs_pp, &preprocess_polys)?;

// Compute permutation polys and comms
let permutation_polys = permutation_polys(
num_vars,
&circuit_info.permutation_polys(),
&circuit_info.permutations,
);
let permutation_comms = Pcs::batch_commit(&pcs_pp, &permutation_polys)?;

// Compose expression
let (num_permutation_z_polys, expression) = compose(circuit_info);
let vp = HyperPlonkVerifierParam {
pcs: pcs_vp,
num_instances: circuit_info.num_instances.clone(),
num_witness_polys: circuit_info.num_witness_polys.clone(),
num_challenges: circuit_info.num_challenges.clone(),
num_lookups: circuit_info.lookups.len(),
num_permutation_z_polys,
num_vars,
expression: expression.clone(),
preprocess_comms: preprocess_comms.clone(),
permutation_comms: circuit_info
.permutation_polys()
.into_iter()
.zip(permutation_comms.clone())
.collect(),
};
let pp = HyperPlonkProverParam {
pcs: pcs_pp,
num_instances: circuit_info.num_instances.clone(),
num_witness_polys: circuit_info.num_witness_polys.clone(),
num_challenges: circuit_info.num_challenges.clone(),
lookups: circuit_info.lookups.clone(),
num_permutation_z_polys,
num_vars,
expression,
preprocess_polys,
preprocess_comms,
permutation_polys: circuit_info
.permutation_polys()
.into_iter()
.zip(permutation_polys)
.collect(),
permutation_comms,
};
Ok((pp, vp))
preprocess(param, circuit_info, |pp, polys| {
let comms = Pcs::batch_commit(pp, &polys)?;
Ok((polys, comms))
})
}

fn prove(
Expand Down
85 changes: 84 additions & 1 deletion plonkish_backend/src/backend/hyperplonk/preprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::{
backend::PlonkishCircuitInfo,
backend::{
hyperplonk::{HyperPlonkProverParam, HyperPlonkVerifierParam},
PlonkishCircuitInfo,
},
pcs::PolynomialCommitmentScheme,
poly::multilinear::MultilinearPolynomial,
util::{
arithmetic::{div_ceil, steps, PrimeField},
chain,
expression::{Expression, Query, Rotation},
Itertools,
},
Error,
};
use std::{array, borrow::Cow, mem};

Expand All @@ -22,6 +27,84 @@ pub(crate) fn batch_size<F: PrimeField>(circuit_info: &PlonkishCircuitInfo<F>) -
.sum()
}

#[allow(clippy::type_complexity)]
pub(crate) fn preprocess<F: PrimeField, Pcs: PolynomialCommitmentScheme<F>>(
param: &Pcs::Param,
circuit_info: &PlonkishCircuitInfo<F>,
batch_commit: impl Fn(
&Pcs::ProverParam,
Vec<MultilinearPolynomial<F>>,
) -> Result<(Vec<MultilinearPolynomial<F>>, Vec<Pcs::Commitment>), Error>,
) -> Result<
(
HyperPlonkProverParam<F, Pcs>,
HyperPlonkVerifierParam<F, Pcs>,
),
Error,
> {
assert!(circuit_info.is_well_formed());

let num_vars = circuit_info.k;
let poly_size = 1 << num_vars;
let batch_size = batch_size(circuit_info);
let (pcs_pp, pcs_vp) = Pcs::trim(param, poly_size, batch_size)?;

// Compute preprocesses comms
let preprocess_polys = circuit_info
.preprocess_polys
.iter()
.cloned()
.map(MultilinearPolynomial::new)
.collect_vec();
let (preprocess_polys, preprocess_comms) = batch_commit(&pcs_pp, preprocess_polys)?;

// Compute permutation polys and comms
let permutation_polys = permutation_polys(
num_vars,
&circuit_info.permutation_polys(),
&circuit_info.permutations,
);
let (permutation_polys, permutation_comms) = batch_commit(&pcs_pp, permutation_polys)?;

// Compose expression
let (num_permutation_z_polys, expression) = compose(circuit_info);
let vp = HyperPlonkVerifierParam {
pcs: pcs_vp,
num_instances: circuit_info.num_instances.clone(),
num_witness_polys: circuit_info.num_witness_polys.clone(),
num_challenges: circuit_info.num_challenges.clone(),
num_lookups: circuit_info.lookups.len(),
num_permutation_z_polys,
num_vars,
expression: expression.clone(),
preprocess_comms: preprocess_comms.clone(),
permutation_comms: circuit_info
.permutation_polys()
.into_iter()
.zip(permutation_comms.clone())
.collect(),
};
let pp = HyperPlonkProverParam {
pcs: pcs_pp,
num_instances: circuit_info.num_instances.clone(),
num_witness_polys: circuit_info.num_witness_polys.clone(),
num_challenges: circuit_info.num_challenges.clone(),
lookups: circuit_info.lookups.clone(),
num_permutation_z_polys,
num_vars,
expression,
preprocess_polys,
preprocess_comms,
permutation_polys: circuit_info
.permutation_polys()
.into_iter()
.zip(permutation_polys)
.collect(),
permutation_comms,
};
Ok((pp, vp))
}

pub(crate) fn compose<F: PrimeField>(
circuit_info: &PlonkishCircuitInfo<F>,
) -> (usize, Expression<F>) {
Expand Down
Loading

0 comments on commit 1803a74

Please sign in to comment.