From fb87c421e700bcb937347d4ad3125b315d833b43 Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Mon, 21 Oct 2019 14:18:35 +0300 Subject: [PATCH] Runs cargo fmt --- .../benches/crypto_primitives/comm.rs | 2 +- .../src/commitment/blake2s/constraints.rs | 27 ++++-- .../src/commitment/blake2s/mod.rs | 3 +- .../commitment/injective_map/constraints.rs | 9 +- crypto-primitives/src/commitment/mod.rs | 2 +- .../src/commitment/pedersen/constraints.rs | 38 +++++---- .../src/commitment/pedersen/mod.rs | 12 +-- .../src/crh/injective_map/constraints.rs | 31 +++++-- .../src/crh/injective_map/mod.rs | 4 +- crypto-primitives/src/crh/mod.rs | 2 - .../src/crh/pedersen/constraints.rs | 28 ++++--- crypto-primitives/src/crh/pedersen/mod.rs | 9 +- crypto-primitives/src/lib.rs | 12 +-- .../src/merkle_tree/constraints.rs | 83 ++++++++----------- crypto-primitives/src/merkle_tree/mod.rs | 47 ++++++----- crypto-primitives/src/nizk/constraints.rs | 3 +- .../src/nizk/gm17/constraints.rs | 19 ++--- crypto-primitives/src/nizk/gm17/mod.rs | 18 ++-- .../src/nizk/groth16/constraints.rs | 81 ++++++++---------- crypto-primitives/src/nizk/groth16/mod.rs | 18 ++-- .../src/prf/blake2s/constraints.rs | 18 ++-- crypto-primitives/src/prf/constraints.rs | 6 +- .../src/signature/constraints.rs | 5 +- crypto-primitives/src/signature/mod.rs | 5 +- .../src/signature/schnorr/constraints.rs | 31 ++++--- .../src/signature/schnorr/mod.rs | 11 +-- 26 files changed, 284 insertions(+), 240 deletions(-) diff --git a/crypto-primitives/benches/crypto_primitives/comm.rs b/crypto-primitives/benches/crypto_primitives/comm.rs index b82085e..8eb9d59 100644 --- a/crypto-primitives/benches/crypto_primitives/comm.rs +++ b/crypto-primitives/benches/crypto_primitives/comm.rs @@ -3,7 +3,7 @@ use rand; #[macro_use] extern crate criterion; -use algebra::{UniformRand, curves::edwards_bls12::EdwardsProjective as Edwards}; +use algebra::{curves::edwards_bls12::EdwardsProjective as Edwards, UniformRand}; use criterion::Criterion; use crypto_primitives::commitment::{pedersen::*, CommitmentScheme}; diff --git a/crypto-primitives/src/commitment/blake2s/constraints.rs b/crypto-primitives/src/commitment/blake2s/constraints.rs index 93e8413..c8327d1 100644 --- a/crypto-primitives/src/commitment/blake2s/constraints.rs +++ b/crypto-primitives/src/commitment/blake2s/constraints.rs @@ -5,7 +5,7 @@ use crate::{ prf::blake2s::constraints::{blake2s_gadget, Blake2sOutputGadget}, CommitmentGadget, }; -use algebra::{PrimeField, Field}; +use algebra::{Field, PrimeField}; use r1cs_std::prelude::*; use std::borrow::Borrow; @@ -18,7 +18,9 @@ pub struct Blake2sRandomnessGadget(pub Vec); pub struct Blake2sCommitmentGadget; -impl CommitmentGadget for Blake2sCommitmentGadget { +impl CommitmentGadget + for Blake2sCommitmentGadget +{ type OutputGadget = Blake2sOutputGadget; type ParametersGadget = Blake2sParametersGadget; type RandomnessGadget = Blake2sRandomnessGadget; @@ -54,7 +56,10 @@ impl AllocGadget<(), ConstraintF> for Blake2sParametersGadge Ok(Blake2sParametersGadget) } - fn alloc_input>(_: CS, _: F) -> Result + fn alloc_input>( + _: CS, + _: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow<()>, @@ -65,7 +70,10 @@ impl AllocGadget<(), ConstraintF> for Blake2sParametersGadge impl AllocGadget<[u8; 32], ConstraintF> for Blake2sRandomnessGadget { #[inline] - fn alloc>(cs: CS, value_gen: F) -> Result + fn alloc>( + cs: CS, + value_gen: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow<[u8; 32]>, @@ -105,14 +113,15 @@ mod test { use algebra::fields::bls12_381::Fr; use rand::{thread_rng, Rng}; - use crate::*; use crate::{ - commitment::blake2s::Blake2sCommitment, - commitment::blake2s::constraints::{Blake2sCommitmentGadget, Blake2sRandomnessGadget}, + commitment::blake2s::{ + constraints::{Blake2sCommitmentGadget, Blake2sRandomnessGadget}, + Blake2sCommitment, + }, + *, }; use r1cs_core::ConstraintSystem; - use r1cs_std::prelude::*; - use r1cs_std::test_constraint_system::TestConstraintSystem; + use r1cs_std::{prelude::*, test_constraint_system::TestConstraintSystem}; #[test] fn commitment_gadget_test() { diff --git a/crypto-primitives/src/commitment/blake2s/mod.rs b/crypto-primitives/src/commitment/blake2s/mod.rs index 2617d85..0b8104c 100644 --- a/crypto-primitives/src/commitment/blake2s/mod.rs +++ b/crypto-primitives/src/commitment/blake2s/mod.rs @@ -1,7 +1,7 @@ use super::CommitmentScheme; +use crate::Error; use blake2::Blake2s as b2s; use digest::Digest; -use crate::Error; use rand::Rng; pub struct Blake2sCommitment; @@ -9,7 +9,6 @@ pub struct Blake2sCommitment; #[cfg(feature = "r1cs")] pub mod constraints; - impl CommitmentScheme for Blake2sCommitment { type Parameters = (); type Randomness = [u8; 32]; diff --git a/crypto-primitives/src/commitment/injective_map/constraints.rs b/crypto-primitives/src/commitment/injective_map/constraints.rs index 53d9ff9..767f1cb 100644 --- a/crypto-primitives/src/commitment/injective_map/constraints.rs +++ b/crypto-primitives/src/commitment/injective_map/constraints.rs @@ -2,9 +2,11 @@ use algebra::{Field, PrimeField}; use crate::commitment::{ injective_map::{InjectiveMap, PedersenCommCompressor}, - pedersen::PedersenWindow, - pedersen::constraints::{ - PedersenCommitmentGadget, PedersenCommitmentGadgetParameters, PedersenRandomnessGadget, + pedersen::{ + constraints::{ + PedersenCommitmentGadget, PedersenCommitmentGadgetParameters, PedersenRandomnessGadget, + }, + PedersenWindow, }, CommitmentGadget, }; @@ -23,7 +25,6 @@ where ConstraintF: Field, GG: GroupGadget, IG: InjectiveMapGadget, - { _compressor: PhantomData, _compressor_gadget: PhantomData, diff --git a/crypto-primitives/src/commitment/mod.rs b/crypto-primitives/src/commitment/mod.rs index 2e1ff19..e925a1d 100644 --- a/crypto-primitives/src/commitment/mod.rs +++ b/crypto-primitives/src/commitment/mod.rs @@ -1,5 +1,5 @@ -use rand::Rng; use algebra::UniformRand; +use rand::Rng; use std::{fmt::Debug, hash::Hash}; use algebra::bytes::ToBytes; diff --git a/crypto-primitives/src/commitment/pedersen/constraints.rs b/crypto-primitives/src/commitment/pedersen/constraints.rs index b15e9ea..7fcc63b 100644 --- a/crypto-primitives/src/commitment/pedersen/constraints.rs +++ b/crypto-primitives/src/commitment/pedersen/constraints.rs @@ -13,9 +13,9 @@ use std::{borrow::Borrow, marker::PhantomData}; #[derive(Derivative)] #[derivative(Clone(bound = "G: Group, W: PedersenWindow, ConstraintF: Field"))] pub struct PedersenCommitmentGadgetParameters { - params: PedersenParameters, + params: PedersenParameters, #[doc(hidden)] - _group: PhantomData, + _group: PhantomData, #[doc(hidden)] _engine: PhantomData, #[doc(hidden)] @@ -26,10 +26,8 @@ pub struct PedersenCommitmentGadgetParameters); pub struct PedersenCommitmentGadget>( - #[doc(hidden)] - PhantomData<*const G>, - #[doc(hidden)] - PhantomData<*const GG>, + #[doc(hidden)] PhantomData<*const G>, + #[doc(hidden)] PhantomData<*const GG>, PhantomData, ); @@ -90,13 +88,17 @@ where } } -impl AllocGadget, ConstraintF> for PedersenCommitmentGadgetParameters +impl AllocGadget, ConstraintF> + for PedersenCommitmentGadgetParameters where G: Group, W: PedersenWindow, ConstraintF: PrimeField, { - fn alloc>(_cs: CS, value_gen: F) -> Result + fn alloc>( + _cs: CS, + value_gen: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow>, @@ -137,7 +139,10 @@ where G: Group, ConstraintF: PrimeField, { - fn alloc>(cs: CS, value_gen: F) -> Result + fn alloc>( + cs: CS, + value_gen: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow>, @@ -166,22 +171,25 @@ where #[cfg(test)] mod test { - use algebra::{fields::jubjub::{fq::Fq, fr::Fr}}; + use algebra::{ + fields::jubjub::{fq::Fq, fr::Fr}, + UniformRand, + }; use rand::thread_rng; - use algebra::UniformRand; use crate::{ commitment::{ - pedersen::{PedersenCommitment, PedersenRandomness, constraints::PedersenCommitmentGadget}, - CommitmentScheme, - CommitmentGadget, + pedersen::{ + constraints::PedersenCommitmentGadget, PedersenCommitment, PedersenRandomness, + }, + CommitmentGadget, CommitmentScheme, }, crh::pedersen::PedersenWindow, }; use algebra::curves::{jubjub::JubJubProjective as JubJub, ProjectiveCurve}; use r1cs_core::ConstraintSystem; use r1cs_std::{ - groups::jubjub::JubJubGadget, test_constraint_system::TestConstraintSystem, prelude::*, + groups::jubjub::JubJubGadget, prelude::*, test_constraint_system::TestConstraintSystem, }; #[test] diff --git a/crypto-primitives/src/commitment/pedersen/mod.rs b/crypto-primitives/src/commitment/pedersen/mod.rs index 4f63973..0be2fa4 100644 --- a/crypto-primitives/src/commitment/pedersen/mod.rs +++ b/crypto-primitives/src/commitment/pedersen/mod.rs @@ -1,7 +1,8 @@ use crate::Error; -use algebra::UniformRand; -use algebra::{Field, ToConstraintField}; -use algebra::{bytes::ToBytes, groups::Group, BitIterator, FpParameters, PrimeField}; +use algebra::{ + bytes::ToBytes, groups::Group, BitIterator, Field, FpParameters, PrimeField, ToConstraintField, + UniformRand, +}; use rand::Rng; use std::marker::PhantomData; @@ -124,8 +125,9 @@ impl CommitmentScheme for PedersenCommitment } } - -impl> ToConstraintField for PedersenParameters { +impl> ToConstraintField + for PedersenParameters +{ #[inline] fn to_field_elements(&self) -> Result, Error> { Ok(Vec::new()) diff --git a/crypto-primitives/src/crh/injective_map/constraints.rs b/crypto-primitives/src/crh/injective_map/constraints.rs index eb767dc..9319ef7 100644 --- a/crypto-primitives/src/crh/injective_map/constraints.rs +++ b/crypto-primitives/src/crh/injective_map/constraints.rs @@ -1,12 +1,12 @@ use std::{fmt::Debug, marker::PhantomData}; use crate::crh::{ - FixedLengthCRHGadget, injective_map::{InjectiveMap, PedersenCRHCompressor, TECompressor}, pedersen::{ - PedersenWindow, constraints::{PedersenCRHGadget, PedersenCRHGadgetParameters}, - } + PedersenWindow, + }, + FixedLengthCRHGadget, }; use algebra::{ @@ -24,7 +24,13 @@ use r1cs_std::{ prelude::*, }; -pub trait InjectiveMapGadget, ConstraintF: Field, GG: GroupGadget> { +pub trait InjectiveMapGadget< + G: Group, + I: InjectiveMap, + ConstraintF: Field, + GG: GroupGadget, +> +{ type OutputGadget: EqGadget + ToBytesGadget + CondSelectGadget @@ -41,8 +47,13 @@ pub trait InjectiveMapGadget, ConstraintF: Field, G pub struct TECompressorGadget; -impl InjectiveMapGadget, TECompressor, ConstraintF, TwistedEdwardsGadget>> - for TECompressorGadget +impl + InjectiveMapGadget< + TEAffine

