From 6d026d60ec17a0f9311a1f32afd9210541c3472a Mon Sep 17 00:00:00 2001 From: Hossein Moghaddas Date: Mon, 21 Oct 2024 22:19:49 +0200 Subject: [PATCH] Sort the imports and merge them (#143) * Sort the imports ans merge them * Undo the mistake * More readability * More cleaning --- .../src/commitment/blake2s/constraints.rs | 6 ++-- .../src/commitment/blake2s/mod.rs | 3 +- .../src/commitment/constraints.rs | 2 +- .../commitment/injective_map/constraints.rs | 2 -- .../src/commitment/injective_map/mod.rs | 10 +++--- crypto-primitives/src/commitment/mod.rs | 6 ++-- .../src/commitment/pedersen/constraints.rs | 5 ++- .../src/commitment/pedersen/mod.rs | 16 +++++----- .../src/crh/bowe_hopwood/constraints.rs | 13 ++++---- crypto-primitives/src/crh/bowe_hopwood/mod.rs | 26 ++++++++-------- crypto-primitives/src/crh/constraints.rs | 8 ++--- .../src/crh/injective_map/constraints.rs | 11 +++---- .../src/crh/injective_map/mod.rs | 15 +++++---- crypto-primitives/src/crh/mod.rs | 31 +++++-------------- .../src/crh/pedersen/constraints.rs | 9 ++---- crypto-primitives/src/crh/pedersen/mod.rs | 23 +++++++------- .../src/crh/poseidon/constraints.rs | 31 ++++++++++--------- crypto-primitives/src/crh/poseidon/mod.rs | 16 +++++----- .../src/crh/sha256/constraints.rs | 4 +-- crypto-primitives/src/crh/sha256/mod.rs | 14 ++++----- .../src/encryption/constraints.rs | 6 ++-- .../src/encryption/elgamal/constraints.rs | 11 +++---- .../src/encryption/elgamal/mod.rs | 13 +++----- crypto-primitives/src/encryption/mod.rs | 9 +++--- crypto-primitives/src/lib.rs | 4 +-- .../src/merkle_tree/constraints.rs | 10 +++--- crypto-primitives/src/merkle_tree/mod.rs | 25 +++++++-------- .../src/merkle_tree/tests/constraints.rs | 27 +++++++++------- .../src/merkle_tree/tests/mod.rs | 12 ++++--- .../src/merkle_tree/tests/test_utils.rs | 3 +- .../src/prf/blake2s/constraints.rs | 8 ++--- crypto-primitives/src/prf/blake2s/mod.rs | 4 +-- crypto-primitives/src/prf/constraints.rs | 8 ++--- crypto-primitives/src/prf/mod.rs | 5 ++- .../src/signature/constraints.rs | 3 +- crypto-primitives/src/signature/mod.rs | 3 +- .../src/signature/schnorr/constraints.rs | 9 +++--- .../src/signature/schnorr/mod.rs | 4 +-- crypto-primitives/src/snark/constraints.rs | 18 ++++++----- crypto-primitives/src/sponge/absorb.rs | 15 +++++---- .../src/sponge/constraints/absorb.rs | 17 +++++----- .../src/sponge/constraints/mod.rs | 26 ++++++++++------ .../src/sponge/poseidon/constraints.rs | 13 ++++---- .../src/sponge/poseidon/tests.rs | 12 ++++--- .../src/sponge/poseidon/traits.rs | 3 +- 45 files changed, 241 insertions(+), 278 deletions(-) diff --git a/crypto-primitives/src/commitment/blake2s/constraints.rs b/crypto-primitives/src/commitment/blake2s/constraints.rs index 07f28ca8..3989d974 100644 --- a/crypto-primitives/src/commitment/blake2s/constraints.rs +++ b/crypto-primitives/src/commitment/blake2s/constraints.rs @@ -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; diff --git a/crypto-primitives/src/commitment/blake2s/mod.rs b/crypto-primitives/src/commitment/blake2s/mod.rs index cab562ed..724f3771 100644 --- a/crypto-primitives/src/commitment/blake2s/mod.rs +++ b/crypto-primitives/src/commitment/blake2s/mod.rs @@ -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; diff --git a/crypto-primitives/src/commitment/constraints.rs b/crypto-primitives/src/commitment/constraints.rs index 5124e5a5..e7a533ee 100644 --- a/crypto-primitives/src/commitment/constraints.rs +++ b/crypto-primitives/src/commitment/constraints.rs @@ -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 { type OutputVar: EqGadget diff --git a/crypto-primitives/src/commitment/injective_map/constraints.rs b/crypto-primitives/src/commitment/injective_map/constraints.rs index bc9dc628..13a9d67f 100644 --- a/crypto-primitives/src/commitment/injective_map/constraints.rs +++ b/crypto-primitives/src/commitment/injective_map/constraints.rs @@ -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}; @@ -14,7 +13,6 @@ use ark_r1cs_std::{ uint8::UInt8, }; use ark_relations::r1cs::SynthesisError; - use ark_std::marker::PhantomData; type ConstraintF = <::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/commitment/injective_map/mod.rs b/crypto-primitives/src/commitment/injective_map/mod.rs index 700edf7b..ca32904c 100644 --- a/crypto-primitives/src/commitment/injective_map/mod.rs +++ b/crypto-primitives/src/commitment/injective_map/mod.rs @@ -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; diff --git a/crypto-primitives/src/commitment/mod.rs b/crypto-primitives/src/commitment/mod.rs index 30edabeb..c94db15b 100644 --- a/crypto-primitives/src/commitment/mod.rs +++ b/crypto-primitives/src/commitment/mod.rs @@ -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; @@ -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; diff --git a/crypto-primitives/src/commitment/pedersen/constraints.rs b/crypto-primitives/src/commitment/pedersen/constraints.rs index 8386815d..8dec380a 100644 --- a/crypto-primitives/src/commitment/pedersen/constraints.rs +++ b/crypto-primitives/src/commitment/pedersen/constraints.rs @@ -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 = <::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/commitment/pedersen/mod.rs b/crypto-primitives/src/commitment/pedersen/mod.rs index e1aa0d4b..96345322 100644 --- a/crypto-primitives/src/commitment/pedersen/mod.rs +++ b/crypto-primitives/src/commitment/pedersen/mod.rs @@ -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; diff --git a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs index a9bf49de..fd0c433b 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs @@ -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

= <

::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/crh/bowe_hopwood/mod.rs b/crypto-primitives/src/crh/bowe_hopwood/mod.rs index d284c3ef..89a4ca27 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/mod.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/mod.rs @@ -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; diff --git a/crypto-primitives/src/crh/constraints.rs b/crypto-primitives/src/crh/constraints.rs index 81c0aebd..28ea34b4 100644 --- a/crypto-primitives/src/crh/constraints.rs +++ b/crypto-primitives/src/crh/constraints.rs @@ -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: Sized { type InputVar: ?Sized; diff --git a/crypto-primitives/src/crh/injective_map/constraints.rs b/crypto-primitives/src/crh/injective_map/constraints.rs index 1a60c842..5d034c99 100644 --- a/crypto-primitives/src/crh/injective_map/constraints.rs +++ b/crypto-primitives/src/crh/injective_map/constraints.rs @@ -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, @@ -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 = <::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/crh/injective_map/mod.rs b/crypto-primitives/src/crh/injective_map/mod.rs index 289a9006..f84ea1f8 100644 --- a/crypto-primitives/src/crh/injective_map/mod.rs +++ b/crypto-primitives/src/crh/injective_map/mod.rs @@ -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; diff --git a/crypto-primitives/src/crh/mod.rs b/crypto-primitives/src/crh/mod.rs index 08cb4a6e..e0e214b7 100644 --- a/crypto-primitives/src/crh/mod.rs +++ b/crypto-primitives/src/crh/mod.rs @@ -1,20 +1,15 @@ #![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::*; @@ -22,13 +17,7 @@ pub use constraints::*; /// 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: &mut R) -> Result; @@ -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: &mut R) -> Result; diff --git a/crypto-primitives/src/crh/pedersen/constraints.rs b/crypto-primitives/src/crh/pedersen/constraints.rs index 0d1e72ff..ce7aa49f 100644 --- a/crypto-primitives/src/crh/pedersen/constraints.rs +++ b/crypto-primitives/src/crh/pedersen/constraints.rs @@ -1,6 +1,6 @@ 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; @@ -8,10 +8,7 @@ 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>"))] diff --git a/crypto-primitives/src/crh/pedersen/mod.rs b/crypto-primitives/src/crh/pedersen/mod.rs index 29d696d4..6fb1650f 100644 --- a/crypto-primitives/src/crh/pedersen/mod.rs +++ b/crypto-primitives/src/crh/pedersen/mod.rs @@ -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; diff --git a/crypto-primitives/src/crh/poseidon/constraints.rs b/crypto-primitives/src/crh/poseidon/constraints.rs index 059a6934..ef7219ed 100644 --- a/crypto-primitives/src/crh/poseidon/constraints.rs +++ b/crypto-primitives/src/crh/poseidon/constraints.rs @@ -1,22 +1,25 @@ -use crate::crh::poseidon::{TwoToOneCRH, CRH}; -use crate::crh::CRHScheme; -use crate::crh::{ - CRHSchemeGadget as CRHGadgetTrait, TwoToOneCRHSchemeGadget as TwoToOneCRHGadgetTrait, +use crate::{ + crh::{ + poseidon::{TwoToOneCRH, CRH}, + CRHScheme, CRHSchemeGadget as CRHGadgetTrait, + TwoToOneCRHSchemeGadget as TwoToOneCRHGadgetTrait, + }, + sponge::{ + constraints::CryptographicSpongeVar, + poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig}, + Absorb, + }, }; -use crate::sponge::constraints::CryptographicSpongeVar; -use crate::sponge::poseidon::constraints::PoseidonSpongeVar; -use crate::sponge::poseidon::PoseidonConfig; - -use crate::sponge::Absorb; use ark_ff::PrimeField; -use ark_r1cs_std::alloc::{AllocVar, AllocationMode}; -use ark_r1cs_std::fields::fp::FpVar; -use ark_r1cs_std::R1CSVar; +use ark_r1cs_std::{ + alloc::{AllocVar, AllocationMode}, + fields::fp::FpVar, + R1CSVar, +}; use ark_relations::r1cs::{Namespace, SynthesisError}; -use ark_std::borrow::Borrow; -use ark_std::marker::PhantomData; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +use ark_std::{borrow::Borrow, marker::PhantomData}; #[derive(Clone)] pub struct CRHParametersVar { diff --git a/crypto-primitives/src/crh/poseidon/mod.rs b/crypto-primitives/src/crh/poseidon/mod.rs index 6c465012..4b24e8cd 100644 --- a/crypto-primitives/src/crh/poseidon/mod.rs +++ b/crypto-primitives/src/crh/poseidon/mod.rs @@ -1,11 +1,13 @@ -use crate::crh::TwoToOneCRHScheme; -use crate::sponge::poseidon::{PoseidonConfig, PoseidonSponge}; -use crate::sponge::{Absorb, CryptographicSponge}; -use crate::{crh::CRHScheme, Error}; +use crate::{ + crh::{CRHScheme, TwoToOneCRHScheme}, + sponge::{ + poseidon::{PoseidonConfig, PoseidonSponge}, + Absorb, CryptographicSponge, + }, + Error, +}; use ark_ff::PrimeField; -use ark_std::borrow::Borrow; -use ark_std::marker::PhantomData; -use ark_std::rand::Rng; +use ark_std::{borrow::Borrow, marker::PhantomData, rand::Rng}; #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/crh/sha256/constraints.rs b/crypto-primitives/src/crh/sha256/constraints.rs index c68c97fd..6bee0060 100644 --- a/crypto-primitives/src/crh/sha256/constraints.rs +++ b/crypto-primitives/src/crh/sha256/constraints.rs @@ -4,9 +4,6 @@ // Thank you! use crate::crh::{sha256::Sha256, CRHSchemeGadget, TwoToOneCRHSchemeGadget}; - -use core::{borrow::Borrow, iter, marker::PhantomData}; - use ark_ff::PrimeField; use ark_r1cs_std::{ alloc::{AllocVar, AllocationMode}, @@ -21,6 +18,7 @@ use ark_r1cs_std::{ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +use ark_std::{borrow::Borrow, iter, marker::PhantomData}; const STATE_LEN: usize = 8; diff --git a/crypto-primitives/src/crh/sha256/mod.rs b/crypto-primitives/src/crh/sha256/mod.rs index 16738d88..d07b36ab 100644 --- a/crypto-primitives/src/crh/sha256/mod.rs +++ b/crypto-primitives/src/crh/sha256/mod.rs @@ -1,9 +1,11 @@ -use crate::crh::{CRHScheme, TwoToOneCRHScheme}; -use crate::Error; - -use ark_std::rand::Rng; +use crate::{ + crh::{CRHScheme, TwoToOneCRHScheme}, + Error, +}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +use ark_std::{borrow::Borrow, rand::Rng}; +use sha2::digest::Digest; // Re-export the RustCrypto Sha256 type and its associated traits pub use sha2::{digest, Sha256}; @@ -12,10 +14,6 @@ pub use sha2::{digest, Sha256}; pub mod constraints; // Implement the CRH traits for SHA-256 - -use core::borrow::Borrow; -use sha2::digest::Digest; - impl CRHScheme for Sha256 { type Input = [u8]; // This is always 32 bytes. It has to be a Vec to impl CanonicalSerialize diff --git a/crypto-primitives/src/encryption/constraints.rs b/crypto-primitives/src/encryption/constraints.rs index de2a8f91..503f733a 100644 --- a/crypto-primitives/src/encryption/constraints.rs +++ b/crypto-primitives/src/encryption/constraints.rs @@ -1,10 +1,8 @@ use crate::encryption::AsymmetricEncryptionScheme; - +use ark_ff::fields::Field; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::SynthesisError; -use core::fmt::Debug; - -use ark_ff::fields::Field; +use ark_std::fmt::Debug; pub trait AsymmetricEncryptionGadget { type OutputVar: AllocVar diff --git a/crypto-primitives/src/encryption/elgamal/constraints.rs b/crypto-primitives/src/encryption/elgamal/constraints.rs index c5c3c21b..aa7b2a7f 100644 --- a/crypto-primitives/src/encryption/elgamal/constraints.rs +++ b/crypto-primitives/src/encryption/elgamal/constraints.rs @@ -1,15 +1,14 @@ -use ark_r1cs_std::prelude::*; -use ark_relations::r1cs::{Namespace, SynthesisError}; - -use crate::encryption::elgamal::{ - Ciphertext, ElGamal, Parameters, Plaintext, PublicKey, Randomness, +use crate::encryption::{ + elgamal::{Ciphertext, ElGamal, Parameters, Plaintext, PublicKey, Randomness}, + AsymmetricEncryptionGadget, }; -use crate::encryption::AsymmetricEncryptionGadget; use ark_ec::CurveGroup; use ark_ff::{ fields::{Field, PrimeField}, Zero, }; +use ark_r1cs_std::prelude::*; +use ark_relations::r1cs::{Namespace, SynthesisError}; use ark_serialize::CanonicalSerialize; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; diff --git a/crypto-primitives/src/encryption/elgamal/mod.rs b/crypto-primitives/src/encryption/elgamal/mod.rs index 2ffc9563..107710c7 100644 --- a/crypto-primitives/src/encryption/elgamal/mod.rs +++ b/crypto-primitives/src/encryption/elgamal/mod.rs @@ -1,13 +1,10 @@ -#[cfg(feature = "r1cs")] -pub mod constraints; - -use crate::encryption::AsymmetricEncryptionScheme; -use crate::Error; +use crate::{encryption::AsymmetricEncryptionScheme, Error}; use ark_ec::{AdditiveGroup, CurveGroup}; use ark_ff::{fields::PrimeField, UniformRand}; -use ark_std::marker::PhantomData; -use ark_std::ops::Mul; -use ark_std::rand::Rng; +use ark_std::{marker::PhantomData, ops::Mul, rand::Rng}; + +#[cfg(feature = "r1cs")] +pub mod constraints; pub struct ElGamal { _group: PhantomData, diff --git a/crypto-primitives/src/encryption/mod.rs b/crypto-primitives/src/encryption/mod.rs index d1213a76..5c721eb0 100644 --- a/crypto-primitives/src/encryption/mod.rs +++ b/crypto-primitives/src/encryption/mod.rs @@ -1,13 +1,12 @@ +use crate::Error; +use ark_std::rand::Rng; + #[cfg(feature = "r1cs")] pub mod constraints; +pub mod elgamal; #[cfg(feature = "r1cs")] pub use constraints::*; -pub mod elgamal; - -use crate::Error; -use ark_std::rand::Rng; - pub trait AsymmetricEncryptionScheme { type Parameters; type PublicKey; diff --git a/crypto-primitives/src/lib.rs b/crypto-primitives/src/lib.rs index 31ae920b..62d559b7 100644 --- a/crypto-primitives/src/lib.rs +++ b/crypto-primitives/src/lib.rs @@ -51,8 +51,8 @@ pub enum Error { SerializationError(ark_serialize::SerializationError), } -impl core::fmt::Display for Error { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { +impl ark_std::fmt::Display for Error { + fn fmt(&self, f: &mut ark_std::fmt::Formatter<'_>) -> ark_std::fmt::Result { match self { Self::IncorrectInputLength(len) => write!(f, "incorrect input length: {len}"), Self::NotPrimeOrder => write!(f, "element is not prime order"), diff --git a/crypto-primitives/src/merkle_tree/constraints.rs b/crypto-primitives/src/merkle_tree/constraints.rs index ccad3a93..9a23c34d 100644 --- a/crypto-primitives/src/merkle_tree/constraints.rs +++ b/crypto-primitives/src/merkle_tree/constraints.rs @@ -1,13 +1,13 @@ -use crate::crh::TwoToOneCRHSchemeGadget; -use crate::merkle_tree::Config; -use crate::{crh::CRHSchemeGadget, merkle_tree::Path}; +use crate::{ + crh::{CRHSchemeGadget, TwoToOneCRHSchemeGadget}, + merkle_tree::{Config, Path}, +}; use ark_ff::PrimeField; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{Namespace, SynthesisError}; -use ark_std::borrow::Borrow; -use ark_std::fmt::Debug; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +use ark_std::{borrow::Borrow, fmt::Debug}; #[cfg(test)] use crate::merkle_tree::IdentityDigestConverter; diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index efd46921..7dcabfa1 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -3,25 +3,24 @@ use core::hash::BuildHasherDefault; /// Defines a trait to chain two types of CRHs. -use crate::crh::TwoToOneCRHScheme; -use crate::sponge::Absorb; -use crate::{crh::CRHScheme, Error}; +use crate::{ + crh::{CRHScheme, TwoToOneCRHScheme}, + sponge::Absorb, + Error, +}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use ark_std::borrow::Borrow; -use ark_std::collections::BTreeSet; -use ark_std::hash::Hash; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; +use ark_std::{borrow::Borrow, collections::BTreeSet, fmt::Debug, hash::Hash}; use hashbrown::HashMap; - -#[cfg(test)] -mod tests; +#[cfg(feature = "parallel")] +use rayon::prelude::*; #[cfg(feature = "r1cs")] pub mod constraints; -#[cfg(feature = "parallel")] -use rayon::prelude::*; +#[cfg(test)] +mod tests; #[cfg(all( target_has_atomic = "8", @@ -85,7 +84,7 @@ pub trait Config { // leaf layer type LeafDigest: Clone + Eq - + core::fmt::Debug + + Debug + Hash + Default + CanonicalSerialize @@ -101,7 +100,7 @@ pub trait Config { // inner layer type InnerDigest: Clone + Eq - + core::fmt::Debug + + Debug + Hash + Default + CanonicalSerialize diff --git a/crypto-primitives/src/merkle_tree/tests/constraints.rs b/crypto-primitives/src/merkle_tree/tests/constraints.rs index 134e5092..ab55dc83 100644 --- a/crypto-primitives/src/merkle_tree/tests/constraints.rs +++ b/crypto-primitives/src/merkle_tree/tests/constraints.rs @@ -1,9 +1,11 @@ mod byte_mt_tests { - use crate::crh::{pedersen, TwoToOneCRHScheme, TwoToOneCRHSchemeGadget}; - - use crate::crh::{CRHScheme, CRHSchemeGadget}; - use crate::merkle_tree::constraints::{BytesVarDigestConverter, ConfigGadget}; - use crate::merkle_tree::{constraints::PathVar, ByteDigestConverter, Config, MerkleTree}; + use crate::crh::{ + pedersen, CRHScheme, CRHSchemeGadget, TwoToOneCRHScheme, TwoToOneCRHSchemeGadget, + }; + use crate::merkle_tree::{ + constraints::{BytesVarDigestConverter, ConfigGadget, PathVar}, + ByteDigestConverter, Config, MerkleTree, + }; use ark_ed_on_bls12_381::{constraints::EdwardsVar, EdwardsProjective as JubJub, Fq}; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::ConstraintSystem; @@ -234,13 +236,14 @@ mod byte_mt_tests { mod field_mt_tests { use crate::crh::{poseidon, CRHSchemeGadget, TwoToOneCRHSchemeGadget}; - use crate::merkle_tree::constraints::ConfigGadget; - use crate::merkle_tree::tests::test_utils::poseidon_parameters; - use crate::merkle_tree::{constraints::PathVar, Config, IdentityDigestConverter, MerkleTree}; - use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::uint32::UInt32; - use ark_r1cs_std::R1CSVar; - use ark_r1cs_std::{alloc::AllocVar, convert::ToBitsGadget}; + use crate::merkle_tree::{ + constraints::{ConfigGadget, PathVar}, + tests::test_utils::poseidon_parameters, + Config, IdentityDigestConverter, MerkleTree, + }; + use ark_r1cs_std::{ + alloc::AllocVar, convert::ToBitsGadget, fields::fp::FpVar, uint32::UInt32, R1CSVar, + }; use ark_relations::r1cs::ConstraintSystem; use ark_std::{test_rng, One, UniformRand}; diff --git a/crypto-primitives/src/merkle_tree/tests/mod.rs b/crypto-primitives/src/merkle_tree/tests/mod.rs index a2815f57..4f18d6eb 100644 --- a/crypto-primitives/src/merkle_tree/tests/mod.rs +++ b/crypto-primitives/src/merkle_tree/tests/mod.rs @@ -7,8 +7,7 @@ mod bytes_mt_tests { use crate::{crh::*, merkle_tree::*}; use ark_ed_on_bls12_381::EdwardsProjective as JubJub; use ark_ff::BigInteger256; - use ark_std::{test_rng, UniformRand}; - use std::iter::zip; + use ark_std::{iter::zip, test_rng, UniformRand}; #[derive(Clone)] pub(super) struct Window4x256; @@ -184,9 +183,12 @@ mod bytes_mt_tests { } mod field_mt_tests { - use crate::crh::poseidon; - use crate::merkle_tree::tests::test_utils::poseidon_parameters; - use crate::merkle_tree::{Config, IdentityDigestConverter, MerkleTree}; + use crate::{ + crh::poseidon, + merkle_tree::{ + tests::test_utils::poseidon_parameters, Config, IdentityDigestConverter, MerkleTree, + }, + }; use ark_std::{test_rng, One, UniformRand}; type F = ark_ed_on_bls12_381::Fr; diff --git a/crypto-primitives/src/merkle_tree/tests/test_utils.rs b/crypto-primitives/src/merkle_tree/tests/test_utils.rs index ef0795c6..9da40354 100644 --- a/crypto-primitives/src/merkle_tree/tests/test_utils.rs +++ b/crypto-primitives/src/merkle_tree/tests/test_utils.rs @@ -1,6 +1,5 @@ use crate::sponge::poseidon::PoseidonConfig; -use ark_std::str::FromStr; -use ark_std::{One, Zero}; +use ark_std::{str::FromStr, One, Zero}; type F = ark_ed_on_bls12_381::Fr; diff --git a/crypto-primitives/src/prf/blake2s/constraints.rs b/crypto-primitives/src/prf/blake2s/constraints.rs index cd9ea242..c0c180b9 100644 --- a/crypto-primitives/src/prf/blake2s/constraints.rs +++ b/crypto-primitives/src/prf/blake2s/constraints.rs @@ -1,13 +1,11 @@ -use ark_ff::PrimeField; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; - use crate::prf::PRFGadget; +use ark_ff::PrimeField; use ark_r1cs_std::prelude::*; +use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_std::borrow::Borrow; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; -use core::borrow::Borrow; - // 2.1. Parameters // The following table summarizes various parameters and their ranges: // | BLAKE2b | BLAKE2s | diff --git a/crypto-primitives/src/prf/blake2s/mod.rs b/crypto-primitives/src/prf/blake2s/mod.rs index 7dd10c9b..5addc754 100644 --- a/crypto-primitives/src/prf/blake2s/mod.rs +++ b/crypto-primitives/src/prf/blake2s/mod.rs @@ -1,11 +1,9 @@ +use crate::{prf::PRF, Error}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; use blake2::{Blake2s256 as B2s, Blake2sMac}; use digest::Digest; -use super::PRF; -use crate::Error; - #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/prf/constraints.rs b/crypto-primitives/src/prf/constraints.rs index 19fb0da6..2e64729d 100644 --- a/crypto-primitives/src/prf/constraints.rs +++ b/crypto-primitives/src/prf/constraints.rs @@ -1,10 +1,8 @@ -use ark_ff::Field; -use core::fmt::Debug; - use crate::prf::PRF; -use ark_relations::r1cs::{Namespace, SynthesisError}; - +use ark_ff::Field; use ark_r1cs_std::prelude::*; +use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_std::fmt::Debug; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; diff --git a/crypto-primitives/src/prf/mod.rs b/crypto-primitives/src/prf/mod.rs index fa3da3a4..5aef9297 100644 --- a/crypto-primitives/src/prf/mod.rs +++ b/crypto-primitives/src/prf/mod.rs @@ -1,8 +1,7 @@ #![allow(clippy::upper_case_acronyms)] -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use core::{fmt::Debug, hash::Hash}; - use crate::Error; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use ark_std::{fmt::Debug, hash::Hash}; #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/signature/constraints.rs b/crypto-primitives/src/signature/constraints.rs index a669c0ad..860a8efb 100644 --- a/crypto-primitives/src/signature/constraints.rs +++ b/crypto-primitives/src/signature/constraints.rs @@ -1,9 +1,8 @@ +use crate::signature::SignatureScheme; use ark_ff::Field; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::SynthesisError; -use crate::signature::SignatureScheme; - pub trait SigVerifyGadget { type ParametersVar: AllocVar + Clone; diff --git a/crypto-primitives/src/signature/mod.rs b/crypto-primitives/src/signature/mod.rs index 1f7cf219..577c6d73 100644 --- a/crypto-primitives/src/signature/mod.rs +++ b/crypto-primitives/src/signature/mod.rs @@ -1,7 +1,6 @@ use crate::Error; use ark_serialize::CanonicalSerialize; -use ark_std::hash::Hash; -use ark_std::rand::Rng; +use ark_std::{hash::Hash, rand::Rng}; #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/signature/schnorr/constraints.rs b/crypto-primitives/src/signature/schnorr/constraints.rs index 9198465f..f87089c3 100644 --- a/crypto-primitives/src/signature/schnorr/constraints.rs +++ b/crypto-primitives/src/signature/schnorr/constraints.rs @@ -1,15 +1,14 @@ +use crate::signature::{ + schnorr::{Parameters, PublicKey, Schnorr}, + SigRandomizePkGadget, +}; use ark_ec::CurveGroup; use ark_ff::Field; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{Namespace, SynthesisError}; - -use crate::signature::SigRandomizePkGadget; - #[cfg(not(feature = "std"))] use ark_std::vec::Vec; use ark_std::{borrow::Borrow, marker::PhantomData}; - -use crate::signature::schnorr::{Parameters, PublicKey, Schnorr}; use digest::Digest; type ConstraintF = <::BaseField as Field>::BasePrimeField; diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index bd7692f6..c27513f3 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -5,11 +5,9 @@ use ark_ff::{ AdditiveGroup, One, ToConstraintField, UniformRand, Zero, }; use ark_serialize::CanonicalSerialize; -use ark_std::ops::Mul; -use ark_std::rand::Rng; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; -use ark_std::{hash::Hash, marker::PhantomData}; +use ark_std::{hash::Hash, marker::PhantomData, ops::Mul, rand::Rng}; use digest::Digest; #[cfg(feature = "r1cs")] diff --git a/crypto-primitives/src/snark/constraints.rs b/crypto-primitives/src/snark/constraints.rs index fca144d2..ae4a39f0 100644 --- a/crypto-primitives/src/snark/constraints.rs +++ b/crypto-primitives/src/snark/constraints.rs @@ -1,17 +1,19 @@ use ark_ff::{BigInteger, PrimeField}; -use ark_r1cs_std::fields::{ - emulated_fp::{ - params::{get_params, OptimizationType}, - AllocatedEmulatedFpVar, EmulatedFpVar, +use ark_r1cs_std::{ + fields::{ + emulated_fp::{ + params::{get_params, OptimizationType}, + AllocatedEmulatedFpVar, EmulatedFpVar, + }, + fp::{AllocatedFp, FpVar}, }, - fp::{AllocatedFp, FpVar}, + prelude::*, }; -use ark_r1cs_std::prelude::*; -use ark_relations::r1cs::OptimizationGoal; use ark_relations::{ lc, ns, r1cs::{ - ConstraintSynthesizer, ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, + ConstraintSynthesizer, ConstraintSystemRef, LinearCombination, Namespace, OptimizationGoal, + SynthesisError, }, }; use ark_snark::{CircuitSpecificSetupSNARK, UniversalSetupSNARK, SNARK}; diff --git a/crypto-primitives/src/sponge/absorb.rs b/crypto-primitives/src/sponge/absorb.rs index 60d83e85..b00a61a1 100644 --- a/crypto-primitives/src/sponge/absorb.rs +++ b/crypto-primitives/src/sponge/absorb.rs @@ -1,17 +1,16 @@ -use ark_ec::short_weierstrass::Affine as SWAffine; -use ark_ec::twisted_edwards::Affine as TEAffine; +pub use ark_crypto_primitives_macros::*; use ark_ec::{ - short_weierstrass::SWCurveConfig as SWModelParameters, - twisted_edwards::TECurveConfig as TEModelParameters, + short_weierstrass::{Affine as SWAffine, SWCurveConfig as SWModelParameters}, + twisted_edwards::{Affine as TEAffine, TECurveConfig as TEModelParameters}, +}; +use ark_ff::{ + models::{Fp, FpConfig}, + BigInteger, Field, PrimeField, ToConstraintField, }; -use ark_ff::models::{Fp, FpConfig}; -use ark_ff::{BigInteger, Field, PrimeField, ToConstraintField}; use ark_serialize::CanonicalSerialize; #[cfg(not(feature = "std"))] use ark_std::{string::String, vec::Vec}; -pub use ark_crypto_primitives_macros::*; - /// An interface for objects that can be absorbed by a `CryptographicSponge`. pub trait Absorb { /// Converts the object into a list of bytes that can be absorbed by a `CryptographicSponge`. diff --git a/crypto-primitives/src/sponge/constraints/absorb.rs b/crypto-primitives/src/sponge/constraints/absorb.rs index 3abd7a20..5235f164 100644 --- a/crypto-primitives/src/sponge/constraints/absorb.rs +++ b/crypto-primitives/src/sponge/constraints/absorb.rs @@ -3,15 +3,16 @@ use ark_ec::{ twisted_edwards::TECurveConfig as TEModelParameters, CurveConfig as ModelParameters, }; use ark_ff::{Field, PrimeField}; -use ark_r1cs_std::boolean::Boolean; -use ark_r1cs_std::convert::{ToBytesGadget, ToConstraintFieldGadget}; -use ark_r1cs_std::fields::fp::FpVar; -use ark_r1cs_std::fields::{FieldOpsBounds, FieldVar}; -use ark_r1cs_std::groups::curves::short_weierstrass::{ - AffineVar as SWAffineVar, ProjectiveVar as SWProjectiveVar, +use ark_r1cs_std::{ + boolean::Boolean, + convert::{ToBytesGadget, ToConstraintFieldGadget}, + fields::{fp::FpVar, FieldOpsBounds, FieldVar}, + groups::curves::{ + short_weierstrass::{AffineVar as SWAffineVar, ProjectiveVar as SWProjectiveVar}, + twisted_edwards::AffineVar as TEAffineVar, + }, + uint8::UInt8, }; -use ark_r1cs_std::groups::curves::twisted_edwards::AffineVar as TEAffineVar; -use ark_r1cs_std::uint8::UInt8; use ark_relations::r1cs::SynthesisError; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; diff --git a/crypto-primitives/src/sponge/constraints/mod.rs b/crypto-primitives/src/sponge/constraints/mod.rs index aa872fe5..51acebb1 100644 --- a/crypto-primitives/src/sponge/constraints/mod.rs +++ b/crypto-primitives/src/sponge/constraints/mod.rs @@ -1,14 +1,22 @@ use crate::sponge::{Absorb, CryptographicSponge, FieldElementSize}; use ark_ff::PrimeField; -use ark_r1cs_std::alloc::AllocVar; -use ark_r1cs_std::boolean::Boolean; -use ark_r1cs_std::fields::emulated_fp::params::{get_params, OptimizationType}; -use ark_r1cs_std::fields::emulated_fp::{AllocatedEmulatedFpVar, EmulatedFpVar}; -use ark_r1cs_std::fields::fp::{AllocatedFp, FpVar}; -use ark_r1cs_std::uint8::UInt8; -use ark_r1cs_std::R1CSVar; -use ark_relations::lc; -use ark_relations::r1cs::{ConstraintSystemRef, LinearCombination, SynthesisError}; +use ark_r1cs_std::{ + alloc::AllocVar, + boolean::Boolean, + fields::{ + emulated_fp::{ + params::{get_params, OptimizationType}, + AllocatedEmulatedFpVar, EmulatedFpVar, + }, + fp::{AllocatedFp, FpVar}, + }, + uint8::UInt8, + R1CSVar, +}; +use ark_relations::{ + lc, + r1cs::{ConstraintSystemRef, LinearCombination, SynthesisError}, +}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; diff --git a/crypto-primitives/src/sponge/poseidon/constraints.rs b/crypto-primitives/src/sponge/poseidon/constraints.rs index c3023bad..60aa800b 100644 --- a/crypto-primitives/src/sponge/poseidon/constraints.rs +++ b/crypto-primitives/src/sponge/poseidon/constraints.rs @@ -1,11 +1,10 @@ -use crate::sponge::constraints::AbsorbGadget; -use crate::sponge::constraints::{CryptographicSpongeVar, SpongeWithGadget}; -use crate::sponge::poseidon::{PoseidonConfig, PoseidonSponge}; -use crate::sponge::DuplexSpongeMode; - +use crate::sponge::{ + constraints::{AbsorbGadget, CryptographicSpongeVar, SpongeWithGadget}, + poseidon::{PoseidonConfig, PoseidonSponge}, + DuplexSpongeMode, +}; use ark_ff::PrimeField; -use ark_r1cs_std::fields::fp::FpVar; -use ark_r1cs_std::prelude::*; +use ark_r1cs_std::{fields::fp::FpVar, prelude::*}; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec; diff --git a/crypto-primitives/src/sponge/poseidon/tests.rs b/crypto-primitives/src/sponge/poseidon/tests.rs index dd760d12..337caf7f 100644 --- a/crypto-primitives/src/sponge/poseidon/tests.rs +++ b/crypto-primitives/src/sponge/poseidon/tests.rs @@ -1,7 +1,11 @@ -use crate::sponge::poseidon::{PoseidonConfig, PoseidonDefaultConfigField, PoseidonSponge}; -use crate::sponge::test::Fr; -use crate::sponge::{Absorb, AbsorbWithLength, CryptographicSponge, FieldBasedCryptographicSponge}; -use crate::{absorb, collect_sponge_bytes, collect_sponge_field_elements}; +use crate::{ + absorb, collect_sponge_bytes, collect_sponge_field_elements, + sponge::{ + poseidon::{PoseidonConfig, PoseidonDefaultConfigField, PoseidonSponge}, + test::Fr, + Absorb, AbsorbWithLength, CryptographicSponge, FieldBasedCryptographicSponge, + }, +}; use ark_ff::{One, PrimeField, UniformRand}; use ark_std::test_rng; diff --git a/crypto-primitives/src/sponge/poseidon/traits.rs b/crypto-primitives/src/sponge/poseidon/traits.rs index c1c446e7..bfe10fed 100644 --- a/crypto-primitives/src/sponge/poseidon/traits.rs +++ b/crypto-primitives/src/sponge/poseidon/traits.rs @@ -1,5 +1,4 @@ -use crate::sponge::poseidon::grain_lfsr::PoseidonGrainLFSR; -use crate::sponge::poseidon::PoseidonConfig; +use crate::sponge::poseidon::{grain_lfsr::PoseidonGrainLFSR, PoseidonConfig}; use ark_ff::{fields::models::*, PrimeField}; #[cfg(not(feature = "std"))] use ark_std::vec::Vec;