mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-09 23:41:33 +01:00
Upgrade rand to 0.7 (#33)
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -739,7 +739,9 @@ mod test {
|
||||
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 @@ mod test {
|
||||
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);
|
||||
|
||||
@@ -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 @@ mod test {
|
||||
|
||||
#[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 @@ mod test {
|
||||
|
||||
#[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 @@ mod test {
|
||||
|
||||
#[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 @@ mod test {
|
||||
|
||||
#[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();
|
||||
|
||||
|
||||
@@ -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 @@ mod test {
|
||||
|
||||
#[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 @@ mod test {
|
||||
|
||||
#[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();
|
||||
|
||||
@@ -213,10 +213,11 @@ pub trait FieldGadget<F: Field, ConstraintF: Field>:
|
||||
|
||||
#[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 @@ mod test {
|
||||
// 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 @@ mod test {
|
||||
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 @@ mod test {
|
||||
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 @@ mod test {
|
||||
|
||||
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();
|
||||
|
||||
@@ -96,8 +96,10 @@ mod test {
|
||||
|
||||
#[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();
|
||||
|
||||
|
||||
@@ -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 @@ where
|
||||
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 @@ where
|
||||
);
|
||||
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user