arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
Upgrade rand to 0.7 (#33)

Pratyush Mishra pratyushmishra@berkeley.edu
Tue, 17 Sep 2019 16:30:42 -0700
commit

8ea084ddfce9ba8dd9a4a09f3f5d4adf37692e7d

parent

cfe2c8d29ae75f93b0434dfe75b47dc02c956896

M r1cs-std/Cargo.toml → r1cs-std/Cargo.toml

@@ -28,4 +28,5 @@ derivative = "1"

radix_trie = "0.1" [dev-dependencies] -rand = { version = "0.4" } +rand = { version = "0.7" } +rand_xorshift = { version = "0.2" }
M r1cs-std/src/bits/boolean.rs → r1cs-std/src/bits/boolean.rs

@@ -739,7 +739,9 @@ test_constraint_system::TestConstraintSystem,

prelude::* }; use algebra::{fields::bls12_381::Fr, BitIterator, Field, PrimeField}; - use rand::{Rand, SeedableRng, XorShiftRng}; + use algebra::UniformRand; +use rand::SeedableRng; +use rand_xorshift::XorShiftRng; use r1cs_core::ConstraintSystem; use std::str::FromStr;

@@ -1736,7 +1738,7 @@

assert!(!cs.is_satisfied()); } - let mut rng = XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let r = Fr::rand(&mut rng);
M r1cs-std/src/bits/uint32.rs → r1cs-std/src/bits/uint32.rs

@@ -340,12 +340,13 @@ mod test {

use super::UInt32; use crate::{bits::boolean::Boolean, test_constraint_system::TestConstraintSystem}; use algebra::fields::{bls12_381::Fr, Field}; - use rand::{Rng, SeedableRng, XorShiftRng}; + use rand::{Rng, SeedableRng}; + use rand_xorshift::XorShiftRng; use r1cs_core::ConstraintSystem; #[test] fn test_uint32_from_bits() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let v = (0..32)

@@ -377,7 +378,7 @@ }

#[test] fn test_uint32_xor() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let mut cs = TestConstraintSystem::<Fr>::new();

@@ -419,7 +420,7 @@ }

#[test] fn test_uint32_addmany_constants() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let mut cs = TestConstraintSystem::<Fr>::new();

@@ -454,7 +455,7 @@ }

#[test] fn test_uint32_addmany() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let mut cs = TestConstraintSystem::<Fr>::new();

@@ -505,7 +506,7 @@ }

#[test] fn test_uint32_rotr() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut num = rng.gen();
M r1cs-std/src/bits/uint8.rs → r1cs-std/src/bits/uint8.rs

@@ -294,7 +294,8 @@ mod test {

use super::UInt8; use crate::{prelude::*, test_constraint_system::TestConstraintSystem}; use algebra::fields::bls12_381::Fr; - use rand::{Rng, SeedableRng, XorShiftRng}; + use rand::{Rng, SeedableRng}; + use rand_xorshift::XorShiftRng; use r1cs_core::ConstraintSystem; #[test]

@@ -323,7 +324,7 @@ }

#[test] fn test_uint8_from_bits() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let v = (0..8)

@@ -355,7 +356,7 @@ }

#[test] fn test_uint8_xor() { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for _ in 0..1000 { let mut cs = TestConstraintSystem::<Fr>::new();
M r1cs-std/src/fields/mod.rs → r1cs-std/src/fields/mod.rs

@@ -213,10 +213,11 @@ }

#[cfg(test)] mod test { - use rand::{self, thread_rng, Rand, SeedableRng, XorShiftRng}; + use rand::{self, thread_rng, SeedableRng}; + use rand_xorshift::XorShiftRng; use crate::{prelude::*, test_constraint_system::TestConstraintSystem}; - use algebra::{fields::Field, BitIterator}; + use algebra::{UniformRand, Field, BitIterator}; use r1cs_core::ConstraintSystem; fn field_test<FE: Field, ConstraintF: Field, F: FieldGadget<FE, ConstraintF>, CS: ConstraintSystem<ConstraintF>>(

