Migrate bellman to rand 0.5
This commit is contained in:
parent
a7e22b3550
commit
4606a0cefb
|
@ -61,7 +61,8 @@ dependencies = [
|
|||
"group 0.1.0",
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2",
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -9,7 +9,7 @@ repository = "https://github.com/ebfull/bellman"
|
|||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.4"
|
||||
rand_core = "0.3"
|
||||
bit-vec = "0.4.4"
|
||||
ff = { path = "../ff" }
|
||||
futures = "0.1"
|
||||
|
@ -20,6 +20,9 @@ crossbeam = { version = "0.3", optional = true }
|
|||
pairing = { path = "../pairing", optional = true }
|
||||
byteorder = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.5"
|
||||
|
||||
[features]
|
||||
groth16 = ["pairing"]
|
||||
multicore = ["futures-cpupool", "crossbeam", "num_cpus"]
|
||||
|
|
|
@ -375,16 +375,16 @@ fn parallel_fft<E: ScalarEngine, T: Group<E>>(
|
|||
#[test]
|
||||
fn polynomial_arith() {
|
||||
use pairing::bls12_381::Bls12;
|
||||
use rand::{self, Rand};
|
||||
use rand_core::RngCore;
|
||||
|
||||
fn test_mul<E: ScalarEngine, R: rand::Rng>(rng: &mut R)
|
||||
fn test_mul<E: ScalarEngine, R: RngCore>(rng: &mut R)
|
||||
{
|
||||
let worker = Worker::new();
|
||||
|
||||
for coeffs_a in 0..70 {
|
||||
for coeffs_b in 0..70 {
|
||||
let mut a: Vec<_> = (0..coeffs_a).map(|_| Scalar::<E>(E::Fr::rand(rng))).collect();
|
||||
let mut b: Vec<_> = (0..coeffs_b).map(|_| Scalar::<E>(E::Fr::rand(rng))).collect();
|
||||
let mut a: Vec<_> = (0..coeffs_a).map(|_| Scalar::<E>(E::Fr::random(rng))).collect();
|
||||
let mut b: Vec<_> = (0..coeffs_b).map(|_| Scalar::<E>(E::Fr::random(rng))).collect();
|
||||
|
||||
// naive evaluation
|
||||
let mut naive = vec![Scalar(E::Fr::zero()); coeffs_a + coeffs_b];
|
||||
|
@ -423,9 +423,9 @@ fn polynomial_arith() {
|
|||
#[test]
|
||||
fn fft_composition() {
|
||||
use pairing::bls12_381::Bls12;
|
||||
use rand;
|
||||
use rand_core::RngCore;
|
||||
|
||||
fn test_comp<E: ScalarEngine, R: rand::Rng>(rng: &mut R)
|
||||
fn test_comp<E: ScalarEngine, R: RngCore>(rng: &mut R)
|
||||
{
|
||||
let worker = Worker::new();
|
||||
|
||||
|
@ -434,7 +434,7 @@ fn fft_composition() {
|
|||
|
||||
let mut v = vec![];
|
||||
for _ in 0..coeffs {
|
||||
v.push(Scalar::<E>(rng.gen()));
|
||||
v.push(Scalar::<E>(E::Fr::random(rng)));
|
||||
}
|
||||
|
||||
let mut domain = EvaluationDomain::from_coeffs(v.clone()).unwrap();
|
||||
|
@ -462,10 +462,10 @@ fn fft_composition() {
|
|||
#[test]
|
||||
fn parallel_fft_consistency() {
|
||||
use pairing::bls12_381::Bls12;
|
||||
use rand::{self, Rand};
|
||||
use rand_core::RngCore;
|
||||
use std::cmp::min;
|
||||
|
||||
fn test_consistency<E: ScalarEngine, R: rand::Rng>(rng: &mut R)
|
||||
fn test_consistency<E: ScalarEngine, R: RngCore>(rng: &mut R)
|
||||
{
|
||||
let worker = Worker::new();
|
||||
|
||||
|
@ -473,7 +473,7 @@ fn parallel_fft_consistency() {
|
|||
for log_d in 0..10 {
|
||||
let d = 1 << log_d;
|
||||
|
||||
let v1 = (0..d).map(|_| Scalar::<E>(E::Fr::rand(rng))).collect::<Vec<_>>();
|
||||
let v1 = (0..d).map(|_| Scalar::<E>(E::Fr::random(rng))).collect::<Vec<_>>();
|
||||
let mut v1 = EvaluationDomain::from_coeffs(v1).unwrap();
|
||||
let mut v2 = EvaluationDomain::from_coeffs(v1.coeffs.clone()).unwrap();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rand::Rng;
|
||||
use rand_core::RngCore;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -35,15 +35,15 @@ pub fn generate_random_parameters<E, C, R>(
|
|||
circuit: C,
|
||||
rng: &mut R
|
||||
) -> Result<Parameters<E>, SynthesisError>
|
||||
where E: Engine, C: Circuit<E>, R: Rng
|
||||
where E: Engine, C: Circuit<E>, R: RngCore
|
||||
{
|
||||
let g1 = rng.gen();
|
||||
let g2 = rng.gen();
|
||||
let alpha = rng.gen();
|
||||
let beta = rng.gen();
|
||||
let gamma = rng.gen();
|
||||
let delta = rng.gen();
|
||||
let tau = rng.gen();
|
||||
let g1 = E::G1::random(rng);
|
||||
let g2 = E::G2::random(rng);
|
||||
let alpha = E::Fr::random(rng);
|
||||
let beta = E::Fr::random(rng);
|
||||
let gamma = E::Fr::random(rng);
|
||||
let delta = E::Fr::random(rng);
|
||||
let tau = E::Fr::random(rng);
|
||||
|
||||
generate_parameters::<E, C>(
|
||||
circuit,
|
||||
|
|
|
@ -487,7 +487,7 @@ mod test_with_bls12_381 {
|
|||
use {Circuit, SynthesisError, ConstraintSystem};
|
||||
|
||||
use ff::Field;
|
||||
use rand::{Rand, thread_rng};
|
||||
use rand::{thread_rng};
|
||||
use pairing::bls12_381::{Bls12, Fr};
|
||||
|
||||
#[test]
|
||||
|
@ -547,8 +547,8 @@ mod test_with_bls12_381 {
|
|||
let pvk = prepare_verifying_key::<Bls12>(¶ms.vk);
|
||||
|
||||
for _ in 0..100 {
|
||||
let a = Fr::rand(rng);
|
||||
let b = Fr::rand(rng);
|
||||
let a = Fr::random(rng);
|
||||
let b = Fr::random(rng);
|
||||
let mut c = a;
|
||||
c.mul_assign(&b);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rand::Rng;
|
||||
use rand_core::RngCore;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -189,10 +189,10 @@ pub fn create_random_proof<E, C, R, P: ParameterSource<E>>(
|
|||
params: P,
|
||||
rng: &mut R
|
||||
) -> Result<Proof<E>, SynthesisError>
|
||||
where E: Engine, C: Circuit<E>, R: Rng
|
||||
where E: Engine, C: Circuit<E>, R: RngCore
|
||||
{
|
||||
let r = rng.gen();
|
||||
let s = rng.gen();
|
||||
let r = E::Fr::random(rng);
|
||||
let s = E::Fr::random(rng);
|
||||
|
||||
create_proof::<E, C, P>(circuit, params, r, s)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use pairing::{Engine, PairingCurveAffine};
|
|||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use rand::{Rand, Rng};
|
||||
use rand_core::RngCore;
|
||||
use std::num::Wrapping;
|
||||
|
||||
const MODULUS_R: Wrapping<u32> = Wrapping(64513);
|
||||
|
@ -20,13 +20,11 @@ impl fmt::Display for Fr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Rand for Fr {
|
||||
fn rand<R: Rng>(rng: &mut R) -> Self {
|
||||
Fr(Wrapping(rng.gen()) % MODULUS_R)
|
||||
}
|
||||
}
|
||||
|
||||
impl Field for Fr {
|
||||
fn random<R: RngCore>(rng: &mut R) -> Self {
|
||||
Fr(Wrapping(rng.next_u32()) % MODULUS_R)
|
||||
}
|
||||
|
||||
fn zero() -> Self {
|
||||
Fr(Wrapping(0))
|
||||
}
|
||||
|
@ -145,12 +143,6 @@ impl PartialOrd for FrRepr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Rand for FrRepr {
|
||||
fn rand<R: Rng>(rng: &mut R) -> Self {
|
||||
FrRepr([rng.gen()])
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FrRepr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", (self.0)[0])
|
||||
|
@ -300,6 +292,10 @@ impl CurveProjective for Fr {
|
|||
type Scalar = Fr;
|
||||
type Engine = DummyEngine;
|
||||
|
||||
fn random<R: RngCore>(rng: &mut R) -> Self {
|
||||
<Fr as Field>::random(rng)
|
||||
}
|
||||
|
||||
fn zero() -> Self {
|
||||
<Fr as Field>::zero()
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ extern crate ff;
|
|||
extern crate group;
|
||||
#[cfg(feature = "pairing")]
|
||||
extern crate pairing;
|
||||
extern crate rand;
|
||||
extern crate rand_core;
|
||||
|
||||
extern crate futures;
|
||||
extern crate bit_vec;
|
||||
|
@ -15,6 +15,9 @@ extern crate futures_cpupool;
|
|||
#[cfg(feature = "multicore")]
|
||||
extern crate num_cpus;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate rand;
|
||||
|
||||
pub mod multicore;
|
||||
mod multiexp;
|
||||
pub mod domain;
|
||||
|
|
|
@ -274,14 +274,14 @@ fn test_with_bls12() {
|
|||
acc
|
||||
}
|
||||
|
||||
use rand::{self, Rand};
|
||||
use rand;
|
||||
use pairing::{bls12_381::Bls12, Engine};
|
||||
|
||||
const SAMPLES: usize = 1 << 14;
|
||||
|
||||
let rng = &mut rand::thread_rng();
|
||||
let v = Arc::new((0..SAMPLES).map(|_| <Bls12 as ScalarEngine>::Fr::rand(rng).into_repr()).collect::<Vec<_>>());
|
||||
let g = Arc::new((0..SAMPLES).map(|_| <Bls12 as Engine>::G1::rand(rng).into_affine()).collect::<Vec<_>>());
|
||||
let v = Arc::new((0..SAMPLES).map(|_| <Bls12 as ScalarEngine>::Fr::random(rng).into_repr()).collect::<Vec<_>>());
|
||||
let g = Arc::new((0..SAMPLES).map(|_| <Bls12 as Engine>::G1::random(rng).into_affine()).collect::<Vec<_>>());
|
||||
|
||||
let naive = naive_multiexp(g.clone(), v.clone());
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ extern crate pairing;
|
|||
extern crate rand;
|
||||
|
||||
// For randomness (during paramgen and proof generation)
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::thread_rng;
|
||||
|
||||
// For benchmarking
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
// Bring in some tools for using pairing-friendly curves
|
||||
use ff::Field;
|
||||
use ff::{Field, ScalarEngine};
|
||||
use pairing::Engine;
|
||||
|
||||
// We're going to use the BLS12-381 pairing-friendly elliptic curve.
|
||||
|
@ -172,7 +172,7 @@ fn test_mimc() {
|
|||
let rng = &mut thread_rng();
|
||||
|
||||
// Generate the MiMC round constants
|
||||
let constants = (0..MIMC_ROUNDS).map(|_| rng.gen()).collect::<Vec<_>>();
|
||||
let constants = (0..MIMC_ROUNDS).map(|_| <Bls12 as ScalarEngine>::Fr::random(rng)).collect::<Vec<_>>();
|
||||
|
||||
println!("Creating parameters...");
|
||||
|
||||
|
@ -203,8 +203,8 @@ fn test_mimc() {
|
|||
|
||||
for _ in 0..SAMPLES {
|
||||
// Generate a random preimage and compute the image
|
||||
let xl = rng.gen();
|
||||
let xr = rng.gen();
|
||||
let xl = <Bls12 as ScalarEngine>::Fr::random(rng);
|
||||
let xr = <Bls12 as ScalarEngine>::Fr::random(rng);
|
||||
let image = mimc::<Bls12>(xl, xr, &constants);
|
||||
|
||||
proof_vec.truncate(0);
|
||||
|
|
Loading…
Reference in New Issue