Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify PolynomialCommitment trait: remove the generic on S: CryptographicSponge #145

Merged
merged 18 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ 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-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives" }
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives/" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" }

ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves/" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/" }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra/" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra/" }
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
32 changes: 10 additions & 22 deletions bench-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ pub use criterion::*;
pub use paste::paste;

/// Measure the time cost of {commit/open/verify} across a range of num_vars
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,
range: Vec<usize>,
msg: &str,
Expand Down Expand Up @@ -53,11 +49,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 @@ -74,11 +66,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 @@ -106,7 +94,7 @@ 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 @@ -123,7 +111,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -136,7 +124,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 @@ -156,7 +144,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -177,7 +165,7 @@ 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 @@ -193,7 +181,7 @@ where
[&labeled_poly],
&coms,
&point,
&mut test_sponge(),
&mut test_sponge::<F>(),
&states,
Some(rng),
)
Expand All @@ -206,7 +194,7 @@ where
&point,
[claimed_eval],
&proof,
&mut test_sponge(),
&mut test_sponge::<F>(),
None,
)
.unwrap();
Expand Down
7 changes: 4 additions & 3 deletions poly-commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ ark-poly = {version = "^0.4.0", default-features = false }
ark-crypto-primitives = {version = "^0.4.0", default-features = false, features = ["sponge", "merkle_tree"] }
ark-std = { version = "^0.4.0", default-features = false }

derivative = { version = "2", features = [ "use_core" ] }
digest = "0.10"

ark-relations = { version = "^0.4.0", default-features = false, optional = true }
ark-r1cs-std = { version = "^0.4.0", default-features = false, optional = true }
hashbrown = { version = "0.13", default-features = false, optional = true }

digest = "0.10"
derivative = { version = "2", features = [ "use_core" ] }
hashbrown = { version = "0.13", default-features = false, optional = true}
rayon = { version = "1", optional = true }

[[bench]]
Expand Down
5 changes: 1 addition & 4 deletions poly-commit/benches/pcs.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
16 changes: 9 additions & 7 deletions poly-commit/src/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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, hash::Hash, marker::Sized};
use ark_std::{borrow::Borrow, cmp::Eq, cmp::PartialEq, hash::Hash};
#[cfg(not(feature = "std"))]
use ark_std::{string::String, vec::Vec};
use hashbrown::{HashMap, HashSet};

/// Define the minimal interface of prepared allocated structures.
Expand Down Expand Up @@ -94,9 +97,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
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
Loading