Skip to content

Commit

Permalink
Revert "Revert "Merge remote-tracking branch 'origin/main' into lydia…
Browse files Browse the repository at this point in the history
…/poseidoncircuit""

This reverts commit b6f0f99.
  • Loading branch information
lydiagarms committed Jan 6, 2025
1 parent 3002187 commit f5ae9e0
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 75 deletions.
12 changes: 7 additions & 5 deletions plonkish_backend/src/accumulation/protostar/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ pub(crate) mod test {
HyperPlonk,
},
pcs::{
multilinear::{Gemini, MultilinearIpa, MultilinearKzg, Zeromorph},
univariate::UnivariateKzg,
multilinear::Zeromorph,
univariate::{UnivariateIpa, UnivariateKzg},
},
util::{
expression::rotate::BinaryField,
Expand Down Expand Up @@ -641,8 +641,10 @@ pub(crate) mod test {
};
}

tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
tests!(kzg, MultilinearKzg<Bn256>);
tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
//tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
//tests!(kzg, MultilinearKzg<Bn256>);
//tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
tests!(zeromorph_kzg, Zeromorph<UnivariateKzg<Bn256>>);
//tests!(gemini_ipa, Gemini<UnivariateIpa<grumpkin::G1Affine>>);
tests!(zeromorph_ipa, Zeromorph<UnivariateIpa<grumpkin::G1Affine>>);
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,10 @@ pub(crate) fn lookup_constraints<F: PrimeField>(
let [m, h_input, h_table] = &[m, h, h + 1]
.map(|poly| Query::new(poly, Rotation::cur()))
.map(Expression::<F>::Polynomial);
let (inputs, tables) = lookup
.iter()
.map(|(input, table)| (input, table))
.unzip::<_, _, Vec<_>, Vec<_>>();
let (inputs, tables) = lookup.iter().cloned().unzip::<_, _, Vec<_>, Vec<_>>();
let [input, table] = &[inputs, tables].map(|exprs| {
chain![
exprs.first().cloned().cloned(),
exprs.first().cloned(),
exprs
.into_iter()
.skip(1)
Expand Down
12 changes: 7 additions & 5 deletions plonkish_backend/src/accumulation/sangria/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub(crate) mod test {
HyperPlonk,
},
pcs::{
multilinear::{Gemini, MultilinearIpa, MultilinearKzg, Zeromorph},
univariate::UnivariateKzg,
multilinear::Zeromorph,
univariate::{UnivariateIpa, UnivariateKzg},
},
util::{
expression::rotate::BinaryField,
Expand Down Expand Up @@ -53,8 +53,10 @@ pub(crate) mod test {
};
}

tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
tests!(kzg, MultilinearKzg<Bn256>);
tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
//tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
//tests!(kzg, MultilinearKzg<Bn256>);
//tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
tests!(zeromorph_kzg, Zeromorph<UnivariateKzg<Bn256>>);
//tests!(gemini_ipa, Gemini<UnivariateIpa<grumpkin::G1Affine>>);
tests!(zeromorph_ipa, Zeromorph<UnivariateIpa<grumpkin::G1Affine>>);
}
27 changes: 11 additions & 16 deletions plonkish_backend/src/backend/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,14 @@ mod test {
test::run_plonkish_backend,
},
pcs::{
multilinear::{
Gemini, MultilinearBrakedown, MultilinearHyrax, MultilinearIpa, MultilinearKzg,
Zeromorph,
},
univariate::UnivariateKzg,
multilinear::Zeromorph,
univariate::{UnivariateIpa, UnivariateKzg},
},
util::{
code::BrakedownSpec6, expression::rotate::BinaryField, hash::Keccak256,
test::seeded_std_rng, transcript::Keccak256Transcript,
expression::rotate::BinaryField, test::seeded_std_rng, transcript::Keccak256Transcript,
},
};
use halo2_curves::{
bn256::{self, Bn256},
grumpkin,
};
use halo2_curves::{bn256::Bn256, grumpkin};

macro_rules! tests {
($suffix:ident, $pcs:ty, $num_vars_range:expr) => {
Expand All @@ -383,10 +376,12 @@ mod test {
};
}

tests!(brakedown, MultilinearBrakedown<bn256::Fr, Keccak256, BrakedownSpec6>);
tests!(hyrax, MultilinearHyrax<grumpkin::G1Affine>, 5..16);
tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
tests!(kzg, MultilinearKzg<Bn256>);
tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
//tests!(brakedown, MultilinearBrakedown<bn256::Fr, Keccak256, BrakedownSpec6>);
//tests!(hyrax, MultilinearHyrax<grumpkin::G1Affine>, 5..16);
//tests!(ipa, MultilinearIpa<grumpkin::G1Affine>);
//tests!(kzg, MultilinearKzg<Bn256>);
//tests!(gemini_kzg, Gemini<UnivariateKzg<Bn256>>);
tests!(zeromorph_kzg, Zeromorph<UnivariateKzg<Bn256>>);
//tests!(gemini_ipa, Gemini<UnivariateIpa<grumpkin::G1Affine>>);
tests!(zeromorph_ipa, Zeromorph<UnivariateIpa<grumpkin::G1Affine>>);
}
9 changes: 3 additions & 6 deletions plonkish_backend/src/backend/hyperplonk/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ pub(super) fn lookup_constraints<F: PrimeField>(
.map(|poly| Query::new(poly, Rotation::cur()))
.map(Expression::<F>::Polynomial);
// separate the input and tables from the lookup
let (inputs, tables) = lookup
.iter()
.map(|(input, table)| (input, table))
.unzip::<_, _, Vec<_>, Vec<_>>();
// Returns a distributed power expression for the input and table, with base beta, i.e. inputs[0] + \beta inputs[1] + \beta^2 inputs[2] + ...
let (inputs, tables) = lookup.iter().cloned().unzip::<_, _, Vec<_>, Vec<_>>();
let input = &Expression::distribute_powers(inputs, beta);
let table = &Expression::distribute_powers(tables, beta);
// h[i] = (gamma + input[i])^-1 - m[i] * (gamma + table[i])^-1
Expand Down Expand Up @@ -298,7 +294,8 @@ pub(crate) fn permutation_polys<F: PrimeField>(
}
poly_index
};
// permutations will be the matrix defining all permutation polynomials. As we start with the identity permutation, all entries have value of the index within the matrix.
// Permutations will be the matrix defining all permutation polynomials.
// As we start with the identity permutation, all entries have value of the index within the matrix.
let mut permutations = (0..permutation_polys.len() as u64)
.map(|idx| {
steps(F::from(idx << num_vars))
Expand Down
9 changes: 3 additions & 6 deletions plonkish_backend/src/backend/hyperplonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,14 @@ pub(super) fn lookup_compressed_poly<F: PrimeField, R: Rotatable + From<usize>>(
};

// split inputs and tables into separate vectors
let (inputs, tables) = lookup
.iter()
.map(|(input, table)| (input, table))
.unzip::<_, _, Vec<_>, Vec<_>>();
let (inputs, tables) = lookup.iter().cloned().unzip::<_, _, Vec<_>, Vec<_>>();

let timer = start_timer(|| "compressed_input_poly");
let compressed_input_poly = compress(&inputs);
let compressed_input_poly = compress(&inputs.iter().collect::<Vec<_>>());
end_timer(timer);

let timer = start_timer(|| "compressed_table_poly");
let compressed_table_poly = compress(&tables);
let compressed_table_poly = compress(&tables.iter().collect::<Vec<_>>());
end_timer(timer);

[compressed_input_poly, compressed_table_poly]
Expand Down
2 changes: 1 addition & 1 deletion plonkish_backend/src/backend/hyperplonk/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn vanilla_plonk_circuit_info<F: PrimeField>(
preprocess_polys: [Vec<F>; 5],
permutations: Vec<Vec<(usize, usize)>>,
) -> PlonkishCircuitInfo<F> {
let [pi, q_l, q_r, q_m, q_o, q_c, w_l, w_r, w_o] =
let [pi, q_l, q_r, q_m, q_o, q_c, w_l, w_r, w_o]: &[Expression<F>; 9] =
&array::from_fn(|poly| Query::new(poly, Rotation::cur())).map(Expression::Polynomial);
PlonkishCircuitInfo {
k: num_vars,
Expand Down
2 changes: 2 additions & 0 deletions plonkish_backend/src/backend/unihyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,15 @@ mod test {
($suffix:ident, $pcs:ty, $additive:literal, $num_vars_range:expr) => {
paste::paste! {
#[test]
#[ignore = "we do not currently use UniHyperPlonk"]
fn [<vanilla_plonk_w_ $suffix>]() {
run_plonkish_backend::<_, UniHyperPlonk<$pcs, $additive>, Keccak256Transcript<_>, _>($num_vars_range, |num_vars| {
rand_vanilla_plonk_circuit::<_, Lexical>(num_vars, seeded_std_rng(), seeded_std_rng())
});
}

#[test]
#[ignore = "we do not currently use UniHyperPlonk"]
fn [<vanilla_plonk_w_lookup_w_ $suffix>]() {
run_plonkish_backend::<_, UniHyperPlonk<$pcs, $additive>, Keccak256Transcript<_>, _>($num_vars_range, |num_vars| {
rand_vanilla_plonk_w_lookup_circuit::<_, Lexical>(num_vars, seeded_std_rng(), seeded_std_rng())
Expand Down
8 changes: 4 additions & 4 deletions plonkish_backend/src/frontend/halo2/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod vanilla_plonk {
}

#[derive(Clone, Default)]
pub struct VanillaPlonk<F>(usize, Vec<[Assigned<F>; 8]>);
pub struct VanillaPlonk<F>(Vec<[Assigned<F>; 8]>);

impl<F: Field> Circuit<F> for VanillaPlonk<F> {
type Config = VanillaPlonkConfig;
Expand All @@ -76,7 +76,7 @@ mod vanilla_plonk {
layouter.assign_region(
|| "",
|mut region| {
for (offset, values) in self.1.iter().enumerate() {
for (offset, values) in self.0.iter().enumerate() {
let (selectors, wires) = values.split_at(config.selectors.len());
for (column, value) in
config.selectors.into_iter().zip(selectors.iter().copied())
Expand Down Expand Up @@ -114,11 +114,11 @@ mod vanilla_plonk {
.collect_vec(),
]
.collect();
Self(k, values)
Self(values)
}

fn instances(&self) -> Vec<Vec<F>> {
let [q_l, q_r, q_m, q_o, q_c, w_l, w_r, w_o] = self.1[0];
let [q_l, q_r, q_m, q_o, q_c, w_l, w_r, w_o] = self.0[0];
let pi = (-(q_l * w_l + q_r * w_r + q_m * w_l * w_r + q_o * w_o + q_c)).evaluate();
vec![vec![pi]]
}
Expand Down
2 changes: 2 additions & 0 deletions plonkish_backend/src/pcs/multilinear/brakedown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,13 @@ mod test {
type Pcs = MultilinearBrakedown<Fr, Keccak256, BrakedownSpec6>;

#[test]
#[ignore = "we do not currently use brakedown"]
fn commit_open_verify() {
run_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}

#[test]
#[ignore = "we do not currently use brakedown"]
fn batch_commit_open_verify() {
run_batch_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}
Expand Down
16 changes: 11 additions & 5 deletions plonkish_backend/src/pcs/multilinear/gemini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
pcs::{
multilinear::additive,
univariate::{
err_too_large_deree, ipa::UnivariateIpa, UnivariateIpaCommitment, UnivariateKzg,
err_too_large_degree, ipa::UnivariateIpa, UnivariateIpaCommitment, UnivariateKzg,
UnivariateKzgCommitment,
},
Evaluation, Point, PolynomialCommitmentScheme,
Expand Down Expand Up @@ -58,7 +58,7 @@ where
fn commit(pp: &Self::ProverParam, poly: &Self::Polynomial) -> Result<Self::Commitment, Error> {
if pp.degree() + 1 < poly.evals().len() {
let got = poly.evals().len() - 1;
return Err(err_too_large_deree("commit", pp.degree(), got));
return Err(err_too_large_degree("commit", pp.degree(), got));
}

Ok(UnivariateKzg::commit_monomial(pp, poly.evals()))
Expand All @@ -85,7 +85,7 @@ where
let num_vars = point.len();
if pp.degree() + 1 < poly.evals().len() {
let got = poly.evals().len() - 1;
return Err(err_too_large_deree("open", pp.degree(), got));
return Err(err_too_large_degree("open", pp.degree(), got));
}

if cfg!(feature = "sanity-check") {
Expand Down Expand Up @@ -254,10 +254,14 @@ where
fn commit(pp: &Self::ProverParam, poly: &Self::Polynomial) -> Result<Self::Commitment, Error> {
if pp.degree() + 1 < poly.evals().len() {
let got = poly.evals().len() - 1;
return Err(err_too_large_deree("commit", pp.degree(), got));
return Err(err_too_large_degree("commit", pp.degree(), got));
}
let uni_poly = UnivariatePolynomial::monomial(poly.evals().to_vec());

if uni_poly.coeffs().is_empty() {
return Ok(UnivariateIpaCommitment::<C>::default());
}

UnivariateIpa::commit(pp, &uni_poly)
}

Expand All @@ -282,7 +286,7 @@ where
let num_vars = point.len();
if pp.degree() + 1 < poly.evals().len() {
let got = poly.evals().len() - 1;
return Err(err_too_large_deree("open", pp.degree(), got));
return Err(err_too_large_degree("open", pp.degree(), got));
}

if cfg!(feature = "sanity-check") {
Expand Down Expand Up @@ -439,12 +443,14 @@ mod test {
type GemIpaPcs = Gemini<UnivariateIpa<grumpkin::G1Affine>>;

#[test]
#[ignore = "we do not currently use gemini"]
fn commit_open_verify() {
run_commit_open_verify::<_, GemKzgPcs, Keccak256Transcript<_>>();
run_commit_open_verify::<_, GemIpaPcs, Keccak256Transcript<_>>();
}

#[test]
#[ignore = "we do not currently use gemini"]
fn batch_commit_open_verify() {
run_batch_commit_open_verify::<_, GemKzgPcs, Keccak256Transcript<_>>();
run_batch_commit_open_verify::<_, GemIpaPcs, Keccak256Transcript<_>>();
Expand Down
2 changes: 2 additions & 0 deletions plonkish_backend/src/pcs/multilinear/hyrax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,13 @@ mod test {
type Pcs = MultilinearHyrax<Affine>;

#[test]
#[ignore = "we do not currently use hyrax"]
fn commit_open_verify() {
run_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}

#[test]
#[ignore = "we do not currently use hyrax"]
fn batch_commit_open_verify() {
run_batch_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}
Expand Down
6 changes: 5 additions & 1 deletion plonkish_backend/src/pcs/multilinear/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ where
fn commit(pp: &Self::ProverParam, poly: &Self::Polynomial) -> Result<Self::Commitment, Error> {
validate_input("commit", pp.num_vars(), [poly], None)?;

Ok(variable_base_msm(poly.evals(), pp.g()).into()).map(MultilinearIpaCommitment)
Ok(MultilinearIpaCommitment(
variable_base_msm(poly.evals(), pp.g()).into(),
))
}

fn batch_commit<'a>(
Expand Down Expand Up @@ -241,11 +243,13 @@ mod test {
type Pcs = MultilinearIpa<Affine>;

#[test]
#[ignore = "we do not currently use multilinear IPA"]
fn commit_open_verify() {
run_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}

#[test]
#[ignore = "we do not currently use multilinear IPA"]
fn batch_commit_open_verify() {
run_batch_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}
Expand Down
7 changes: 5 additions & 2 deletions plonkish_backend/src/pcs/multilinear/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ where
fn commit(pp: &Self::ProverParam, poly: &Self::Polynomial) -> Result<Self::Commitment, Error> {
validate_input("commit", pp.num_vars(), [poly], None)?;

Ok(variable_base_msm(poly.evals(), pp.eq(poly.num_vars())).into())
.map(MultilinearKzgCommitment)
Ok(MultilinearKzgCommitment(
variable_base_msm(poly.evals(), pp.eq(poly.num_vars())).into(),
))
}

fn batch_commit<'a>(
Expand Down Expand Up @@ -375,11 +376,13 @@ mod test {
type Pcs = MultilinearKzg<Bn256>;

#[test]
#[ignore = "we do not currently use multilinear KZG"]
fn commit_open_verify() {
run_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}

#[test]
#[ignore = "we do not currently use multilinear KZG"]
fn batch_commit_open_verify() {
run_batch_commit_open_verify::<_, Pcs, Keccak256Transcript<_>>();
}
Expand Down
Loading

0 comments on commit f5ae9e0

Please sign in to comment.