crypto-primitives no-std (#96)

This commit is contained in:
Marek Kotewicz
2020-02-20 20:35:53 +01:00
committed by GitHub
parent 02e6b32d7d
commit d4896ade47
37 changed files with 202 additions and 153 deletions

View File

@@ -3,8 +3,8 @@ use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField};
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;
use core::{borrow::Borrow, marker::PhantomData};
use gm17::{Proof, VerifyingKey};
use std::{borrow::Borrow, marker::PhantomData};
#[derive(Derivative)]
#[derivative(Clone(bound = "P::G1Gadget: Clone, P::G2Gadget: Clone"))]
@@ -406,13 +406,13 @@ mod test {
use algebra::{
curves::bls12_377::Bls12_377,
fields::bls12_377::{Fq, Fr},
BitIterator, PrimeField,
test_rng, BitIterator, PrimeField,
};
use r1cs_std::{
boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget,
test_constraint_system::TestConstraintSystem,
};
use rand::{thread_rng, Rng};
use rand::Rng;
type TestProofSystem = Gm17<Bls12_377, Bench<Fr>, Fr>;
type TestVerifierGadget = Gm17VerifierGadget<Bls12_377, Fq, Bls12_377PairingGadget>;
@@ -469,7 +469,7 @@ mod test {
fn gm17_verifier_test() {
let num_inputs = 100;
let num_constraints = num_inputs;
let rng = &mut thread_rng();
let rng = &mut test_rng();
let mut inputs: Vec<Option<Fr>> = Vec::with_capacity(num_inputs);
for _ in 0..num_inputs {
inputs.push(Some(rng.gen()));

View File

@@ -8,7 +8,7 @@ use r1cs_core::ConstraintSynthesizer;
use rand::Rng;
use algebra::ToConstraintField;
use std::marker::PhantomData;
use core::marker::PhantomData;
use super::NIZK;

View File

@@ -3,8 +3,8 @@ use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField};
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;
use core::{borrow::Borrow, marker::PhantomData};
use groth16::{Proof, VerifyingKey};
use std::{borrow::Borrow, marker::PhantomData};
#[derive(Derivative)]
#[derivative(Clone(bound = "P::G1Gadget: Clone, P::G2Gadget: Clone"))]
@@ -353,13 +353,13 @@ mod test {
use algebra::{
curves::bls12_377::Bls12_377,
fields::bls12_377::{Fq, Fr},
BitIterator, PrimeField,
test_rng, BitIterator, PrimeField,
};
use r1cs_std::{
boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget,
test_constraint_system::TestConstraintSystem,
};
use rand::{thread_rng, Rng};
use rand::Rng;
type TestProofSystem = Groth16<Bls12_377, Bench<Fr>, Fr>;
type TestVerifierGadget = Groth16VerifierGadget<Bls12_377, Fq, Bls12_377PairingGadget>;
@@ -416,7 +416,7 @@ mod test {
fn groth16_verifier_test() {
let num_inputs = 100;
let num_constraints = num_inputs;
let rng = &mut thread_rng();
let rng = &mut test_rng();
let mut inputs: Vec<Option<Fr>> = Vec::with_capacity(num_inputs);
for _ in 0..num_inputs {
inputs.push(Some(rng.gen()));

View File

@@ -8,7 +8,7 @@ use r1cs_core::ConstraintSynthesizer;
use rand::Rng;
use algebra::ToConstraintField;
use std::marker::PhantomData;
use core::marker::PhantomData;
use super::NIZK;

View File

@@ -53,8 +53,8 @@ pub trait NIZK {
#[cfg(all(feature = "gm17", test))]
mod test {
use rand::thread_rng;
use std::ops::AddAssign;
use algebra::test_rng;
use core::ops::AddAssign;
#[test]
fn test_gm17() {
@@ -102,7 +102,7 @@ mod test {
sum.add_assign(&Fr::one());
let circuit = R1CSCircuit::new(Fr::one(), sum, Fr::one());
let rng = &mut thread_rng();
let rng = &mut test_rng();
let parameters = Gm17::<Bls12_381, R1CSCircuit, [Fr]>::setup(circuit, rng).unwrap();