@@ -388,7 +389,7 @@

// a * a * a = a^3 let mut constants = [FE::zero(); 4]; for c in &mut constants { - *c = rand::random(); + *c = UniformRand::rand(&mut thread_rng()); println!("Current c[i]: {:?}", c); } let bits = [Boolean::constant(false), Boolean::constant(true)];

@@ -396,7 +397,7 @@ let lookup_result =

F::two_bit_lookup(cs.ns(|| "Lookup"), &bits, constants.as_ref()).unwrap(); assert_eq!(lookup_result.get_value().unwrap(), constants[2]); - let negone: FE = rand::random(); + let negone: FE = UniformRand::rand(&mut thread_rng()); let n = F::alloc(&mut cs.ns(|| "alloc new var"), || Ok(negone)).unwrap(); let _ = n.to_bytes(&mut cs.ns(|| "ToBytes")).unwrap();

@@ -412,7 +413,7 @@ >(

mut cs: CS, maxpower: usize, ) { - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); for i in 0..(maxpower + 1) { let mut a = FE::rand(&mut rng); let mut a_gadget = F::alloc(cs.ns(|| format!("a_gadget_{:?}", i)), || Ok(a)).unwrap();

@@ -432,7 +433,7 @@ use algebra::fields::bls12_377::{Fq, Fq12, Fq2, Fq6};

let mut cs = TestConstraintSystem::<Fq>::new(); - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let a = FqGadget::alloc(&mut cs.ns(|| "generate_a"), || Ok(Fq::rand(&mut rng))).unwrap(); let b = FqGadget::alloc(&mut cs.ns(|| "generate_b"), || Ok(Fq::rand(&mut rng))).unwrap();
M r1cs-std/src/groups/curves/short_weierstrass/bls12/bls12_377.rs → r1cs-std/src/groups/curves/short_weierstrass/bls12/bls12_377.rs

@@ -96,8 +96,10 @@ }

#[test] fn bls12_g1_gadget_test() { - use rand::{Rand, SeedableRng, XorShiftRng}; - let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + use algebra::UniformRand; + use rand::SeedableRng; + use rand_xorshift::XorShiftRng; + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut cs = TestConstraintSystem::<Fq>::new();
M r1cs-std/src/groups/curves/twisted_edwards/test.rs → r1cs-std/src/groups/curves/twisted_edwards/test.rs

@@ -1,10 +1,10 @@

-use rand; +use rand::thread_rng; use crate::{prelude::*, groups::test::group_test}; use algebra::{ curves::{models::TEModelParameters, twisted_edwards_extended::GroupAffine as TEAffine}, - BitIterator, Group, PrimeField, Field, + BitIterator, Group, PrimeField, Field, UniformRand, }; use r1cs_core::ConstraintSystem;

@@ -16,8 +16,8 @@ P: TEModelParameters,

GG: GroupGadget<TEAffine<P>, ConstraintF, Value = TEAffine<P>>, CS: ConstraintSystem<ConstraintF>, { - let a: TEAffine<P> = rand::random(); - let b: TEAffine<P> = rand::random(); + let a: TEAffine<P> = UniformRand::rand(&mut thread_rng()); + let b: TEAffine<P> = UniformRand::rand(&mut thread_rng()); let gadget_a = GG::alloc(&mut cs.ns(|| "a"), || Ok(a)).unwrap(); let gadget_b = GG::alloc(&mut cs.ns(|| "b"), || Ok(b)).unwrap(); assert_eq!(gadget_a.get_value().unwrap(), a);

@@ -29,7 +29,7 @@ gadget_b,

); // Check mul_bits - let scalar: <TEAffine<P> as Group>::ScalarField = rand::random(); + let scalar: <TEAffine<P> as Group>::ScalarField = UniformRand::rand(&mut thread_rng()); let native_result = a.mul(&scalar); let mut scalar: Vec<bool> = BitIterator::new(scalar.into_repr()).collect();