, + TECompressor, + ConstraintF, + TwistedEdwardsGadget>, + > for TECompressorGadget where ConstraintF: PrimeField + SquareRootField, P: TEModelParameters + ModelParameters, @@ -58,8 +69,12 @@ where } impl - InjectiveMapGadget, TECompressor, ConstraintF, TwistedEdwardsGadget>> - for TECompressorGadget + InjectiveMapGadget< + TEProjective

, + TECompressor, + ConstraintF, + TwistedEdwardsGadget>, + > for TECompressorGadget where ConstraintF: PrimeField + SquareRootField, P: TEModelParameters + ModelParameters, diff --git a/crypto-primitives/src/crh/injective_map/mod.rs b/crypto-primitives/src/crh/injective_map/mod.rs index e4d4fc1..c4b9f89 100644 --- a/crypto-primitives/src/crh/injective_map/mod.rs +++ b/crypto-primitives/src/crh/injective_map/mod.rs @@ -1,6 +1,5 @@ -use crate::CryptoError; +use crate::{CryptoError, Error}; use algebra::bytes::ToBytes; -use crate::Error; use rand::Rng; use std::{fmt::Debug, hash::Hash, marker::PhantomData}; @@ -17,7 +16,6 @@ use algebra::{ groups::Group, }; - #[cfg(feature = "r1cs")] pub mod constraints; diff --git a/crypto-primitives/src/crh/mod.rs b/crypto-primitives/src/crh/mod.rs index 9a1d84d..4af4c6b 100644 --- a/crypto-primitives/src/crh/mod.rs +++ b/crypto-primitives/src/crh/mod.rs @@ -7,13 +7,11 @@ pub mod pedersen; use crate::Error; - #[cfg(feature = "r1cs")] pub mod constraints; #[cfg(feature = "r1cs")] pub use constraints::*; - pub trait FixedLengthCRH { const INPUT_SIZE_BITS: usize; type Output: ToBytes + Clone + Eq + Hash + Default; diff --git a/crypto-primitives/src/crh/pedersen/constraints.rs b/crypto-primitives/src/crh/pedersen/constraints.rs index 98d3e3e..27ce3f1 100644 --- a/crypto-primitives/src/crh/pedersen/constraints.rs +++ b/crypto-primitives/src/crh/pedersen/constraints.rs @@ -1,7 +1,6 @@ - use crate::crh::{ - FixedLengthCRHGadget, pedersen::{PedersenCRH, PedersenParameters, PedersenWindow}, + FixedLengthCRHGadget, }; use algebra::{Field, Group}; use r1cs_core::{ConstraintSystem, SynthesisError}; @@ -27,14 +26,15 @@ pub struct PedersenCRHGadgetParameters< pub struct PedersenCRHGadget> { #[doc(hideen)] - _group: PhantomData<*const G>, + _group: PhantomData<*const G>, #[doc(hideen)] _group_gadget: PhantomData<*const GG>, #[doc(hideen)] - _engine: PhantomData, + _engine: PhantomData, } -impl FixedLengthCRHGadget, ConstraintF> for PedersenCRHGadget +impl FixedLengthCRHGadget, ConstraintF> + for PedersenCRHGadget where ConstraintF: Field, G: Group, @@ -74,9 +74,13 @@ where } impl> - AllocGadget, ConstraintF> for PedersenCRHGadgetParameters + AllocGadget, ConstraintF> + for PedersenCRHGadgetParameters { - fn alloc>(_cs: CS, value_gen: F) -> Result + fn alloc>( + _cs: CS, + value_gen: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow>, @@ -114,16 +118,14 @@ mod test { use rand::{thread_rng, Rng}; use crate::crh::{ - pedersen::{PedersenCRH, PedersenWindow}, - pedersen::constraints::PedersenCRHGadget, - FixedLengthCRH, - FixedLengthCRHGadget + pedersen::{constraints::PedersenCRHGadget, PedersenCRH, PedersenWindow}, + FixedLengthCRH, FixedLengthCRHGadget, }; use algebra::curves::{jubjub::JubJubProjective as JubJub, ProjectiveCurve}; use r1cs_core::ConstraintSystem; use r1cs_std::{ - groups::curves::twisted_edwards::jubjub::JubJubGadget, - test_constraint_system::TestConstraintSystem, prelude::*, + groups::curves::twisted_edwards::jubjub::JubJubGadget, prelude::*, + test_constraint_system::TestConstraintSystem, }; type TestCRH = PedersenCRH; diff --git a/crypto-primitives/src/crh/pedersen/mod.rs b/crypto-primitives/src/crh/pedersen/mod.rs index 49a8f28..6dbc731 100644 --- a/crypto-primitives/src/crh/pedersen/mod.rs +++ b/crypto-primitives/src/crh/pedersen/mod.rs @@ -7,9 +7,7 @@ use std::{ }; use crate::crh::FixedLengthCRH; -use algebra::{Field, ToConstraintField}; -use algebra::groups::Group; - +use algebra::{groups::Group, Field, ToConstraintField}; #[cfg(feature = "r1cs")] pub mod constraints; @@ -141,8 +139,9 @@ impl Debug for PedersenParameters { } } - -impl> ToConstraintField for PedersenParameters { +impl> ToConstraintField + for PedersenParameters +{ #[inline] fn to_field_elements(&self) -> Result, Error> { Ok(Vec::new()) diff --git a/crypto-primitives/src/lib.rs b/crypto-primitives/src/lib.rs index b33aef6..0f3a467 100644 --- a/crypto-primitives/src/lib.rs +++ b/crypto-primitives/src/lib.rs @@ -14,7 +14,7 @@ pub mod signature; pub use self::{ commitment::CommitmentScheme, crh::FixedLengthCRH, - merkle_tree::{MerkleTreePath, MerkleHashTree}, + merkle_tree::{MerkleHashTree, MerkleTreePath}, nizk::NIZK, prf::PRF, signature::SignatureScheme, @@ -22,16 +22,12 @@ pub use self::{ #[cfg(feature = "r1cs")] pub use self::{ - commitment::CommitmentGadget, - crh::FixedLengthCRHGadget, - merkle_tree::constraints::MerkleTreePathGadget, - nizk::NIZKVerifierGadget, - prf::PRFGadget, + commitment::CommitmentGadget, crh::FixedLengthCRHGadget, + merkle_tree::constraints::MerkleTreePathGadget, nizk::NIZKVerifierGadget, prf::PRFGadget, signature::SigRandomizePkGadget, }; - -pub type Error = Box; +pub type Error = Box; #[derive(Debug)] pub enum CryptoError { diff --git a/crypto-primitives/src/merkle_tree/constraints.rs b/crypto-primitives/src/merkle_tree/constraints.rs index 16e40aa..462549d 100644 --- a/crypto-primitives/src/merkle_tree/constraints.rs +++ b/crypto-primitives/src/merkle_tree/constraints.rs @@ -1,10 +1,11 @@ use algebra::Field; use r1cs_core::{ConstraintSystem, SynthesisError}; -use r1cs_std::prelude::*; -use r1cs_std::boolean::AllocatedBit; +use r1cs_std::{boolean::AllocatedBit, prelude::*}; -use crate::merkle_tree::*; -use crate::crh::{FixedLengthCRH, FixedLengthCRHGadget}; +use crate::{ + crh::{FixedLengthCRH, FixedLengthCRHGadget}, + merkle_tree::*, +}; use std::borrow::Borrow; @@ -14,7 +15,7 @@ where HGadget: FixedLengthCRHGadget, ConstraintF: Field, { - path: Vec<(HGadget::OutputGadget, HGadget::OutputGadget)>, + path: Vec<(HGadget::OutputGadget, HGadget::OutputGadget)>, } impl MerkleTreePathGadget @@ -30,13 +31,7 @@ where root: &CRHGadget::OutputGadget, leaf: impl ToBytesGadget, ) -> Result<(), SynthesisError> { - self.conditionally_check_membership( - cs, - parameters, - root, - leaf, - &Boolean::Constant(true), - ) + self.conditionally_check_membership(cs, parameters, root, leaf, &Boolean::Constant(true)) } pub fn conditionally_check_membership>( @@ -153,9 +148,7 @@ where })?; path.push((l_hash, r_hash)); } - Ok(MerkleTreePathGadget { - path, - }) + Ok(MerkleTreePathGadget { path }) } fn alloc_input>( @@ -179,9 +172,7 @@ where path.push((l_hash, r_hash)); } - Ok(MerkleTreePathGadget { - path, - }) + Ok(MerkleTreePathGadget { path }) } } @@ -191,20 +182,15 @@ mod test { use crate::{ crh::{ - pedersen::{PedersenCRH, PedersenWindow}, - pedersen::constraints::PedersenCRHGadget, - FixedLengthCRH, - FixedLengthCRHGadget, + pedersen::{constraints::PedersenCRHGadget, PedersenCRH, PedersenWindow}, + FixedLengthCRH, FixedLengthCRHGadget, }, merkle_tree::*, }; - use algebra::{ - curves::jubjub::JubJubAffine as JubJub, - fields::jubjub::fq::Fq, - }; + use algebra::{curves::jubjub::JubJubAffine as JubJub, fields::jubjub::fq::Fq}; + use r1cs_core::ConstraintSystem; use rand::SeedableRng; use rand_xorshift::XorShiftRng; - use r1cs_core::ConstraintSystem; use super::*; use r1cs_std::{ @@ -223,7 +209,7 @@ mod test { type HG = PedersenCRHGadget; struct JubJubMerkleTreeParams; - + impl MerkleTreeConfig for JubJubMerkleTreeParams { const HEIGHT: usize = 32; type H = H; @@ -244,25 +230,27 @@ mod test { assert!(proof.verify(&crh_parameters, &root, &leaf).unwrap()); // Allocate Merkle Tree Root - let root = >::OutputGadget::alloc(&mut cs.ns(|| format!("new_digest_{}", i)), || { - if use_bad_root { - Ok(::Output::default()) - } else { - Ok(root) - } - }) + let root = >::OutputGadget::alloc( + &mut cs.ns(|| format!("new_digest_{}", i)), + || { + if use_bad_root { + Ok(::Output::default()) + } else { + Ok(root) + } + }, + ) .unwrap(); let constraints_from_digest = cs.num_constraints(); println!("constraints from digest: {}", constraints_from_digest); // Allocate Parameters for CRH - let crh_parameters = - >::ParametersGadget::alloc( - &mut cs.ns(|| format!("new_parameters_{}", i)), - || Ok(crh_parameters.clone()), - ) - .unwrap(); + let crh_parameters = >::ParametersGadget::alloc( + &mut cs.ns(|| format!("new_parameters_{}", i)), + || Ok(crh_parameters.clone()), + ) + .unwrap(); let constraints_from_parameters = cs.num_constraints() - constraints_from_digest; println!( @@ -272,15 +260,16 @@ mod test { // Allocate Leaf let leaf_g = UInt8::constant_vec(leaf); - + let constraints_from_leaf = cs.num_constraints() - constraints_from_parameters - constraints_from_digest; println!("constraints from leaf: {}", constraints_from_leaf); // Allocate Merkle Tree Path - let cw = MerkleTreePathGadget::<_, HG, _>::alloc(&mut cs.ns(|| format!("new_witness_{}", i)), || { - Ok(proof) - }) + let cw = MerkleTreePathGadget::<_, HG, _>::alloc( + &mut cs.ns(|| format!("new_witness_{}", i)), + || Ok(proof), + ) .unwrap(); let constraints_from_path = cs.num_constraints() @@ -320,7 +309,7 @@ mod test { fn good_root_test() { let mut leaves = Vec::new(); for i in 0..4u8 { - let input = [i ; 30]; + let input = [i; 30]; leaves.push(input); } generate_merkle_tree(&leaves, false); @@ -331,7 +320,7 @@ mod test { fn bad_root_test() { let mut leaves = Vec::new(); for i in 0..4u8 { - let input = [i ; 30]; + let input = [i; 30]; leaves.push(input); } generate_merkle_tree(&leaves, true); diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 5cce751..96eeeb4 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -1,9 +1,7 @@ -use crate::crh::FixedLengthCRH; +use crate::{crh::FixedLengthCRH, Error}; use algebra::bytes::ToBytes; -use crate::Error; use std::{fmt, rc::Rc}; - #[cfg(feature = "r1cs")] pub mod constraints; @@ -20,22 +18,25 @@ pub trait MerkleTreeConfig { Debug(bound = "P: MerkleTreeConfig, ::Output: fmt::Debug") )] pub struct MerkleTreePath { - pub(crate) path: Vec<(::Output, ::Output)>, + pub(crate) path: Vec<( + ::Output, + ::Output, + )>, } pub type MerkleTreeParams

