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,16 +1,14 @@
use algebra::Field;
use core::hash::Hash;
use core::{borrow::Borrow, hash::Hash, marker::PhantomData};
use crate::crh::{
bowe_hopwood::{BoweHopwoodPedersenCRH, BoweHopwoodPedersenParameters, CHUNK_SIZE},
pedersen::PedersenWindow,
FixedLengthCRHGadget,
};
use algebra::groups::Group;
use algebra_core::{groups::Group, Field};
use r1cs_core::{ConstraintSystem, SynthesisError};
use r1cs_std::{alloc::AllocGadget, groups::GroupGadget, uint8::UInt8};
use core::{borrow::Borrow, marker::PhantomData};
use r1cs_std::bits::boolean::Boolean;
#[derive(Derivative)]
@@ -125,38 +123,39 @@ impl<G: Group, W: PedersenWindow, ConstraintF: Field, GG: GroupGadget<G, Constra
#[cfg(test)]
mod test {
use rand::Rng;
use crate::crh::{
bowe_hopwood::{constraints::BoweHopwoodPedersenCRHGadget, BoweHopwoodPedersenCRH},
pedersen::PedersenWindow,
FixedLengthCRH, FixedLengthCRHGadget,
};
use algebra::{
curves::edwards_sw6::EdwardsProjective as Edwards, fields::sw6::fr::Fr, test_rng,
ProjectiveCurve,
jubjub::{Fq as Fr, JubJubProjective as JubJub},
test_rng, ProjectiveCurve,
};
use r1cs_core::ConstraintSystem;
use r1cs_std::{
alloc::AllocGadget, groups::curves::twisted_edwards::edwards_sw6::EdwardsSWGadget,
test_constraint_system::TestConstraintSystem, uint8::UInt8,
alloc::AllocGadget, jubjub::JubJubGadget, test_constraint_system::TestConstraintSystem,
uint8::UInt8,
};
use rand::Rng;
type TestCRH = BoweHopwoodPedersenCRH<Edwards, Window>;
type TestCRHGadget = BoweHopwoodPedersenCRHGadget<Edwards, Fr, EdwardsSWGadget>;
type TestCRH = BoweHopwoodPedersenCRH<JubJub, Window>;
type TestCRHGadget = BoweHopwoodPedersenCRHGadget<JubJub, Fr, JubJubGadget>;
#[derive(Clone, PartialEq, Eq, Hash)]
pub(super) struct Window;
impl PedersenWindow for Window {
const WINDOW_SIZE: usize = 90;
const WINDOW_SIZE: usize = 63;
const NUM_WINDOWS: usize = 8;
}
fn generate_input<CS: ConstraintSystem<Fr>, R: Rng>(
mut cs: CS,
rng: &mut R,
) -> ([u8; 270], Vec<UInt8>) {
let mut input = [1u8; 270];
) -> ([u8; 189], Vec<UInt8>) {
let mut input = [1u8; 189];
rng.fill_bytes(&mut input);
let mut input_bytes = vec![];

View File

@@ -9,7 +9,7 @@ use rayon::prelude::*;
use super::pedersen::{bytes_to_bits, PedersenCRH, PedersenWindow};
use crate::crh::FixedLengthCRH;
use algebra::{biginteger::BigInteger, fields::PrimeField, groups::Group};
use algebra_core::{biginteger::BigInteger, fields::PrimeField, groups::Group};
use ff_fft::cfg_chunks;
#[cfg(feature = "r1cs")]
@@ -173,22 +173,22 @@ mod test {
crh::{bowe_hopwood::BoweHopwoodPedersenCRH, pedersen::PedersenWindow},
FixedLengthCRH,
};
use algebra::{curves::edwards_sw6::EdwardsProjective, test_rng};
use algebra::{jubjub::JubJubProjective, test_rng};
#[test]
fn test_simple_bh() {
#[derive(Clone)]
struct TestWindow {}
impl PedersenWindow for TestWindow {
const WINDOW_SIZE: usize = 90;
const WINDOW_SIZE: usize = 63;
const NUM_WINDOWS: usize = 8;
}
let rng = &mut test_rng();
let params =
<BoweHopwoodPedersenCRH<EdwardsProjective, TestWindow> as FixedLengthCRH>::setup(rng)
<BoweHopwoodPedersenCRH<JubJubProjective, TestWindow> as FixedLengthCRH>::setup(rng)
.unwrap();
<BoweHopwoodPedersenCRH<EdwardsProjective, TestWindow> as FixedLengthCRH>::evaluate(
<BoweHopwoodPedersenCRH<JubJubProjective, TestWindow> as FixedLengthCRH>::evaluate(
&params,
&[1, 2, 3],
)

View File

@@ -1,4 +1,4 @@
use algebra::Field;
use algebra_core::Field;
use core::fmt::Debug;
use crate::crh::FixedLengthCRH;

View File

@@ -9,7 +9,7 @@ use crate::crh::{
FixedLengthCRHGadget,
};
use algebra::{
use algebra_core::{
curves::{
models::{ModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine as TEAffine, GroupProjective as TEProjective},

View File

@@ -1,5 +1,5 @@
use crate::{CryptoError, Error};
use algebra::bytes::ToBytes;
use algebra_core::bytes::ToBytes;
use core::{fmt::Debug, hash::Hash, marker::PhantomData};
use rand::Rng;
@@ -7,7 +7,7 @@ use super::{
pedersen::{PedersenCRH, PedersenParameters, PedersenWindow},
FixedLengthCRH,
};
use algebra::{
use algebra_core::{
curves::{
models::{ModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine as TEAffine, GroupProjective as TEProjective},

View File

@@ -1,4 +1,4 @@
use algebra::bytes::ToBytes;
use algebra_core::bytes::ToBytes;
use core::hash::Hash;
use rand::Rng;

View File

@@ -2,7 +2,7 @@ use crate::crh::{
pedersen::{PedersenCRH, PedersenParameters, PedersenWindow},
FixedLengthCRHGadget,
};
use algebra::{Field, Group};
use algebra_core::{Field, Group};
use r1cs_core::{ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;
@@ -119,14 +119,12 @@ mod test {
FixedLengthCRH, FixedLengthCRHGadget,
};
use algebra::{
curves::{jubjub::JubJubProjective as JubJub, ProjectiveCurve},
fields::bls12_381::fr::Fr,
test_rng,
jubjub::{Fq as Fr, JubJubProjective as JubJub},
test_rng, ProjectiveCurve,
};
use r1cs_core::ConstraintSystem;
use r1cs_std::{
groups::curves::twisted_edwards::jubjub::JubJubGadget, prelude::*,
test_constraint_system::TestConstraintSystem,
jubjub::JubJubGadget, prelude::*, test_constraint_system::TestConstraintSystem,
};
use rand::Rng;

View File

@@ -8,7 +8,7 @@ use rand::Rng;
use rayon::prelude::*;
use crate::crh::FixedLengthCRH;
use algebra::{groups::Group, Field, ToConstraintField};
use algebra_core::{groups::Group, Field, ToConstraintField};
use ff_fft::cfg_chunks;
#[cfg(feature = "r1cs")]