Skip to content
Permalink
Browse files

Upgrade ff-fft, gm17, and r1cs-std

  • Loading branch information...
Pratyush committed Sep 17, 2019
1 parent e019c90 commit e605d5bdb9ac125e83e48fa4e131e859ddb748b7
@@ -52,9 +52,9 @@ impl<F: PrimeField> EvaluationDomain<F> {

/// Sample an element that is *not* in the domain.
pub fn sample_element_outside_domain<R: Rng>(&self, rng: &mut R) -> F {
let mut t = rng.gen();
let mut t = F::rand(rng);
while self.evaluate_vanishing_polynomial(t).is_zero() {
t = rng.gen();
t = F::rand(rng);
}
t
}
@@ -360,7 +360,8 @@ impl<'a, 'b, F: PrimeField> Mul<&'a DensePolynomial<F>> for &'b DensePolynomial<
mod tests {
use crate::polynomial::*;
use algebra::fields::{bls12_381::fr::Fr, Field};
use rand::{thread_rng, Rand};
use algebra::UniformRand;
use rand::thread_rng;

#[test]
fn double_polynomials_random() {
@@ -1,6 +1,7 @@
use algebra::UniformRand;
use algebra::curves::{bls12_381::Bls12_381, PairingEngine};
use crate::{domain::*, multicore::*};
use rand::{self, Rand};
use rand;
use std::cmp::min;

// Test multiplying various (low degree) polynomials together and
@@ -13,7 +14,7 @@ fn fft_composition() {

let mut v = vec![];
for _ in 0..coeffs {
v.push(rng.gen());
v.push(E::Fr::rand(rng));
}
let mut v2 = v.clone();

@@ -1,6 +1,6 @@
use ff_fft::EvaluationDomain;
use algebra::{
msm::FixedBaseMSM,
msm::FixedBaseMSM, UniformRand,
AffineCurve, Field, PairingEngine, PrimeField, ProjectiveCurve,
};

@@ -22,11 +22,11 @@ where
C: ConstraintSynthesizer<E::Fr>,
R: Rng,
{
let alpha = rng.gen();
let beta = rng.gen();
let alpha = E::Fr::rand(rng);
let beta = E::Fr::rand(rng);
let gamma = E::Fr::one();
let g = rng.gen();
let h = rng.gen();
let g = E::G1Projective::rand(rng);
let h = E::G2Projective::rand(rng);

generate_parameters::<E, C, R>(circuit, alpha, beta, gamma, g, h, rng)
}
@@ -2,7 +2,7 @@ use rand::Rng;
use rayon::prelude::*;

use algebra::{
msm::VariableBaseMSM, AffineCurve, Field, PairingEngine, PrimeField, ProjectiveCurve,
UniformRand, msm::VariableBaseMSM, AffineCurve, Field, PairingEngine, PrimeField, ProjectiveCurve,
};

use crate::{Parameters, Proof};
@@ -187,9 +187,9 @@ where
C: ConstraintSynthesizer<E::Fr>,
R: Rng,
{
let d1 = rng.gen();
let d2 = rng.gen();
let r = rng.gen();
let d1 = E::Fr::rand(rng);
let d2 = E::Fr::rand(rng);
let r = E::Fr::rand(rng);

create_proof::<E, C>(circuit, params, d1, d2, r)
}
@@ -35,8 +35,8 @@ mod bls12_377 {
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
};

use algebra::{curves::bls12_377::Bls12_377, fields::bls12_377::Fr};
use rand::{thread_rng, Rand};
use algebra::{UniformRand, curves::bls12_377::Bls12_377, fields::bls12_377::Fr};
use rand::thread_rng;
use std::ops::MulAssign;

#[test]
@@ -77,9 +77,9 @@ mod sw6 {
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
};

use rand::{thread_rng, Rand};
use rand::thread_rng;

use algebra::{curves::sw6::SW6, fields::sw6::Fr as SW6Fr, Field};
use algebra::{UniformRand, curves::sw6::SW6, fields::sw6::Fr as SW6Fr, Field};

#[test]
fn prove_and_verify() {
@@ -29,3 +29,4 @@ radix_trie = "0.1"

[dev-dependencies]
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,15 +389,15 @@ 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)];
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 @@ 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();

0 comments on commit e605d5b

Please sign in to comment.
You can’t perform that action at this time.