= <

::H as FixedLengthCRH>::Parameters; pub type MerkleTreeDigest

= <

::H as FixedLengthCRH>::Output; - impl Default for MerkleTreePath

{ fn default() -> Self { let mut path = Vec::with_capacity(P::HEIGHT as usize); for _i in 1..P::HEIGHT as usize { - path.push((::Output::default(), ::Output::default())); - } - Self { - path, + path.push(( + ::Output::default(), + ::Output::default(), + )); } + Self { path } } } @@ -82,7 +83,10 @@ impl MerkleTreePath

{ pub struct MerkleHashTree { tree: Vec<::Output>, - padding_tree: Vec<(::Output, ::Output)>, + padding_tree: Vec<( + ::Output, + ::Output, + )>, parameters: Rc<::Parameters>, root: Option<::Output>, } @@ -99,7 +103,10 @@ impl MerkleHashTree

{ } } - pub fn new(parameters: Rc<::Parameters>, leaves: &[L]) -> Result { + pub fn new( + parameters: Rc<::Parameters>, + leaves: &[L], + ) -> Result { let new_time = start_timer!(|| "MerkleTree::New"); let last_level_size = leaves.len().next_power_of_two(); @@ -225,9 +232,7 @@ impl MerkleHashTree

{ if path.len() != (Self::HEIGHT - 1) as usize { Err(MerkleTreeError::IncorrectPathLength(path.len()))? } else { - Ok(MerkleTreePath { - path, - }) + Ok(MerkleTreePath { path }) } } } @@ -241,7 +246,9 @@ pub enum MerkleTreeError { impl std::fmt::Display for MerkleTreeError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let msg = match self { - MerkleTreeError::IncorrectLeafIndex(index) => format!("incorrect leaf index: {}", index), + MerkleTreeError::IncorrectLeafIndex(index) => { + format!("incorrect leaf index: {}", index) + }, MerkleTreeError::IncorrectPathLength(len) => format!("incorrect path length: {}", len), }; write!(f, "{}", msg) @@ -358,10 +365,12 @@ pub(crate) fn hash_empty( H::evaluate(parameters, &empty_buffer) } - #[cfg(test)] mod test { - use crate::{crh::{pedersen::*, *}, merkle_tree::*}; + use crate::{ + crh::{pedersen::*, *}, + merkle_tree::*, + }; use algebra::curves::jubjub::JubJubAffine as JubJub; use rand::SeedableRng; use rand_xorshift::XorShiftRng; @@ -373,18 +382,16 @@ mod test { const NUM_WINDOWS: usize = 256; } - type H = PedersenCRH; struct JubJubMerkleTreeParams; - + impl MerkleTreeConfig for JubJubMerkleTreeParams { const HEIGHT: usize = 32; type H = H; } type JubJubMerkleTree = MerkleHashTree; - fn generate_merkle_tree(leaves: &[L]) -> () { let mut rng = XorShiftRng::seed_from_u64(9174123u64); diff --git a/crypto-primitives/src/nizk/constraints.rs b/crypto-primitives/src/nizk/constraints.rs index 92d6925..fd77fd6 100644 --- a/crypto-primitives/src/nizk/constraints.rs +++ b/crypto-primitives/src/nizk/constraints.rs @@ -5,7 +5,8 @@ use r1cs_std::prelude::*; use crate::nizk::NIZK; pub trait NIZKVerifierGadget { - type VerificationKeyGadget: AllocGadget + ToBytesGadget; + type VerificationKeyGadget: AllocGadget + + ToBytesGadget; type ProofGadget: AllocGadget; diff --git a/crypto-primitives/src/nizk/gm17/constraints.rs b/crypto-primitives/src/nizk/gm17/constraints.rs index 3ad2002..fbcc1ff 100644 --- a/crypto-primitives/src/nizk/gm17/constraints.rs +++ b/crypto-primitives/src/nizk/gm17/constraints.rs @@ -1,5 +1,5 @@ use crate::nizk::{gm17::Gm17, NIZKVerifierGadget}; -use algebra::{Field, ToConstraintField, AffineCurve, PairingEngine}; +use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField}; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; use r1cs_std::prelude::*; @@ -36,11 +36,8 @@ pub struct VerifyingKeyGadget< pub query: Vec, } -impl< - PairingE: PairingEngine, - ConstraintF: Field, - P: PairingGadget, - > VerifyingKeyGadget +impl> + VerifyingKeyGadget { pub fn prepare>( &self, @@ -408,15 +405,14 @@ mod test { use super::*; use algebra::{ curves::bls12_377::Bls12_377, - fields::bls12_377::Fr, - fields::bls12_377::Fq, + fields::bls12_377::{Fq, Fr}, BitIterator, PrimeField, }; - use rand::{thread_rng, Rng}; use r1cs_std::{ boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget, test_constraint_system::TestConstraintSystem, }; + use rand::{thread_rng, Rng}; type TestProofSystem = Gm17, Fr>; type TestVerifierGadget = Gm17VerifierGadget; @@ -429,7 +425,10 @@ mod test { } impl ConstraintSynthesizer for Bench { - fn generate_constraints>(self, cs: &mut CS) -> Result<(), SynthesisError> { + fn generate_constraints>( + self, + cs: &mut CS, + ) -> Result<(), SynthesisError> { assert!(self.inputs.len() >= 2); assert!(self.num_constraints >= self.inputs.len()); diff --git a/crypto-primitives/src/nizk/gm17/mod.rs b/crypto-primitives/src/nizk/gm17/mod.rs index 32126b1..26790d0 100644 --- a/crypto-primitives/src/nizk/gm17/mod.rs +++ b/crypto-primitives/src/nizk/gm17/mod.rs @@ -1,11 +1,11 @@ -use algebra::PairingEngine; use crate::Error; -use rand::Rng; +use algebra::PairingEngine; use gm17::{ create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, Parameters, PreparedVerifyingKey, Proof, VerifyingKey, }; use r1cs_core::ConstraintSynthesizer; +use rand::Rng; use algebra::ToConstraintField; use std::marker::PhantomData; @@ -17,16 +17,22 @@ pub mod constraints; /// Note: V should serialize its contents to `Vec` in the same order as /// during the constraint generation. -pub struct Gm17, V: ToConstraintField + ?Sized> { +pub struct Gm17< + E: PairingEngine, + C: ConstraintSynthesizer, + V: ToConstraintField + ?Sized, +> { #[doc(hidden)] - _engine: PhantomData, + _engine: PhantomData, #[doc(hidden)] - _circuit: PhantomData, + _circuit: PhantomData, #[doc(hidden)] _verifier_input: PhantomData, } -impl, V: ToConstraintField + ?Sized> NIZK for Gm17 { +impl, V: ToConstraintField + ?Sized> NIZK + for Gm17 +{ type Circuit = C; type AssignedCircuit = C; type ProvingParameters = Parameters; diff --git a/crypto-primitives/src/nizk/groth16/constraints.rs b/crypto-primitives/src/nizk/groth16/constraints.rs index c740fd4..be0f0da 100644 --- a/crypto-primitives/src/nizk/groth16/constraints.rs +++ b/crypto-primitives/src/nizk/groth16/constraints.rs @@ -1,5 +1,5 @@ use crate::nizk::{groth16::Groth16, NIZKVerifierGadget}; -use algebra::{Field, ToConstraintField, AffineCurve, PairingEngine}; +use algebra::{AffineCurve, Field, PairingEngine, ToConstraintField}; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; use r1cs_std::prelude::*; @@ -28,18 +28,15 @@ pub struct VerifyingKeyGadget< ConstraintF: Field, P: PairingGadget, > { - pub alpha_g1: P::G1Gadget, - pub beta_g2: P::G2Gadget, - pub gamma_g2: P::G2Gadget, - pub delta_g2: P::G2Gadget, - pub gamma_abc_g1: Vec, + pub alpha_g1: P::G1Gadget, + pub beta_g2: P::G2Gadget, + pub gamma_g2: P::G2Gadget, + pub delta_g2: P::G2Gadget, + pub gamma_abc_g1: Vec, } -impl< - PairingE: PairingEngine, - ConstraintF: Field, - P: PairingGadget, - > VerifyingKeyGadget +impl> + VerifyingKeyGadget { pub fn prepare>( &self, @@ -49,7 +46,11 @@ impl< let alpha_g1_pc = P::prepare_g1(&mut cs.ns(|| "Prepare alpha_g1"), &self.alpha_g1)?; let beta_g2_pc = P::prepare_g2(&mut cs.ns(|| "Prepare beta_g2"), &self.beta_g2)?; - let alpha_g1_beta_g2 = P::pairing(&mut cs.ns(|| "Precompute e(alpha_g1, beta_g2)"), alpha_g1_pc, beta_g2_pc)?; + let alpha_g1_beta_g2 = P::pairing( + &mut cs.ns(|| "Precompute e(alpha_g1, beta_g2)"), + alpha_g1_pc, + beta_g2_pc, + )?; let gamma_g2_neg = self.gamma_g2.negate(&mut cs.ns(|| "Negate gamma_g2"))?; let gamma_g2_neg_pc = P::prepare_g2(&mut cs.ns(|| "Prepare gamma_g2_neg"), &gamma_g2_neg)?; @@ -58,10 +59,10 @@ impl< let delta_g2_neg_pc = P::prepare_g2(&mut cs.ns(|| "Prepare delta_g2_neg"), &delta_g2_neg)?; Ok(PreparedVerifyingKeyGadget { - alpha_g1_beta_g2: alpha_g1_beta_g2, - gamma_g2_neg_pc: gamma_g2_neg_pc, - delta_g2_neg_pc: delta_g2_neg_pc, - gamma_abc_g1: self.gamma_abc_g1.clone(), + alpha_g1_beta_g2, + gamma_g2_neg_pc, + delta_g2_neg_pc, + gamma_abc_g1: self.gamma_abc_g1.clone(), }) } } @@ -76,10 +77,10 @@ pub struct PreparedVerifyingKeyGadget< ConstraintF: Field, P: PairingGadget, > { - pub alpha_g1_beta_g2: P::GTGadget, - pub gamma_g2_neg_pc: P::G2PreparedGadget, - pub delta_g2_neg_pc: P::G2PreparedGadget, - pub gamma_abc_g1: Vec, + pub alpha_g1_beta_g2: P::GTGadget, + pub gamma_g2_neg_pc: P::G2PreparedGadget, + pub delta_g2_neg_pc: P::G2PreparedGadget, + pub gamma_abc_g1: Vec, } pub struct Groth16VerifierGadget @@ -146,11 +147,7 @@ where P::miller_loop( cs.ns(|| "Miller loop 1"), - &[ - proof_a_prep, - g_ic_prep, - proof_c_prep, - ], + &[proof_a_prep, g_ic_prep, proof_c_prep], &[ proof_b_prep, pvk.gamma_g2_neg_pc.clone(), @@ -190,7 +187,8 @@ where delta_g2, gamma_abc_g1, } = vk.borrow().clone(); - let alpha_g1 = P::G1Gadget::alloc(cs.ns(|| "alpha_g1"), || Ok(alpha_g1.into_projective()))?; + let alpha_g1 = + P::G1Gadget::alloc(cs.ns(|| "alpha_g1"), || Ok(alpha_g1.into_projective()))?; let beta_g2 = P::G2Gadget::alloc(cs.ns(|| "beta_g2"), || Ok(beta_g2.into_projective()))?; let gamma_g2 = @@ -236,7 +234,8 @@ where delta_g2, gamma_abc_g1, } = vk.borrow().clone(); - let alpha_g1 = P::G1Gadget::alloc_input(cs.ns(|| "alpha_g1"), || Ok(alpha_g1.into_projective()))?; + let alpha_g1 = + P::G1Gadget::alloc_input(cs.ns(|| "alpha_g1"), || Ok(alpha_g1.into_projective()))?; let beta_g2 = P::G2Gadget::alloc_input(cs.ns(|| "beta_g2"), || Ok(beta_g2.into_projective()))?; let gamma_g2 = @@ -327,21 +326,9 @@ where ) -> Result, SynthesisError> { let mut bytes = Vec::new(); bytes.extend_from_slice(&self.alpha_g1.to_bytes(&mut cs.ns(|| "alpha_g1 to bytes"))?); - bytes.extend_from_slice( - &self - .beta_g2 - .to_bytes(&mut cs.ns(|| "beta_g2 to bytes"))?, - ); - bytes.extend_from_slice( - &self - .gamma_g2 - .to_bytes(&mut cs.ns(|| "gamma_g2 to bytes"))?, - ); - bytes.extend_from_slice( - &self - .delta_g2 - .to_bytes(&mut cs.ns(|| "delta_g2 to bytes"))?, - ); + bytes.extend_from_slice(&self.beta_g2.to_bytes(&mut cs.ns(|| "beta_g2 to bytes"))?); + bytes.extend_from_slice(&self.gamma_g2.to_bytes(&mut cs.ns(|| "gamma_g2 to bytes"))?); + bytes.extend_from_slice(&self.delta_g2.to_bytes(&mut cs.ns(|| "delta_g2 to bytes"))?); for (i, g) in self.gamma_abc_g1.iter().enumerate() { let mut cs = cs.ns(|| format!("Iteration {}", i)); bytes.extend_from_slice(&g.to_bytes(&mut cs.ns(|| "g"))?); @@ -365,15 +352,14 @@ mod test { use super::*; use algebra::{ curves::bls12_377::Bls12_377, - fields::bls12_377::Fr, - fields::bls12_377::Fq, + fields::bls12_377::{Fq, Fr}, BitIterator, PrimeField, }; - use rand::{thread_rng, Rng}; use r1cs_std::{ boolean::Boolean, pairing::bls12_377::PairingGadget as Bls12_377PairingGadget, test_constraint_system::TestConstraintSystem, }; + use rand::{thread_rng, Rng}; type TestProofSystem = Groth16, Fr>; type TestVerifierGadget = Groth16VerifierGadget; @@ -386,7 +372,10 @@ mod test { } impl ConstraintSynthesizer for Bench { - fn generate_constraints>(self, cs: &mut CS) -> Result<(), SynthesisError> { + fn generate_constraints>( + self, + cs: &mut CS, + ) -> Result<(), SynthesisError> { assert!(self.inputs.len() >= 2); assert!(self.num_constraints >= self.inputs.len()); diff --git a/crypto-primitives/src/nizk/groth16/mod.rs b/crypto-primitives/src/nizk/groth16/mod.rs index 09d5577..5e55f2f 100644 --- a/crypto-primitives/src/nizk/groth16/mod.rs +++ b/crypto-primitives/src/nizk/groth16/mod.rs @@ -1,11 +1,11 @@ -use algebra::PairingEngine; use crate::Error; -use rand::Rng; +use algebra::PairingEngine; use groth16::{ create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, Parameters, PreparedVerifyingKey, Proof, VerifyingKey, }; use r1cs_core::ConstraintSynthesizer; +use rand::Rng; use algebra::ToConstraintField; use std::marker::PhantomData; @@ -17,16 +17,22 @@ pub mod constraints; /// Note: V should serialize its contents to `Vec` in the same order as /// during the constraint generation. -pub struct Groth16, V: ToConstraintField + ?Sized> { +pub struct Groth16< + E: PairingEngine, + C: ConstraintSynthesizer, + V: ToConstraintField + ?Sized, +> { #[doc(hidden)] - _engine: PhantomData, + _engine: PhantomData, #[doc(hidden)] - _circuit: PhantomData, + _circuit: PhantomData, #[doc(hidden)] _verifier_input: PhantomData, } -impl, V: ToConstraintField + ?Sized> NIZK for Groth16 { +impl, V: ToConstraintField + ?Sized> NIZK + for Groth16 +{ type Circuit = C; type AssignedCircuit = C; type ProvingParameters = Parameters; diff --git a/crypto-primitives/src/prf/blake2s/constraints.rs b/crypto-primitives/src/prf/blake2s/constraints.rs index e33c686..af5df21 100644 --- a/crypto-primitives/src/prf/blake2s/constraints.rs +++ b/crypto-primitives/src/prf/blake2s/constraints.rs @@ -411,7 +411,10 @@ impl ConditionalEqGadget for Blake2sOutput impl ToBytesGadget for Blake2sOutputGadget { #[inline] - fn to_bytes>(&self, _cs: CS) -> Result, SynthesisError> { + fn to_bytes>( + &self, + _cs: CS, + ) -> Result, SynthesisError> { Ok(self.0.clone()) } @@ -426,7 +429,10 @@ impl ToBytesGadget for Blake2sOutputGadget impl AllocGadget<[u8; 32], ConstraintF> for Blake2sOutputGadget { #[inline] - fn alloc>(cs: CS, value_gen: F) -> Result + fn alloc>( + cs: CS, + value_gen: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow<[u8; 32]>, @@ -498,12 +504,14 @@ mod test { use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; - use crate::prf::blake2s::{Blake2s as B2SPRF, constraints::blake2s_gadget}; + use crate::prf::blake2s::{constraints::blake2s_gadget, Blake2s as B2SPRF}; use blake2::Blake2s; use r1cs_core::ConstraintSystem; use super::Blake2sGadget; - use r1cs_std::{prelude::*, boolean::AllocatedBit, test_constraint_system::TestConstraintSystem}; + use r1cs_std::{ + boolean::AllocatedBit, prelude::*, test_constraint_system::TestConstraintSystem, + }; #[test] fn test_blake2s_constraints() { @@ -522,7 +530,7 @@ mod test { #[test] fn test_blake2s_prf() { - use crate::prf::{PRF, PRFGadget}; + use crate::prf::{PRFGadget, PRF}; use rand::Rng; let mut rng = XorShiftRng::seed_from_u64(1231275789u64); diff --git a/crypto-primitives/src/prf/constraints.rs b/crypto-primitives/src/prf/constraints.rs index 6f8bdef..ca61edc 100644 --- a/crypto-primitives/src/prf/constraints.rs +++ b/crypto-primitives/src/prf/constraints.rs @@ -7,7 +7,11 @@ use r1cs_core::{ConstraintSystem, SynthesisError}; use r1cs_std::prelude::*; pub trait PRFGadget { - type OutputGadget: EqGadget + ToBytesGadget + AllocGadget + Clone + Debug; + type OutputGadget: EqGadget + + ToBytesGadget + + AllocGadget + + Clone + + Debug; fn new_seed>(cs: CS, output: &P::Seed) -> Vec; diff --git a/crypto-primitives/src/signature/constraints.rs b/crypto-primitives/src/signature/constraints.rs index e98a713..8c0c264 100644 --- a/crypto-primitives/src/signature/constraints.rs +++ b/crypto-primitives/src/signature/constraints.rs @@ -7,7 +7,10 @@ use crate::signature::SignatureScheme; pub trait SigRandomizePkGadget { type ParametersGadget: AllocGadget + Clone; - type PublicKeyGadget: ToBytesGadget + EqGadget + AllocGadget + Clone; + type PublicKeyGadget: ToBytesGadget + + EqGadget + + AllocGadget + + Clone; fn check_randomization_gadget>( cs: CS, diff --git a/crypto-primitives/src/signature/mod.rs b/crypto-primitives/src/signature/mod.rs index dae68f2..546ef13 100644 --- a/crypto-primitives/src/signature/mod.rs +++ b/crypto-primitives/src/signature/mod.rs @@ -1,5 +1,5 @@ -use algebra::bytes::ToBytes; use crate::Error; +use algebra::bytes::ToBytes; use rand::Rng; use std::hash::Hash; @@ -8,7 +8,6 @@ pub mod constraints; #[cfg(feature = "r1cs")] pub use constraints::*; - pub mod schnorr; pub trait SignatureScheme { @@ -56,10 +55,10 @@ mod test { use crate::{signature::schnorr::SchnorrSignature, SignatureScheme}; use algebra::{ curves::edwards_sw6::EdwardsAffine as Edwards, groups::Group, to_bytes, ToBytes, + UniformRand, }; use blake2::Blake2s; use rand::thread_rng; - use algebra::UniformRand; fn sign_and_verify(message: &[u8]) { let rng = &mut thread_rng(); diff --git a/crypto-primitives/src/signature/schnorr/constraints.rs b/crypto-primitives/src/signature/schnorr/constraints.rs index f9fcbd0..59830f9 100644 --- a/crypto-primitives/src/signature/schnorr/constraints.rs +++ b/crypto-primitives/src/signature/schnorr/constraints.rs @@ -6,12 +6,11 @@ use crate::signature::SigRandomizePkGadget; use std::{borrow::Borrow, marker::PhantomData}; -use crate::signature::schnorr::{ - SchnorrPublicKey, SchnorrSigParameters, SchnorrSignature, -}; +use crate::signature::schnorr::{SchnorrPublicKey, SchnorrSigParameters, SchnorrSignature}; use digest::Digest; -pub struct SchnorrSigGadgetParameters> { +pub struct SchnorrSigGadgetParameters> +{ generator: GG, _group: PhantomData<*const G>, _engine: PhantomData<*const ConstraintF>, @@ -39,18 +38,18 @@ impl> Clone pub struct SchnorrSigGadgetPk> { pub_key: GG, #[doc(hidden)] - _group: PhantomData<*const G>, + _group: PhantomData<*const G>, #[doc(hidden)] _engine: PhantomData<*const ConstraintF>, } pub struct SchnorrRandomizePkGadget> { #[doc(hidden)] - _group: PhantomData<*const G>, + _group: PhantomData<*const G>, #[doc(hidden)] _group_gadget: PhantomData<*const GG>, #[doc(hidden)] - _engine: PhantomData<*const ConstraintF>, + _engine: PhantomData<*const ConstraintF>, } impl SigRandomizePkGadget, ConstraintF> @@ -109,7 +108,10 @@ where }) } - fn alloc_input>(cs: CS, f: F) -> Result + fn alloc_input>( + cs: CS, + f: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow>, @@ -123,7 +125,8 @@ where } } -impl AllocGadget, ConstraintF> for SchnorrSigGadgetPk +impl AllocGadget, ConstraintF> + for SchnorrSigGadgetPk where G: Group, ConstraintF: Field, @@ -142,7 +145,10 @@ where }) } - fn alloc_input>(cs: CS, f: F) -> Result + fn alloc_input>( + cs: CS, + f: F, + ) -> Result where F: FnOnce() -> Result, T: Borrow>, @@ -196,7 +202,10 @@ where ConstraintF: Field, GG: GroupGadget, { - fn to_bytes>(&self, mut cs: CS) -> Result, SynthesisError> { + fn to_bytes>( + &self, + mut cs: CS, + ) -> Result, SynthesisError> { self.pub_key.to_bytes(&mut cs.ns(|| "PubKey To Bytes")) } diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index 36a96e4..29a8c25 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -1,14 +1,11 @@ -use crate::SignatureScheme; +use crate::{Error, SignatureScheme}; use algebra::{ - ToConstraintField, bytes::ToBytes, fields::{Field, PrimeField}, groups::Group, - to_bytes, + to_bytes, ToConstraintField, UniformRand, }; use digest::Digest; -use crate::Error; -use algebra::UniformRand; use rand::Rng; use std::{ hash::Hash, @@ -223,8 +220,8 @@ pub fn bytes_to_bits(bytes: &[u8]) -> Vec { bits } -impl, D: Digest> ToConstraintField - for SchnorrSigParameters +impl, D: Digest> + ToConstraintField for SchnorrSigParameters { #[inline] fn to_field_elements(&self) -> Result, Error> {