Skip to content

Commit

Permalink
Sort the imports and merge them (#143)
Browse files Browse the repository at this point in the history
* Sort the imports ans merge them

* Undo the mistake

* More readability

* More cleaning
  • Loading branch information
autquis authored Oct 21, 2024
1 parent 26a1514 commit 6d026d6
Show file tree
Hide file tree
Showing 45 changed files with 241 additions and 278 deletions.
6 changes: 2 additions & 4 deletions crypto-primitives/src/commitment/blake2s/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use ark_relations::r1cs::{Namespace, SynthesisError};

use crate::{
commitment::{blake2s, CommitmentGadget},
prf::blake2s::constraints::{evaluate_blake2s, OutputVar},
};
use ark_ff::{Field, PrimeField};
use ark_r1cs_std::prelude::*;

use core::borrow::Borrow;
use ark_relations::r1cs::{Namespace, SynthesisError};
use ark_std::borrow::Borrow;

#[derive(Clone)]
pub struct ParametersVar;
Expand Down
3 changes: 1 addition & 2 deletions crypto-primitives/src/commitment/blake2s/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::CommitmentScheme;
use crate::Error;
use crate::{commitment::CommitmentScheme, Error};
use ark_std::rand::Rng;
use blake2::Blake2s256 as b2s;
use digest::Digest;
Expand Down
2 changes: 1 addition & 1 deletion crypto-primitives/src/commitment/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::commitment::CommitmentScheme;
use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use core::fmt::Debug;
use ark_std::fmt::Debug;

pub trait CommitmentGadget<C: CommitmentScheme, ConstraintF: Field> {
type OutputVar: EqGadget<ConstraintF>
Expand Down
2 changes: 0 additions & 2 deletions crypto-primitives/src/commitment/injective_map/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::commitment::{
Window,
},
};

pub use crate::crh::injective_map::constraints::InjectiveMapGadget;
use ark_ec::CurveGroup;
use ark_ff::{Field, PrimeField};
Expand All @@ -14,7 +13,6 @@ use ark_r1cs_std::{
uint8::UInt8,
};
use ark_relations::r1cs::SynthesisError;

use ark_std::marker::PhantomData;

type ConstraintF<C> = <<C as CurveGroup>::BaseField as Field>::BasePrimeField;
Expand Down
10 changes: 5 additions & 5 deletions crypto-primitives/src/commitment/injective_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::Error;
use ark_std::marker::PhantomData;

use super::{pedersen, CommitmentScheme};
pub use crate::crh::injective_map::InjectiveMap;
use crate::{
commitment::{pedersen, CommitmentScheme},
Error,
};
use ark_ec::CurveGroup;
use ark_std::rand::Rng;
use ark_std::{marker::PhantomData, rand::Rng};

#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
6 changes: 2 additions & 4 deletions crypto-primitives/src/commitment/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Error;
use ark_ff::UniformRand;
use ark_serialize::CanonicalSerialize;
use ark_std::rand::Rng;
use ark_std::{fmt::Debug, hash::Hash};
use ark_std::{fmt::Debug, hash::Hash, rand::Rng};

pub mod blake2s;
pub mod injective_map;
Expand All @@ -12,8 +12,6 @@ pub mod constraints;
#[cfg(feature = "r1cs")]
pub use constraints::*;

use crate::Error;

pub trait CommitmentScheme {
type Output: CanonicalSerialize + Clone + Default + Eq + Hash + Debug;
type Parameters: Clone;
Expand Down
5 changes: 2 additions & 3 deletions crypto-primitives/src/commitment/pedersen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use ark_ff::{
fields::{Field, PrimeField},
Zero,
};
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{Namespace, SynthesisError};
use ark_serialize::CanonicalSerialize;

use ark_r1cs_std::prelude::*;
use core::{borrow::Borrow, iter, marker::PhantomData};
use ark_std::{borrow::Borrow, iter, marker::PhantomData};

type ConstraintF<C> = <<C as CurveGroup>::BaseField as Field>::BasePrimeField;

Expand Down
16 changes: 7 additions & 9 deletions crypto-primitives/src/commitment/pedersen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::{crh::CRHScheme, Error};
use super::CommitmentScheme;
pub use crate::crh::pedersen::Window;
use crate::{
crh::{pedersen, CRHScheme},
Error,
};
use ark_ec::CurveGroup;
use ark_ff::{BitIteratorLE, Field, PrimeField, ToConstraintField};
use ark_serialize::CanonicalSerialize;
use ark_std::marker::PhantomData;
use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::UniformRand;

use super::CommitmentScheme;

use crate::crh::pedersen;
pub use crate::crh::pedersen::Window;
use ark_std::{marker::PhantomData, rand::Rng, UniformRand};

#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
13 changes: 6 additions & 7 deletions crypto-primitives/src/crh/bowe_hopwood/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use ark_ec::twisted_edwards::{Projective as TEProjective, TECurveConfig};
use ark_ec::CurveConfig;
use core::{borrow::Borrow, iter, marker::PhantomData};

use crate::crh::{
bowe_hopwood::{Parameters, CHUNK_SIZE},
bowe_hopwood::{Parameters, TwoToOneCRH, CHUNK_SIZE, CRH},
pedersen::{self, Window},
CRHSchemeGadget, TwoToOneCRHSchemeGadget,
};
use ark_ec::{
twisted_edwards::{Projective as TEProjective, TECurveConfig},
CurveConfig,
};
use ark_ff::Field;
use ark_r1cs_std::{groups::curves::twisted_edwards::AffineVar, prelude::*};
use ark_relations::r1cs::{Namespace, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

use crate::crh::bowe_hopwood::{TwoToOneCRH, CRH};
use ark_std::{borrow::Borrow, iter, marker::PhantomData};

type ConstraintF<P> = <<P as CurveConfig>::BaseField as Field>::BasePrimeField;

Expand Down
26 changes: 13 additions & 13 deletions crypto-primitives/src/crh/bowe_hopwood/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
//! specific Twisted Edwards (TE) curves. See [Section 5.4.17 of the Zcash protocol specification](https://raw.githubusercontent.com/zcash/zips/master/protocol/protocol.pdf#concretepedersenhash) for a formal description of this hash function, specialized for the Jubjub curve.
//! The implementation in this repository is generic across choice of TE curves.
use crate::Error;
use ark_std::rand::Rng;
use ark_std::{
fmt::{Debug, Formatter, Result as FmtResult},
marker::PhantomData,
use crate::{
crh::{pedersen, CRHScheme, TwoToOneCRHScheme},
Error,
};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

use super::pedersen;
use crate::crh::{CRHScheme, TwoToOneCRHScheme};
use ark_ec::{
twisted_edwards::Projective as TEProjective, twisted_edwards::TECurveConfig, AdditiveGroup,
CurveGroup,
};
use ark_ff::fields::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
use ark_std::cfg_chunks;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::UniformRand;
use ark_std::{
borrow::Borrow,
cfg_chunks,
fmt::{Debug, Formatter, Result as FmtResult},
marker::PhantomData,
rand::Rng,
UniformRand,
};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
8 changes: 3 additions & 5 deletions crypto-primitives/src/crh/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use ark_ff::Field;
use core::fmt::Debug;

use crate::crh::{CRHScheme, TwoToOneCRHScheme};
use ark_relations::r1cs::SynthesisError;

use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use ark_std::fmt::Debug;

pub trait CRHSchemeGadget<H: CRHScheme, ConstraintF: Field>: Sized {
type InputVar: ?Sized;
Expand Down
11 changes: 5 additions & 6 deletions crypto-primitives/src/crh/injective_map/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::crh::{
constraints,
injective_map::{InjectiveMap, PedersenCRHCompressor, TECompressor},
injective_map::{
InjectiveMap, PedersenCRHCompressor, PedersenTwoToOneCRHCompressor, TECompressor,
},
pedersen::{constraints as ped_constraints, Window},
TwoToOneCRHSchemeGadget,
CRHSchemeGadget, TwoToOneCRHSchemeGadget,
};
use ark_std::{fmt::Debug, marker::PhantomData};

use crate::crh::injective_map::PedersenTwoToOneCRHCompressor;
use crate::crh::CRHSchemeGadget;
use ark_ec::{
twisted_edwards::{Projective as TEProjective, TECurveConfig},
CurveConfig, CurveGroup,
Expand All @@ -17,6 +15,7 @@ use ark_r1cs_std::{
fields::fp::FpVar, groups::curves::twisted_edwards::AffineVar as TEVar, prelude::*,
};
use ark_relations::r1cs::SynthesisError;
use ark_std::{fmt::Debug, marker::PhantomData};

type ConstraintF<C> = <<C as CurveGroup>::BaseField as Field>::BasePrimeField;

Expand Down
15 changes: 7 additions & 8 deletions crypto-primitives/src/crh/injective_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::Error;
use ark_std::rand::Rng;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{fmt::Debug, hash::Hash, marker::PhantomData};

use super::{pedersen, CRHScheme, TwoToOneCRHScheme};
use crate::{
crh::{pedersen, CRHScheme, TwoToOneCRHScheme},
Error,
};
use ark_ec::{
twisted_edwards::{Affine as TEAffine, Projective as TEProjective, TECurveConfig},
CurveConfig, CurveGroup,
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{borrow::Borrow, fmt::Debug, hash::Hash, marker::PhantomData, rand::Rng};
#[cfg(feature = "r1cs")]
pub mod constraints;

Expand Down
31 changes: 7 additions & 24 deletions crypto-primitives/src/crh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
#![allow(clippy::upper_case_acronyms)]
use crate::Error;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{borrow::Borrow, fmt::Debug, hash::Hash, rand::Rng};

use ark_std::hash::Hash;
use ark_std::rand::Rng;
pub mod bowe_hopwood;
#[cfg(feature = "r1cs")]
pub mod constraints;
pub mod injective_map;
pub mod pedersen;
pub mod poseidon;
pub mod sha256;

use crate::Error;

#[cfg(feature = "r1cs")]
pub mod constraints;

use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
#[cfg(feature = "r1cs")]
pub use constraints::*;

/// Interface to CRH. Note that in this release, while all implementations of `CRH` have fixed length,
/// variable length CRH may also implement this trait in future.
pub trait CRHScheme {
type Input: ?Sized + Send;
type Output: Clone
+ Eq
+ core::fmt::Debug
+ Hash
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize;
type Output: Clone + Eq + Debug + Hash + Default + CanonicalSerialize + CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize + Sync;

fn setup<R: Rng>(r: &mut R) -> Result<Self::Parameters, Error>;
Expand All @@ -43,13 +32,7 @@ pub trait TwoToOneCRHScheme {
/// Raw Input type of TwoToOneCRH
type Input: ?Sized;
/// Raw Output type of TwoToOneCRH
type Output: Clone
+ Eq
+ core::fmt::Debug
+ Hash
+ Default
+ CanonicalSerialize
+ CanonicalDeserialize;
type Output: Clone + Eq + Debug + Hash + Default + CanonicalSerialize + CanonicalDeserialize;
type Parameters: Clone + CanonicalSerialize + CanonicalDeserialize + Sync;

fn setup<R: Rng>(r: &mut R) -> Result<Self::Parameters, Error>;
Expand Down
9 changes: 3 additions & 6 deletions crypto-primitives/src/crh/pedersen/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::crh::{
pedersen::{Parameters, Window},
CRHSchemeGadget as CRHGadgetTrait,
pedersen::{Parameters, TwoToOneCRH, Window, CRH},
CRHSchemeGadget as CRHGadgetTrait, CRHSchemeGadget, TwoToOneCRHSchemeGadget,
};
use ark_ec::CurveGroup;
use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{Namespace, SynthesisError};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;

use crate::crh::pedersen::{TwoToOneCRH, CRH};
use crate::crh::{CRHSchemeGadget, TwoToOneCRHSchemeGadget};
use core::{borrow::Borrow, iter, marker::PhantomData};
use ark_std::{borrow::Borrow, iter, marker::PhantomData};

#[derive(Derivative)]
#[derivative(Clone(bound = "C: CurveGroup, GG: CurveVar<C, ConstraintF<C>>"))]
Expand Down
23 changes: 12 additions & 11 deletions crypto-primitives/src/crh/pedersen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use crate::Error;
use ark_std::rand::Rng;
use ark_std::{
fmt::{Debug, Formatter, Result as FmtResult},
marker::PhantomData,
use crate::{
crh::{CRHScheme, TwoToOneCRHScheme},
Error,
};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

use crate::crh::{CRHScheme, TwoToOneCRHScheme};
use ark_ec::CurveGroup;
use ark_ff::{Field, ToConstraintField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::borrow::Borrow;
use ark_std::cfg_chunks;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{
borrow::Borrow,
cfg_chunks,
fmt::{Debug, Formatter, Result as FmtResult},
marker::PhantomData,
rand::Rng,
};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
Loading

0 comments on commit 6d026d6

Please sign in to comment.