Skip to content
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
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ark-ed-on-bls12-381 = { version = "^0.3.0", default-features = false }
ark-bls12-381 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
ark-bls12-377 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
blake2 = { version = "0.9", default-features = false }
rand_chacha = { version = "0.3.0", default-features = false }

[profile.release]
opt-level = 3
Expand All @@ -55,6 +56,16 @@ debug-assertions = true
incremental = true
debug = true

# To be removed in the new release.
[patch.crates-io]
ark-std = { git = "https://github.com/arkworks-rs/std" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves" }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves" }
ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/curves" }

[features]
default = [ "std", "parallel" ]
std = [ "ark-ff/std", "ark-ec/std", "ark-nonnative-field/std", "ark-poly/std", "ark-std/std", "ark-relations/std", "ark-serialize/std", "ark-sponge/std"]
Expand Down
20 changes: 14 additions & 6 deletions src/ipa_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{BatchLCProof, Error, Evaluations, QuerySet, UVPolynomial};
use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination};
use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment};

use ark_ec::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve};
use ark_ec::{msm::VariableBase, AffineCurve, ProjectiveCurve};
use ark_ff::{to_bytes, Field, One, PrimeField, UniformRand, Zero};
use ark_std::rand::RngCore;
use ark_std::{convert::TryInto, format, marker::PhantomData, vec};
Expand Down Expand Up @@ -65,7 +65,7 @@ where
.map(|s| s.into_repr())
.collect::<Vec<_>>();

let mut comm = VariableBaseMSM::multi_scalar_mul(comm_key, &scalars_bigint);
let mut comm = VariableBase::msm(comm_key, &scalars_bigint);

