Refactor algebra API, split into algebra and algebra-core. (#100)

This commit is contained in:
Pratyush Mishra
2020-02-26 21:42:04 -08:00
committed by GitHub
parent d4896ade47
commit 8bf042a029
68 changed files with 417 additions and 572 deletions

View File

@@ -1,4 +1,4 @@
use algebra::Field;
use algebra_core::Field;
use r1cs_core::{ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;

View File

@@ -1,5 +1,5 @@
use crate::nizk::{gm17::Gm17, NIZKVerifierGadget};
use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField};
use algebra_core::{AffineCurve, Field, PairingEngine, ToConstraintField};
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;
@@ -404,12 +404,11 @@ mod test {
use super::*;
use algebra::{
curves::bls12_377::Bls12_377,
fields::bls12_377::{Fq, Fr},
bls12_377::{Bls12_377, Fq, Fr},
test_rng, BitIterator, PrimeField,
};
use r1cs_std::{
boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget,
bls12_377::PairingGadget as Bls12_377PairingGadget, boolean::Boolean,
test_constraint_system::TestConstraintSystem,
};
use rand::Rng;

View File

@@ -1,5 +1,5 @@
use crate::Error;
use algebra::PairingEngine;
use algebra_core::PairingEngine;
use gm17::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
Parameters, PreparedVerifyingKey, Proof, VerifyingKey,
@@ -7,7 +7,7 @@ use gm17::{
use r1cs_core::ConstraintSynthesizer;
use rand::Rng;
use algebra::ToConstraintField;
use algebra_core::ToConstraintField;
use core::marker::PhantomData;
use super::NIZK;

View File

@@ -1,5 +1,5 @@
use crate::nizk::{groth16::Groth16, NIZKVerifierGadget};
use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField};
use algebra_core::{AffineCurve, Field, PairingEngine, ToConstraintField};
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;
@@ -351,12 +351,11 @@ mod test {
use super::*;
use algebra::{
curves::bls12_377::Bls12_377,
fields::bls12_377::{Fq, Fr},
bls12_377::{Bls12_377, Fq, Fr},
test_rng, BitIterator, PrimeField,
};
use r1cs_std::{
boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget,
bls12_377::PairingGadget as Bls12_377PairingGadget, boolean::Boolean,
test_constraint_system::TestConstraintSystem,
};
use rand::Rng;

View File

@@ -1,5 +1,5 @@
use crate::Error;
use algebra::PairingEngine;
use algebra_core::PairingEngine;
use groth16::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
Parameters, PreparedVerifyingKey, Proof, VerifyingKey,
@@ -7,7 +7,7 @@ use groth16::{
use r1cs_core::ConstraintSynthesizer;
use rand::Rng;
use algebra::ToConstraintField;
use algebra_core::ToConstraintField;
use core::marker::PhantomData;
use super::NIZK;

View File

@@ -1,4 +1,4 @@
use algebra::bytes::ToBytes;
use algebra_core::bytes::ToBytes;
use rand::Rng;
#[cfg(feature = "gm17")]
@@ -59,7 +59,10 @@ mod test {
#[test]
fn test_gm17() {
use crate::nizk::{gm17::Gm17, NIZK};
use algebra::{curves::bls12_381::Bls12_381, fields::bls12_381::Fr, One};
use algebra::{
bls12_377::{Bls12_377, Fr},
One,
};
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
#[derive(Copy, Clone)]
@@ -104,13 +107,13 @@ mod test {
let rng = &mut test_rng();
let parameters = Gm17::<Bls12_381, R1CSCircuit, [Fr]>::setup(circuit, rng).unwrap();
let parameters = Gm17::<Bls12_377, R1CSCircuit, [Fr]>::setup(circuit, rng).unwrap();
let proof =
Gm17::<Bls12_381, R1CSCircuit, [Fr]>::prove(&parameters.0, circuit, rng).unwrap();
Gm17::<Bls12_377, R1CSCircuit, [Fr]>::prove(&parameters.0, circuit, rng).unwrap();
let result =
Gm17::<Bls12_381, R1CSCircuit, [Fr]>::verify(&parameters.1, &[Fr::one(), sum], &proof)
Gm17::<Bls12_377, R1CSCircuit, [Fr]>::verify(&parameters.1, &[Fr::one(), sum], &proof)
.unwrap();
assert!(result);
}