Skip to content

Commit

Permalink
Merge branch 'master' into hyrax-pcs
Browse files Browse the repository at this point in the history
  • Loading branch information
autquis committed Oct 25, 2024
2 parents c2ba181 + bbdb37e commit 9e310f5
Show file tree
Hide file tree
Showing 30 changed files with 362 additions and 421 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [\#82](https://github.com/arkworks-rs/poly-commit/pull/82) Add multivariate opening challenge strategy. Integrate with sponge API.

### Improvements
- [\#152](https://github.com/arkworks-rs/poly-commit/issues/152) Expose `kzg10::open_with_witness_polynomial` and `open` downstream.

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ incremental = true
debug = true

[patch.crates-io]
ark-std = { git = "https://github.com/arkworks-rs/std/" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra/" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }
ark-std = { git = "https://github.com/arkworks-rs/std/" }

ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" }
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ use rand_chacha::ChaCha20Rng;
use ark_ff::PrimeField;

type UniPoly_377 = DensePolynomial<<Bls12_377 as Pairing>::ScalarField>;
type Sponge_Bls12_377 = PoseidonSponge<<Bls12_377 as Pairing>::ScalarField>;
type PCS = MarlinKZG10<Bls12_377, UniPoly_377, Sponge_Bls12_377>;
type PCS = MarlinKZG10<Bls12_377, UniPoly_377>;

let rng = &mut test_rng();

Expand Down
34 changes: 12 additions & 22 deletions bench-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ pub use paste::paste;
/// multilinear PCS for all `num_vars` specified in `nv_list`.
/// `rand_poly` is a function that outputs a random multilinear polynomial.
/// `rand_point` is a function that outputs a random point in the domain of polynomial.
pub fn bench_pcs_method<
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
>(
pub fn bench_pcs_method<F: PrimeField, P: Polynomial<F>, PCS: PolynomialCommitment<F, P>>(
c: &mut Criterion,
nv_list: Vec<usize>,
msg: &str,
Expand Down Expand Up @@ -64,11 +60,7 @@ pub fn bench_pcs_method<
}

/// Report the time cost of a commitment
pub fn commit<
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
>(
pub fn commit<F: PrimeField, P: Polynomial<F>, PCS: PolynomialCommitment<F, P>>(
ck: &PCS::CommitterKey,
_vk: &PCS::VerifierKey,
num_vars: usize,
Expand All @@ -86,11 +78,7 @@ pub fn commit<
}

/// Report the size of a commitment
pub fn commitment_size<
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
>(
pub fn commitment_size<F: PrimeField, P: Polynomial<F>, PCS: PolynomialCommitment<F, P>>(
num_vars: usize,
rand_poly: fn(usize, &mut ChaCha20Rng) -> P,
) -> usize {
Expand Down Expand Up @@ -119,7 +107,8 @@ pub fn open<F, P, PCS>(
where
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
PCS: PolynomialCommitment<F, P>,
P::Point: UniformRand,
{
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();

Expand All @@ -135,7 +124,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -148,7 +137,7 @@ pub fn proof_size<F, P, PCS>(num_vars: usize, rand_poly: fn(usize, &mut ChaCha20
where
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
PCS: PolynomialCommitment<F, P>,

P::Point: UniformRand,
{
Expand All @@ -168,7 +157,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -190,7 +179,8 @@ pub fn verify<F, P, PCS>(
where
F: PrimeField,
P: Polynomial<F>,
PCS: PolynomialCommitment<F, P, PoseidonSponge<F>>,
PCS: PolynomialCommitment<F, P>,
P::Point: UniformRand,
{
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();

Expand All @@ -205,7 +195,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -218,7 +208,7 @@ where
&point,
[claimed_eval],
&proof,
&mut test_sponge(),
&mut test_sponge::<F>(),
None,
)
.unwrap();
Expand Down
5 changes: 1 addition & 4 deletions poly-commit/benches/ipa_times.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use ark_ec::AffineRepr;
use ark_pcs_bench_templates::*;
use ark_poly::DenseUVPolynomial;
use blake2::Blake2s256;

use ark_crypto_primitives::sponge::poseidon::PoseidonSponge;
use ark_ed_on_bls12_381::{EdwardsAffine, Fr};
use ark_ff::PrimeField;
use ark_poly::univariate::DensePolynomial as DenseUnivariatePoly;
Expand All @@ -12,11 +10,10 @@ use ark_poly_commit::ipa_pc::InnerProductArgPC;
use rand_chacha::ChaCha20Rng;

type UniPoly = DenseUnivariatePoly<Fr>;
type Sponge = PoseidonSponge<<EdwardsAffine as AffineRepr>::ScalarField>;

// IPA_PC over the JubJub curve with Blake2s as the hash function
#[allow(non_camel_case_types)]
type IPA_JubJub = InnerProductArgPC<EdwardsAffine, Blake2s256, UniPoly, Sponge>;
type IPA_JubJub = InnerProductArgPC<EdwardsAffine, Blake2s256, UniPoly>;

fn rand_poly_ipa_pc<F: PrimeField>(degree: usize, rng: &mut ChaCha20Rng) -> DenseUnivariatePoly<F> {
DenseUnivariatePoly::rand(degree, rng)
Expand Down
7 changes: 2 additions & 5 deletions poly-commit/benches/size.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use ark_ec::AffineRepr;
use ark_pcs_bench_templates::*;
use ark_poly::DenseUVPolynomial;
use blake2::Blake2s256;

use ark_crypto_primitives::sponge::poseidon::PoseidonSponge;
use ark_ed_on_bls12_381::{EdwardsAffine, Fr};
use ark_ff::PrimeField;
use ark_poly::univariate::DensePolynomial as DenseUnivariatePoly;
Expand All @@ -12,12 +10,11 @@ use ark_poly_commit::ipa_pc::InnerProductArgPC;
use rand_chacha::ChaCha20Rng;

type UniPoly = DenseUnivariatePoly<Fr>;
type Sponge = PoseidonSponge<<EdwardsAffine as AffineRepr>::ScalarField>;
type PC<E, D, P, S> = InnerProductArgPC<E, D, P, S>;
type PC<E, D, P> = InnerProductArgPC<E, D, P>;

// IPA_PC over the JubJub curve with Blake2s as the hash function
#[allow(non_camel_case_types)]
type IPA_JubJub = PC<EdwardsAffine, Blake2s256, UniPoly, Sponge>;
type IPA_JubJub = PC<EdwardsAffine, Blake2s256, UniPoly>;

fn rand_poly_ipa_pc<F: PrimeField>(degree: usize, rng: &mut ChaCha20Rng) -> DenseUnivariatePoly<F> {
DenseUnivariatePoly::rand(degree, rng)
Expand Down
18 changes: 9 additions & 9 deletions poly-commit/src/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use crate::{
data_structures::LabeledCommitment, BatchLCProof, LCTerm, LinearCombination,
PCPreparedCommitment, PCPreparedVerifierKey, PolynomialCommitment, String, Vec,
PCPreparedCommitment, PCPreparedVerifierKey, PolynomialCommitment,
};
use ark_crypto_primitives::sponge::CryptographicSponge;
use ark_ff::PrimeField;
use ark_poly::Polynomial;
use ark_r1cs_std::fields::emulated_fp::EmulatedFpVar;
use ark_r1cs_std::{fields::fp::FpVar, prelude::*};
use ark_r1cs_std::{
fields::{emulated_fp::EmulatedFpVar, fp::FpVar},
prelude::*,
};
use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError};
use ark_std::{
borrow::Borrow,
cmp::Eq,
cmp::PartialEq,
cmp::{Eq, PartialEq},
hash::{BuildHasherDefault, Hash},
marker::Sized,
};
// #[cfg(not(feature = "std"))]
// use ark_std::{string::String, vec::Vec};
use hashbrown::{HashMap, HashSet};

#[cfg(all(
Expand Down Expand Up @@ -118,9 +119,8 @@ pub struct PCCheckRandomDataVar<TargetField: PrimeField, BaseField: PrimeField>
pub trait PCCheckVar<
PCF: PrimeField,
P: Polynomial<PCF>,
PC: PolynomialCommitment<PCF, P, S>,
PC: PolynomialCommitment<PCF, P>,
ConstraintF: PrimeField,
S: CryptographicSponge,
>: Clone
{
/// The prepared verifier key for the scheme; used to check an evaluation proof.
Expand Down
6 changes: 4 additions & 2 deletions poly-commit/src/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{Polynomial, String, Vec};
use crate::Polynomial;
use ark_ff::{Field, PrimeField, ToConstraintField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::RngCore;
use ark_std::{
borrow::Borrow,
marker::PhantomData,
ops::{AddAssign, MulAssign, SubAssign},
rand::RngCore,
};
#[cfg(not(feature = "std"))]
use ark_std::{string::String, vec::Vec};

/// Labels a `LabeledPolynomial` or a `LabeledCommitment`.
pub type PolynomialLabel = String;
Expand Down
3 changes: 2 additions & 1 deletion poly-commit/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::String;
#[cfg(not(feature = "std"))]
use ark_std::string::String;

/// The error type for `PolynomialCommitment`.
#[derive(Debug)]
Expand Down
14 changes: 5 additions & 9 deletions poly-commit/src/hyrax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,14 @@ pub struct HyraxPC<
G: AffineRepr,
// A polynomial type representing multilinear polynomials
P: MultilinearExtension<G::ScalarField>,
// The sponge used in the protocol as random oracle
S: CryptographicSponge,
> {
_phantom: PhantomData<(G, P, S)>,
_phantom: PhantomData<(G, P)>,
}

impl<G, P, S> HyraxPC<G, P, S>
impl<G, P> HyraxPC<G, P>
where
G: AffineRepr,
P: MultilinearExtension<G::ScalarField>,
S: CryptographicSponge,
{
/// Pedersen commitment to a vector of scalars as described in appendix A.1
/// of the reference article.
Expand All @@ -97,12 +94,11 @@ where
}
}

impl<G, P, S> PolynomialCommitment<G::ScalarField, P, S> for HyraxPC<G, P, S>
impl<G, P> PolynomialCommitment<G::ScalarField, P> for HyraxPC<G, P>
where
G: AffineRepr,
G::ScalarField: Absorb,
P: MultilinearExtension<G::ScalarField>,
S: CryptographicSponge,
{
type UniversalParams = HyraxUniversalParams<G>;
type CommitterKey = HyraxCommitterKey<G>;
Expand Down Expand Up @@ -280,7 +276,7 @@ where
labeled_polynomials: impl IntoIterator<Item = &'a LabeledPolynomial<G::ScalarField, P>>,
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
point: &'a P::Point,
sponge: &mut S,
sponge: &mut impl CryptographicSponge,
states: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<Self::Proof, Self::Error>
Expand Down Expand Up @@ -426,7 +422,7 @@ where
point: &'a P::Point,
_values: impl IntoIterator<Item = G::ScalarField>,
proof: &Self::Proof,
sponge: &mut S,
sponge: &mut impl CryptographicSponge,
_rng: Option<&mut dyn RngCore>,
) -> Result<bool, Self::Error>
where
Expand Down
5 changes: 1 addition & 4 deletions poly-commit/src/ipa_pc/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::*;
use crate::{PCCommitterKey, PCVerifierKey, Vec};
use ark_ec::AffineRepr;
use ark_ff::{Field, UniformRand, Zero};
use ark_ff::{UniformRand, Zero};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::RngCore;
use ark_std::vec;

/// `UniversalParams` are the universal parameters for the inner product arg scheme.
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
Expand Down
Loading

0 comments on commit 9e310f5

Please sign in to comment.