Skip to content
12 changes: 6 additions & 6 deletions arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ark-bls12-381 = { version = "0.4.0", default-features = false, features = [ "curve" ] }
ark-ff = { version = "^0.4.0", default-features = false }
ark-poly = { version = "^0.4.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
ark-bls12-381 = { version = "0.5.0", default-features = false, features = [ "curve" ] }
ark-ff = { version = "^0.5.0", default-features = false }
ark-poly = { version = "^0.5.0", default-features = false }
ark-serialize = { version = "^0.5.0", default-features = false }
ark-std = { version = "^0.5.0", default-features = false }
displaydoc = { version = "0.2.3", default-features = false }
rand_chacha = { version = "0.3.0", default-features = false }
rayon = { version = "1.5.2", default-features = false, optional = true }

[dev-dependencies]
ark-ec = { version = "^0.4.0", default-features = false }
ark-ec = { version = "^0.5.0", default-features = false }
criterion = "0.5.1"

[features]
Expand Down
4 changes: 2 additions & 2 deletions arithmetic/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#[macro_use]
extern crate criterion;

use ark_poly::Polynomial;
use arithmetic::fix_variables;
use ark_bls12_381::Fr;
use ark_ff::Field;
Expand All @@ -23,7 +23,7 @@ fn evaluation_op_bench<F: Field>(c: &mut Criterion) {
group.bench_with_input(BenchmarkId::new("evaluate native", nv), &nv, |b, &nv| {
let poly = DenseMultilinearExtension::<F>::rand(nv, &mut rng);
let point: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect();
b.iter(|| black_box(poly.evaluate(&point).unwrap()))
b.iter(|| black_box(poly.evaluate(&point)))
});

group.bench_with_input(BenchmarkId::new("evaluate optimized", nv), &nv, |b, &nv| {
Expand Down
9 changes: 3 additions & 6 deletions arithmetic/src/virtual_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use crate::{errors::ArithErrors, multilinear_polynomial::random_zero_mle_list, random_mle_list};
use ark_ff::PrimeField;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_poly::{DenseMultilinearExtension, MultilinearExtension, Polynomial};
use ark_serialize::CanonicalSerialize;
use ark_std::{
end_timer,
Expand Down Expand Up @@ -229,14 +229,11 @@ impl<F: PrimeField> VirtualPolynomial<F> {
)));
}

let point_vec = point.to_vec();
let evals: Vec<F> = self
.flattened_ml_extensions
.iter()
.map(|x| {
x.evaluate(point).unwrap() // safe unwrap here since we have
// already checked that num_var
// matches
})
.map(|x| x.evaluate(&point_vec))
.collect();

let res = self
Expand Down
12 changes: 6 additions & 6 deletions hyperplonk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ edition = "2021"

[dependencies]
arithmetic = { path = "../arithmetic" }
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-poly = { version = "^0.4.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false, features = [ "derive" ] }
ark-std = { version = "^0.4.0", default-features = false }
ark-ec = { version = "^0.5.0", default-features = false }
ark-ff = { version = "^0.5.0", default-features = false }
ark-poly = { version = "^0.5.0", default-features = false }
ark-serialize = { version = "^0.5.0", default-features = false, features = [ "derive" ] }
ark-std = { version = "^0.5.0", default-features = false }
displaydoc = { version = "0.2.3", default-features = false }
rayon = { version = "1.5.2", default-features = false, optional = true }
subroutines = { path = "../subroutines" }
transcript = { path = "../transcript" }
util = { path = "../util" }

[dev-dependencies]
ark-bls12-381 = { version = "0.4.0", default-features = false, features = [ "curve" ] }
ark-bls12-381 = { version = "0.5.0", default-features = false, features = [ "curve" ] }
# Benchmarks
[[bench]]
name = "hyperplonk-benches"
Expand Down
2 changes: 1 addition & 1 deletion hyperplonk/src/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
Evaluation = E::ScalarField,
Commitment = Commitment<E>,
BatchProof = BatchProof<E, PCS>,
>,
> + Clone + Eq + std::fmt::Debug,
{
type Index = HyperPlonkIndex<E::ScalarField>;
type ProvingKey = HyperPlonkProvingKey<E, PCS>;
Expand Down
3 changes: 2 additions & 1 deletion hyperplonk/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{custom_gate::CustomizedGates, prelude::HyperPlonkErrors, selectors::
use ark_ec::pairing::Pairing;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_serialize::CanonicalSerialize;
use ark_std::log2;
use std::sync::Arc;
use subroutines::{
Expand All @@ -22,7 +23,7 @@ use subroutines::{
/// - a batch opening to all the MLEs at certain index
/// - the zero-check proof for checking custom gate-satisfiability
/// - the permutation-check proof for checking the copy constraints
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, CanonicalSerialize)]
pub struct HyperPlonkProof<E, PC, PCS>
where
E: Pairing,
Expand Down
18 changes: 9 additions & 9 deletions hyperplonk/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod test {
use super::*;
use ark_bls12_381::Fr;
use ark_ff::PrimeField;
use ark_poly::MultilinearExtension;
use ark_poly::{MultilinearExtension, Polynomial};
#[test]
fn test_build_gate() -> Result<(), HyperPlonkErrors> {
test_build_gate_helper::<Fr>()
Expand Down Expand Up @@ -355,32 +355,32 @@ mod test {
// test eval_f
{
let point = [F::zero(), F::zero()];
let selector_evals = ql.evaluate(&point).unwrap();
let witness_evals = [w1.evaluate(&point).unwrap(), w2.evaluate(&point).unwrap()];
let selector_evals = ql.evaluate(&point.to_vec());
let witness_evals = [w1.evaluate(&point.to_vec()), w2.evaluate(&point.to_vec())];
let eval_f = eval_f(&gates, &[selector_evals], &witness_evals)?;
// f(0, 0) = 0
assert_eq!(eval_f, F::zero());
}
{
let point = [F::zero(), F::one()];
let selector_evals = ql.evaluate(&point).unwrap();
let witness_evals = [w1.evaluate(&point).unwrap(), w2.evaluate(&point).unwrap()];
let selector_evals = ql.evaluate(&point.to_vec());
let witness_evals = [w1.evaluate(&point.to_vec()), w2.evaluate(&point.to_vec())];
let eval_f = eval_f(&gates, &[selector_evals], &witness_evals)?;
// f(0, 1) = 2 * 0^5 + (-1) * 1 = -1
assert_eq!(eval_f, -F::one());
}
{
let point = [F::one(), F::zero()];
let selector_evals = ql.evaluate(&point).unwrap();
let witness_evals = [w1.evaluate(&point).unwrap(), w2.evaluate(&point).unwrap()];
let selector_evals = ql.evaluate(&point.to_vec());
let witness_evals = [w1.evaluate(&point.to_vec()), w2.evaluate(&point.to_vec())];
let eval_f = eval_f(&gates, &[selector_evals], &witness_evals)?;
// f(1, 0) = 0 * 1^5 + (-1) * 1 = -1
assert_eq!(eval_f, -F::one());
}
{
let point = [F::one(), F::one()];
let selector_evals = ql.evaluate(&point).unwrap();
let witness_evals = [w1.evaluate(&point).unwrap(), w2.evaluate(&point).unwrap()];
let selector_evals = ql.evaluate(&point.to_vec());
let witness_evals = [w1.evaluate(&point.to_vec()), w2.evaluate(&point.to_vec())];
let eval_f = eval_f(&gates, &[selector_evals], &witness_evals)?;
// f(1, 1) = 5 * 2^5 + (-1) * 2 = 158
assert_eq!(eval_f, F::from(158u64));
Expand Down
12 changes: 6 additions & 6 deletions subroutines/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"

[dependencies]
arithmetic = { path = "../arithmetic" }
ark-bls12-381 = { version = "0.4.0", default-features = false, features = [ "curve" ] }
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-poly = { version = "^0.4.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
ark-bls12-381 = { version = "0.5.0", default-features = false, features = [ "curve" ] }
ark-ec = { version = "^0.5.0", default-features = false }
ark-ff = { version = "^0.5.0", default-features = false }
ark-poly = { version = "^0.5.0", default-features = false }
ark-serialize = { version = "^0.5.0", default-features = false }
ark-std = { version = "^0.5.0", default-features = false }
derivative = { version = "2", features = ["use_core"] }
displaydoc = { version = "0.2.3", default-features = false }
itertools = { version = "0.13.0", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions subroutines/src/pcs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait PolynomialCommitmentScheme<E: Pairing> {
/// Verifier parameters
type VerifierParam: Clone + CanonicalSerialize + CanonicalDeserialize;
/// Structured reference string
type SRS: Clone + Debug;
type SRS: Clone + Debug + CanonicalSerialize + CanonicalDeserialize;
/// Polynomial and its associated types
type Polynomial: Clone + Debug + Hash + PartialEq + Eq;
/// Polynomial input domain
Expand All @@ -39,7 +39,7 @@ pub trait PolynomialCommitmentScheme<E: Pairing> {
/// Proofs
type Proof: Clone + CanonicalSerialize + CanonicalDeserialize + Debug + PartialEq + Eq;
/// Batch proofs
type BatchProof;
type BatchProof: CanonicalSerialize + CanonicalDeserialize + Clone + Debug + Eq;

/// Build SRS for testing.
///
Expand Down
16 changes: 8 additions & 8 deletions subroutines/src/pcs/multilinear_kzg/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ use crate::{
};
use arithmetic::{build_eq_x_r_vec, DenseMultilinearExtension, VPAuxInfo, VirtualPolynomial};
use ark_ec::{pairing::Pairing, scalar_mul::variable_base::VariableBaseMSM, CurveGroup};

use ark_poly::Polynomial;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{end_timer, log2, start_timer, One, Zero};
use std::{collections::BTreeMap, iter, marker::PhantomData, ops::Deref, sync::Arc};
use std::{collections::BTreeMap, fmt::Debug, iter, marker::PhantomData, ops::Deref, sync::Arc};
use transcript::IOPTranscript;

#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize)]
pub struct BatchProof<E, PCS>
where
E: Pairing,
PCS: PolynomialCommitmentScheme<E>,
PCS: PolynomialCommitmentScheme<E> + Clone + Eq + Debug,
{
/// A sum check proof proving tilde g's sum
pub(crate) sum_check_proof: IOPProof<E::ScalarField>,
Expand Down Expand Up @@ -62,7 +62,7 @@ where
Polynomial = Arc<DenseMultilinearExtension<E::ScalarField>>,
Point = Vec<E::ScalarField>,
Evaluation = E::ScalarField,
>,
>+ Clone + Eq + Debug,
{
let open_timer = start_timer!(|| format!("multi open {} points", points.len()));
for eval_point in points.iter() {
Expand Down Expand Up @@ -201,7 +201,7 @@ where
Point = Vec<E::ScalarField>,
Evaluation = E::ScalarField,
Commitment = Commitment<E>,
>,
> + Clone + Eq + Debug,
{
let open_timer = start_timer!(|| "batch verification");
for eval_point in points.iter() {
Expand Down Expand Up @@ -311,7 +311,7 @@ mod tests {
let evals = polys
.iter()
.zip(points.iter())
.map(|(f, p)| f.evaluate(p).unwrap())
.map(|(f, p)| f.evaluate(p))
.collect::<Vec<_>>();

let commitments = polys
Expand Down
15 changes: 4 additions & 11 deletions subroutines/src/pcs/multilinear_kzg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
pub(crate) mod batching;
pub(crate) mod srs;
pub(crate) mod util;

use crate::{
pcs::{prelude::Commitment, PCSError, PolynomialCommitmentScheme, StructuredReferenceString},
BatchProof,
};
use arithmetic::evaluate_opt;
use ark_ec::{
pairing::Pairing,
scalar_mul::{fixed_base::FixedBase, variable_base::VariableBaseMSM},
AffineRepr, CurveGroup,
pairing::Pairing, scalar_mul::variable_base::VariableBaseMSM, AffineRepr, CurveGroup, ScalarMul,
};
use ark_ff::PrimeField;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
Expand All @@ -35,6 +32,8 @@ use transcript::IOPTranscript;
use self::batching::{batch_verify_internal, multi_open_internal};

/// KZG Polynomial Commitment Scheme on multilinear polynomials.

#[derive(CanonicalSerialize, CanonicalDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct MultilinearKzgPCS<E: Pairing> {
#[doc(hidden)]
phantom: PhantomData<E>,
Expand Down Expand Up @@ -288,13 +287,7 @@ fn verify_internal<E: Pairing>(

let prepare_inputs_timer = start_timer!(|| "prepare pairing inputs");

let scalar_size = E::ScalarField::MODULUS_BIT_SIZE as usize;
let window_size = FixedBase::get_mul_window_size(num_var);

let h_table =
FixedBase::get_window_table(scalar_size, window_size, verifier_param.h.into_group());
let h_mul: Vec<E::G2> = FixedBase::msm(scalar_size, window_size, &h_table, point);

let h_mul: Vec<E::G2Affine> = verifier_param.h.into_group().batch_mul(point);
let ignored = verifier_param.num_vars - num_var;
let h_vec: Vec<_> = (0..num_var)
.map(|i| verifier_param.h_mask[ignored + i].into_group() - h_mul[i])
Expand Down
20 changes: 4 additions & 16 deletions subroutines/src/pcs/multilinear_kzg/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::pcs::{
prelude::PCSError,
StructuredReferenceString,
};
use ark_ec::{pairing::Pairing, scalar_mul::fixed_base::FixedBase, AffineRepr, CurveGroup};
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup, ScalarMul};
use ark_ff::{Field, PrimeField, Zero};
use ark_poly::DenseMultilinearExtension;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
Expand Down Expand Up @@ -169,16 +169,7 @@ impl<E: Pairing> StructuredReferenceString<E> for MultilinearUniversalParams<E>
pp_powers.extend(pp_k_powers);
total_scalars += 1 << (num_vars - i);
}
let window_size = FixedBase::get_mul_window_size(total_scalars);
let g_table = FixedBase::get_window_table(scalar_bits, window_size, g);

let pp_g = E::G1::normalize_batch(&FixedBase::msm(
scalar_bits,
window_size,
&g_table,
&pp_powers,
));

let pp_g = g.batch_mul(&pp_powers);
let mut start = 0;
for i in 0..num_vars {
let size = 1 << (num_vars - i);
Expand Down Expand Up @@ -206,11 +197,8 @@ impl<E: Pairing> StructuredReferenceString<E> for MultilinearUniversalParams<E>
end_timer!(pp_generation_timer);

let vp_generation_timer = start_timer!(|| "VP generation");
let h_mask = {
let window_size = FixedBase::get_mul_window_size(num_vars);
let h_table = FixedBase::get_window_table(scalar_bits, window_size, h);
E::G2::normalize_batch(&FixedBase::msm(scalar_bits, window_size, &h_table, &t))
};

let h_mask = { h.batch_mul(&t) };
end_timer!(vp_generation_timer);
end_timer!(total_timer);
Ok(Self {
Expand Down
13 changes: 3 additions & 10 deletions subroutines/src/pcs/univariate_kzg/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! Implementing Structured Reference Strings for univariate polynomial KZG

use crate::pcs::{PCSError, StructuredReferenceString};
use ark_ec::{pairing::Pairing, scalar_mul::fixed_base::FixedBase, AffineRepr, CurveGroup};
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup, ScalarMul};
use ark_ff::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{end_timer, rand::Rng, start_timer, vec, vec::Vec, One, UniformRand};
Expand Down Expand Up @@ -118,17 +118,10 @@ impl<E: Pairing> StructuredReferenceString<E> for UnivariateUniversalParams<E> {
cur *= &beta;
}

let window_size = FixedBase::get_mul_window_size(max_degree + 1);
// let window_size = FixedBase::get_mul_window_size(max_degree + 1);

let scalar_bits = E::ScalarField::MODULUS_BIT_SIZE as usize;
let g_time = start_timer!(|| "Generating powers of G");
// TODO: parallelization
let g_table = FixedBase::get_window_table(scalar_bits, window_size, g);
let powers_of_g =
FixedBase::msm::<E::G1>(scalar_bits, window_size, &g_table, &powers_of_beta);
end_timer!(g_time);

let powers_of_g = E::G1::normalize_batch(&powers_of_g);
let powers_of_g = g.batch_mul(&powers_of_beta);

let h = h.into_affine();
let beta_h = h.mul(beta).into_affine();
Expand Down
3 changes: 2 additions & 1 deletion subroutines/src/poly_iop/perm_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
};
use ark_ec::pairing::Pairing;
use ark_poly::DenseMultilinearExtension;
use ark_serialize::CanonicalSerialize;
use ark_std::{end_timer, start_timer};
use std::sync::Arc;
use transcript::IOPTranscript;
Expand Down Expand Up @@ -52,7 +53,7 @@ where
PCS: PolynomialCommitmentScheme<E>,
{
type PermutationCheckSubClaim;
type PermutationProof;
type PermutationProof: CanonicalSerialize;

/// Initialize the system with a transcript
///
Expand Down
Loading