if randomizer.is_some() {
assert!(hiding_generator.is_some());
Expand Down Expand Up @@ -1044,23 +1044,31 @@ mod tests {
use ark_ff::PrimeField;
use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial};
use ark_sponge::poseidon::PoseidonSponge;
use ark_std::rand::rngs::StdRng;
use blake2::Blake2s;
use rand_chacha::ChaCha20Rng;

type UniPoly = DensePoly<Fr>;
type Sponge = PoseidonSponge<<EdwardsAffine as AffineCurve>::ScalarField>;
type PC<E, D, P, S> = InnerProductArgPC<E, D, P, S>;
type PC_JJB2S = PC<EdwardsAffine, Blake2s, UniPoly, Sponge>;

fn rand_poly<F: PrimeField>(degree: usize, _: Option<usize>, rng: &mut StdRng) -> DensePoly<F> {
fn rand_poly<F: PrimeField>(
degree: usize,
_: Option<usize>,
rng: &mut ChaCha20Rng,
) -> DensePoly<F> {
DensePoly::rand(degree, rng)
}

fn constant_poly<F: PrimeField>(_: usize, _: Option<usize>, rng: &mut StdRng) -> DensePoly<F> {
fn constant_poly<F: PrimeField>(
_: usize,
_: Option<usize>,
rng: &mut ChaCha20Rng,
) -> DensePoly<F> {
DensePoly::from_coefficients_slice(&[F::rand(rng)])
}

fn rand_point<F: PrimeField>(_: Option<usize>, rng: &mut StdRng) -> F {
fn rand_point<F: PrimeField>(_: Option<usize>, rng: &mut ChaCha20Rng) -> F {
F::rand(rng)
}

Expand Down
41 changes: 14 additions & 27 deletions src/kzg10/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! This construction achieves extractability in the algebraic group model (AGM).

use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec};
use ark_ec::msm::{FixedBaseMSM, VariableBaseMSM};
use ark_ec::msm::{FixedBase, VariableBase};
use ark_ec::{group::Group, AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{One, PrimeField, UniformRand, Zero};
use ark_poly::UVPolynomial;
Expand Down Expand Up @@ -58,21 +58,17 @@ where
cur *= &beta;
}

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

let scalar_bits = E::Fr::size_in_bits();
let g_time = start_timer!(|| "Generating powers of G");
let g_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, g);
let powers_of_g = FixedBaseMSM::multi_scalar_mul::<E::G1Projective>(
scalar_bits,
window_size,
&g_table,
&powers_of_beta,
);
let g_table = FixedBase::get_window_table(scalar_bits, window_size, g);
let powers_of_g =
FixedBase::msm::<E::G1Projective>(scalar_bits, window_size, &g_table, &powers_of_beta);
end_timer!(g_time);
let gamma_g_time = start_timer!(|| "Generating powers of gamma * G");
let gamma_g_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, gamma_g);
let mut powers_of_gamma_g = FixedBaseMSM::multi_scalar_mul::<E::G1Projective>(
let gamma_g_table = FixedBase::get_window_table(scalar_bits, window_size, gamma_g);
let mut powers_of_gamma_g = FixedBase::msm::<E::G1Projective>(
scalar_bits,
window_size,
&gamma_g_table,
Expand All @@ -99,8 +95,8 @@ where
cur /= &beta;
}

let neg_h_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, h);
let neg_powers_of_h = FixedBaseMSM::multi_scalar_mul::<E::G2Projective>(
let neg_h_table = FixedBase::get_window_table(scalar_bits, window_size, h);
let neg_powers_of_h = FixedBase::msm::<E::G2Projective>(
scalar_bits,
window_size,
&neg_h_table,
Expand Down Expand Up @@ -156,10 +152,8 @@ where
skip_leading_zeros_and_convert_to_bigints(polynomial);

let msm_time = start_timer!(|| "MSM to compute commitment to plaintext poly");
let mut commitment = VariableBaseMSM::multi_scalar_mul(
&powers.powers_of_g[num_leading_zeros..],
&plain_coeffs,
);
let mut commitment =
VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &plain_coeffs);
end_timer!(msm_time);

let mut randomness = Randomness::<E::Fr, P>::empty();
Expand All @@ -181,8 +175,7 @@ where
let random_ints = convert_to_bigints(&randomness.blinding_polynomial.coeffs());
let msm_time = start_timer!(|| "MSM to compute commitment to random poly");
let random_commitment =
VariableBaseMSM::multi_scalar_mul(&powers.powers_of_gamma_g, random_ints.as_slice())
.into_affine();
VariableBase::msm(&powers.powers_of_gamma_g, random_ints.as_slice()).into_affine();
end_timer!(msm_time);

commitment.add_assign_mixed(&random_commitment);
Expand Down Expand Up @@ -233,10 +226,7 @@ where
skip_leading_zeros_and_convert_to_bigints(witness_polynomial);

let witness_comm_time = start_timer!(|| "Computing commitment to witness polynomial");
let mut w = VariableBaseMSM::multi_scalar_mul(
&powers.powers_of_g[num_leading_zeros..],
&witness_coeffs,
);
let mut w = VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &witness_coeffs);
end_timer!(witness_comm_time);

let random_v = if let Some(hiding_witness_polynomial) = hiding_witness_polynomial {
Expand All @@ -248,10 +238,7 @@ where
let random_witness_coeffs = convert_to_bigints(&hiding_witness_polynomial.coeffs());
let witness_comm_time =
start_timer!(|| "Computing commitment to random witness polynomial");
w += &VariableBaseMSM::multi_scalar_mul(
&powers.powers_of_gamma_g,
&random_witness_coeffs,
);
w += &VariableBase::msm(&powers.powers_of_gamma_g, &random_witness_coeffs);
end_timer!(witness_comm_time);
Some(blinding_evaluation)
} else {
Expand Down
62 changes: 31 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ pub mod tests {
use ark_sponge::poseidon::{PoseidonParameters, PoseidonSponge};
use ark_std::rand::{
distributions::{Distribution, Uniform},
rngs::StdRng,
Rng,
Rng, SeedableRng,
};
use ark_std::test_rng;
use rand_chacha::ChaCha20Rng;

struct TestInfo<F: PrimeField, P: Polynomial<F>, S: CryptographicSponge> {
num_iters: usize,
Expand All @@ -544,14 +544,14 @@ pub mod tests {
enforce_degree_bounds: bool,
max_num_queries: usize,
num_equations: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
}

pub fn bad_degree_bound_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -566,7 +566,7 @@ pub mod tests {
];

for challenge_gen in challenge_generators {
let rng = &mut test_rng();
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();
let max_degree = 100;
let pp = PC::setup(max_degree, None, rng)?;
for _ in 0..10 {
Expand Down Expand Up @@ -674,7 +674,7 @@ pub mod tests {
];

for challenge_gen in challenge_gens {
let rng = &mut test_rng();
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();
// If testing multivariate polynomials, make the max degree lower
let max_degree = match num_vars {
Some(_) => max_degree.unwrap_or(Uniform::from(2..=10).sample(rng)),
Expand Down Expand Up @@ -819,7 +819,7 @@ pub mod tests {
];

for challenge_gen in challenge_gens {
let rng = &mut test_rng();
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();
// If testing multivariate polynomials, make the max degree lower
let max_degree = match num_vars {
Some(_) => max_degree.unwrap_or(Uniform::from(2..=10).sample(rng)),
Expand Down Expand Up @@ -979,8 +979,8 @@ pub mod tests {

pub fn single_poly_test<F, P, PC, S>(
num_vars: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1006,8 +1006,8 @@ pub mod tests {
}

pub fn linear_poly_degree_bound_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1033,8 +1033,8 @@ pub mod tests {
}

pub fn single_poly_degree_bound_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1060,8 +1060,8 @@ pub mod tests {
}

pub fn quadratic_poly_degree_bound_multiple_queries_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1087,8 +1087,8 @@ pub mod tests {
}

pub fn single_poly_degree_bound_multiple_queries_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1114,8 +1114,8 @@ pub mod tests {
}

pub fn two_polys_degree_bound_single_query_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1142,8 +1142,8 @@ pub mod tests {

pub fn full_end_to_end_test<F, P, PC, S>(
num_vars: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1170,8 +1170,8 @@ pub mod tests {

pub fn full_end_to_end_equation_test<F, P, PC, S>(
num_vars: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1198,8 +1198,8 @@ pub mod tests {

pub fn single_equation_test<F, P, PC, S>(
num_vars: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1226,8 +1226,8 @@ pub mod tests {

pub fn two_equation_test<F, P, PC, S>(
num_vars: Option<usize>,
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand All @@ -1253,8 +1253,8 @@ pub mod tests {
}

pub fn two_equation_degree_bound_test<F, P, PC, S>(
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
sponge: fn() -> S,
) -> Result<(), PC::Error>
where
Expand Down
8 changes: 4 additions & 4 deletions src/marlin/marlin_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ mod tests {
use ark_ff::UniformRand;
use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial};
use ark_sponge::poseidon::PoseidonSponge;
use ark_std::rand::rngs::StdRng;
use rand_chacha::ChaCha20Rng;

type UniPoly_381 = DensePoly<<Bls12_381 as PairingEngine>::Fr>;
type UniPoly_377 = DensePoly<<Bls12_377 as PairingEngine>::Fr>;
Expand All @@ -558,20 +558,20 @@ mod tests {
fn rand_poly<E: PairingEngine>(
degree: usize,
_: Option<usize>,
rng: &mut StdRng,
rng: &mut ChaCha20Rng,
) -> DensePoly<E::Fr> {
DensePoly::<E::Fr>::rand(degree, rng)
}

fn constant_poly<E: PairingEngine>(
_: usize,
_: Option<usize>,
rng: &mut StdRng,
rng: &mut ChaCha20Rng,
) -> DensePoly<E::Fr> {
DensePoly::<E::Fr>::from_coefficients_slice(&[E::Fr::rand(rng)])
}

fn rand_point<E: PairingEngine>(_: Option<usize>, rng: &mut StdRng) -> E::Fr {
fn rand_point<E: PairingEngine>(_: Option<usize>, rng: &mut ChaCha20Rng) -> E::Fr {
E::Fr::rand(rng)
}

Expand Down
Loading