Skip to content

Commit 4d78d53

Browse files
Update dependencies of algebra, std and curves repos (#90)
* Use the latest algebra and std repo * address the stdrng issue Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
1 parent ac83f94 commit 4d78d53

File tree

8 files changed

+117
-116
lines changed

8 files changed

+117
-116
lines changed

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ark-ed-on-bls12-381 = { version = "^0.3.0", default-features = false }
4242
ark-bls12-381 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
4343
ark-bls12-377 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
4444
blake2 = { version = "0.9", default-features = false }
45+
rand_chacha = { version = "0.3.0", default-features = false }
4546

4647
[profile.release]
4748
opt-level = 3
@@ -55,6 +56,16 @@ debug-assertions = true
5556
incremental = true
5657
debug = true
5758

59+
# To be removed in the new release.
60+
[patch.crates-io]
61+
ark-std = { git = "https://github.com/arkworks-rs/std" }
62+
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
63+
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
64+
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
65+
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves" }
66+
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves" }
67+
ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/curves" }
68+
5869
[features]
5970
default = [ "std", "parallel" ]
6071
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"]

src/ipa_pc/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{BatchLCProof, Error, Evaluations, QuerySet, UVPolynomial};
33
use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination};
44
use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment};
55

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

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

7070
if randomizer.is_some() {
7171
assert!(hiding_generator.is_some());
@@ -1044,23 +1044,31 @@ mod tests {
10441044
use ark_ff::PrimeField;
10451045
use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial};
10461046
use ark_sponge::poseidon::PoseidonSponge;
1047-
use ark_std::rand::rngs::StdRng;
10481047
use blake2::Blake2s;
1048+
use rand_chacha::ChaCha20Rng;
10491049

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

1055-
fn rand_poly<F: PrimeField>(degree: usize, _: Option<usize>, rng: &mut StdRng) -> DensePoly<F> {
1055+
fn rand_poly<F: PrimeField>(
1056+
degree: usize,
1057+
_: Option<usize>,
1058+
rng: &mut ChaCha20Rng,
1059+
) -> DensePoly<F> {
10561060
DensePoly::rand(degree, rng)
10571061
}
10581062

1059-
fn constant_poly<F: PrimeField>(_: usize, _: Option<usize>, rng: &mut StdRng) -> DensePoly<F> {
1063+
fn constant_poly<F: PrimeField>(
1064+
_: usize,
1065+
_: Option<usize>,
1066+
rng: &mut ChaCha20Rng,
1067+
) -> DensePoly<F> {
10601068
DensePoly::from_coefficients_slice(&[F::rand(rng)])
10611069
}
10621070

1063-
fn rand_point<F: PrimeField>(_: Option<usize>, rng: &mut StdRng) -> F {
1071+
fn rand_point<F: PrimeField>(_: Option<usize>, rng: &mut ChaCha20Rng) -> F {
10641072
F::rand(rng)
10651073
}
10661074

src/kzg10/mod.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! This construction achieves extractability in the algebraic group model (AGM).
77
88
use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec};
9-
use ark_ec::msm::{FixedBaseMSM, VariableBaseMSM};
9+
use ark_ec::msm::{FixedBase, VariableBase};
1010
use ark_ec::{group::Group, AffineCurve, PairingEngine, ProjectiveCurve};
1111
use ark_ff::{One, PrimeField, UniformRand, Zero};
1212
use ark_poly::UVPolynomial;
@@ -58,21 +58,17 @@ where
5858
cur *= &beta;
5959
}
6060

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

6363
let scalar_bits = E::Fr::size_in_bits();
6464
let g_time = start_timer!(|| "Generating powers of G");
65-
let g_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, g);
66-
let powers_of_g = FixedBaseMSM::multi_scalar_mul::<E::G1Projective>(
67-
scalar_bits,
68-
window_size,
69-
&g_table,
70-
&powers_of_beta,
71-
);
65+
let g_table = FixedBase::get_window_table(scalar_bits, window_size, g);
66+
let powers_of_g =
67+
FixedBase::msm::<E::G1Projective>(scalar_bits, window_size, &g_table, &powers_of_beta);
7268
end_timer!(g_time);
7369
let gamma_g_time = start_timer!(|| "Generating powers of gamma * G");
74-
let gamma_g_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, gamma_g);
75-
let mut powers_of_gamma_g = FixedBaseMSM::multi_scalar_mul::<E::G1Projective>(
70+
let gamma_g_table = FixedBase::get_window_table(scalar_bits, window_size, gamma_g);
71+
let mut powers_of_gamma_g = FixedBase::msm::<E::G1Projective>(
7672
scalar_bits,
7773
window_size,
7874
&gamma_g_table,
@@ -99,8 +95,8 @@ where
9995
cur /= &beta;
10096
}
10197

102-
let neg_h_table = FixedBaseMSM::get_window_table(scalar_bits, window_size, h);
103-
let neg_powers_of_h = FixedBaseMSM::multi_scalar_mul::<E::G2Projective>(
98+
let neg_h_table = FixedBase::get_window_table(scalar_bits, window_size, h);
99+
let neg_powers_of_h = FixedBase::msm::<E::G2Projective>(
104100
scalar_bits,
105101
window_size,
106102
&neg_h_table,
@@ -156,10 +152,8 @@ where
156152
skip_leading_zeros_and_convert_to_bigints(polynomial);
157153

158154
let msm_time = start_timer!(|| "MSM to compute commitment to plaintext poly");
159-
let mut commitment = VariableBaseMSM::multi_scalar_mul(
160-
&powers.powers_of_g[num_leading_zeros..],
161-
&plain_coeffs,
162-
);
155+
let mut commitment =
156+
VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &plain_coeffs);
163157
end_timer!(msm_time);
164158

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

188181
commitment.add_assign_mixed(&random_commitment);
@@ -233,10 +226,7 @@ where
233226
skip_leading_zeros_and_convert_to_bigints(witness_polynomial);
234227

235228
let witness_comm_time = start_timer!(|| "Computing commitment to witness polynomial");
236-
let mut w = VariableBaseMSM::multi_scalar_mul(
237-
&powers.powers_of_g[num_leading_zeros..],
238-
&witness_coeffs,
239-
);
229+
let mut w = VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &witness_coeffs);
240230
end_timer!(witness_comm_time);
241231

242232
let random_v = if let Some(hiding_witness_polynomial) = hiding_witness_polynomial {
@@ -248,10 +238,7 @@ where
248238
let random_witness_coeffs = convert_to_bigints(&hiding_witness_polynomial.coeffs());
249239
let witness_comm_time =
250240
start_timer!(|| "Computing commitment to random witness polynomial");
251-
w += &VariableBaseMSM::multi_scalar_mul(
252-
&powers.powers_of_gamma_g,
253-
&random_witness_coeffs,
254-
);
241+
w += &VariableBase::msm(&powers.powers_of_gamma_g, &random_witness_coeffs);
255242
end_timer!(witness_comm_time);
256243
Some(blinding_evaluation)
257244
} else {

src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ pub mod tests {
530530
use ark_sponge::poseidon::{PoseidonParameters, PoseidonSponge};
531531
use ark_std::rand::{
532532
distributions::{Distribution, Uniform},
533-
rngs::StdRng,
534-
Rng,
533+
Rng, SeedableRng,
535534
};
536535
use ark_std::test_rng;
536+
use rand_chacha::ChaCha20Rng;
537537

538538
struct TestInfo<F: PrimeField, P: Polynomial<F>, S: CryptographicSponge> {
539539
num_iters: usize,
@@ -544,14 +544,14 @@ pub mod tests {
544544
enforce_degree_bounds: bool,
545545
max_num_queries: usize,
546546
num_equations: Option<usize>,
547-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
548-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
547+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
548+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
549549
sponge: fn() -> S,
550550
}
551551

552552
pub fn bad_degree_bound_test<F, P, PC, S>(
553-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
554-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
553+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
554+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
555555
sponge: fn() -> S,
556556
) -> Result<(), PC::Error>
557557
where
@@ -566,7 +566,7 @@ pub mod tests {
566566
];
567567

568568
for challenge_gen in challenge_generators {
569-
let rng = &mut test_rng();
569+
let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap();
570570
let max_degree = 100;
571571
let pp = PC::setup(max_degree, None, rng)?;
572572
for _ in 0..10 {
@@ -674,7 +674,7 @@ pub mod tests {
674674
];
675675

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

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

980980
pub fn single_poly_test<F, P, PC, S>(
981981
num_vars: Option<usize>,
982-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
983-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
982+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
983+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
984984
sponge: fn() -> S,
985985
) -> Result<(), PC::Error>
986986
where
@@ -1006,8 +1006,8 @@ pub mod tests {
10061006
}
10071007

10081008
pub fn linear_poly_degree_bound_test<F, P, PC, S>(
1009-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1010-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1009+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1010+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
10111011
sponge: fn() -> S,
10121012
) -> Result<(), PC::Error>
10131013
where
@@ -1033,8 +1033,8 @@ pub mod tests {
10331033
}
10341034

10351035
pub fn single_poly_degree_bound_test<F, P, PC, S>(
1036-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1037-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1036+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1037+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
10381038
sponge: fn() -> S,
10391039
) -> Result<(), PC::Error>
10401040
where
@@ -1060,8 +1060,8 @@ pub mod tests {
10601060
}
10611061

10621062
pub fn quadratic_poly_degree_bound_multiple_queries_test<F, P, PC, S>(
1063-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1064-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1063+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1064+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
10651065
sponge: fn() -> S,
10661066
) -> Result<(), PC::Error>
10671067
where
@@ -1087,8 +1087,8 @@ pub mod tests {
10871087
}
10881088

10891089
pub fn single_poly_degree_bound_multiple_queries_test<F, P, PC, S>(
1090-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1091-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1090+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1091+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
10921092
sponge: fn() -> S,
10931093
) -> Result<(), PC::Error>
10941094
where
@@ -1114,8 +1114,8 @@ pub mod tests {
11141114
}
11151115

11161116
pub fn two_polys_degree_bound_single_query_test<F, P, PC, S>(
1117-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1118-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1117+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1118+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
11191119
sponge: fn() -> S,
11201120
) -> Result<(), PC::Error>
11211121
where
@@ -1142,8 +1142,8 @@ pub mod tests {
11421142

11431143
pub fn full_end_to_end_test<F, P, PC, S>(
11441144
num_vars: Option<usize>,
1145-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1146-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1145+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1146+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
11471147
sponge: fn() -> S,
11481148
) -> Result<(), PC::Error>
11491149
where
@@ -1170,8 +1170,8 @@ pub mod tests {
11701170

11711171
pub fn full_end_to_end_equation_test<F, P, PC, S>(
11721172
num_vars: Option<usize>,
1173-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1174-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1173+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1174+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
11751175
sponge: fn() -> S,
11761176
) -> Result<(), PC::Error>
11771177
where
@@ -1198,8 +1198,8 @@ pub mod tests {
11981198

11991199
pub fn single_equation_test<F, P, PC, S>(
12001200
num_vars: Option<usize>,
1201-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1202-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1201+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1202+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
12031203
sponge: fn() -> S,
12041204
) -> Result<(), PC::Error>
12051205
where
@@ -1226,8 +1226,8 @@ pub mod tests {
12261226

12271227
pub fn two_equation_test<F, P, PC, S>(
12281228
num_vars: Option<usize>,
1229-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1230-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1229+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1230+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
12311231
sponge: fn() -> S,
12321232
) -> Result<(), PC::Error>
12331233
where
@@ -1253,8 +1253,8 @@ pub mod tests {
12531253
}
12541254

12551255
pub fn two_equation_degree_bound_test<F, P, PC, S>(
1256-
rand_poly: fn(usize, Option<usize>, &mut StdRng) -> P,
1257-
rand_point: fn(Option<usize>, &mut StdRng) -> P::Point,
1256+
rand_poly: fn(usize, Option<usize>, &mut ChaCha20Rng) -> P,
1257+
rand_point: fn(Option<usize>, &mut ChaCha20Rng) -> P::Point,
12581258
sponge: fn() -> S,
12591259
) -> Result<(), PC::Error>
12601260
where

src/marlin/marlin_pc/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ mod tests {
542542
use ark_ff::UniformRand;
543543
use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial};
544544
use ark_sponge::poseidon::PoseidonSponge;
545-
use ark_std::rand::rngs::StdRng;
545+
use rand_chacha::ChaCha20Rng;
546546

547547
type UniPoly_381 = DensePoly<<Bls12_381 as PairingEngine>::Fr>;
548548
type UniPoly_377 = DensePoly<<Bls12_377 as PairingEngine>::Fr>;
@@ -558,20 +558,20 @@ mod tests {
558558
fn rand_poly<E: PairingEngine>(
559559
degree: usize,
560560
_: Option<usize>,
561-
rng: &mut StdRng,
561+
rng: &mut ChaCha20Rng,
562562
) -> DensePoly<E::Fr> {
563563
DensePoly::<E::Fr>::rand(degree, rng)
564564
}
565565

566566
fn constant_poly<E: PairingEngine>(
567567
_: usize,
568568
_: Option<usize>,
569-
rng: &mut StdRng,
569+
rng: &mut ChaCha20Rng,
570570
) -> DensePoly<E::Fr> {
571571
DensePoly::<E::Fr>::from_coefficients_slice(&[E::Fr::rand(rng)])
572572
}
573573

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

0 commit comments

Comments
 (0)