diff --git a/.hooks/pre-commit b/.hooks/pre-commit index b8a7c30..8d4d19f 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -13,7 +13,7 @@ problem_files=() # collect ill-formatted files for file in $(git diff --name-only --cached); do if [ ${file: -3} == ".rs" ]; then - rustfmt +nightly --check $file &>/dev/null + rustfmt +stable --check $file &>/dev/null if [ $? != 0 ]; then problem_files+=($file) fi @@ -27,7 +27,7 @@ else # reformat the files that need it and re-stage them. printf "[pre_commit] the following files were rustfmt'd before commit: \n" for file in ${problem_files[@]}; do - rustfmt $file + rustfmt +stable $file git add $file printf "\033[0;32m $file\033[0m \n" done diff --git a/cp-benches/benches/crypto_primitives/nizk.rs b/cp-benches/benches/crypto_primitives/nizk.rs index ac68acd..991a405 100644 --- a/cp-benches/benches/crypto_primitives/nizk.rs +++ b/cp-benches/benches/crypto_primitives/nizk.rs @@ -11,7 +11,7 @@ use rand::{thread_rng, Rng}; type TestProofSystem = Gm17, Fr>; struct Bench { - inputs: Vec>, + inputs: Vec>, num_constraints: usize, } diff --git a/crypto-primitives/src/commitment/injective_map/constraints.rs b/crypto-primitives/src/commitment/injective_map/constraints.rs index 91c30a2..2afe0bc 100644 --- a/crypto-primitives/src/commitment/injective_map/constraints.rs +++ b/crypto-primitives/src/commitment/injective_map/constraints.rs @@ -26,9 +26,9 @@ where GG: GroupGadget, IG: InjectiveMapGadget, { - _compressor: PhantomData, + _compressor: PhantomData, _compressor_gadget: PhantomData, - _crh: PedersenCommitmentGadget, + _crh: PedersenCommitmentGadget, } impl CommitmentGadget, ConstraintF> diff --git a/crypto-primitives/src/commitment/injective_map/mod.rs b/crypto-primitives/src/commitment/injective_map/mod.rs index 83d9242..cbb41c5 100644 --- a/crypto-primitives/src/commitment/injective_map/mod.rs +++ b/crypto-primitives/src/commitment/injective_map/mod.rs @@ -13,9 +13,9 @@ use algebra_core::groups::Group; pub mod constraints; pub struct PedersenCommCompressor, W: PedersenWindow> { - _group: PhantomData, + _group: PhantomData, _compressor: PhantomData, - _comm: PedersenCommitment, + _comm: PedersenCommitment, } impl, W: PedersenWindow> CommitmentScheme diff --git a/crypto-primitives/src/commitment/pedersen/constraints.rs b/crypto-primitives/src/commitment/pedersen/constraints.rs index 20cf766..3b591e8 100644 --- a/crypto-primitives/src/commitment/pedersen/constraints.rs +++ b/crypto-primitives/src/commitment/pedersen/constraints.rs @@ -15,9 +15,9 @@ use r1cs_std::prelude::*; #[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)] @@ -109,8 +109,8 @@ where let parameters = temp.borrow().clone(); Ok(PedersenCommitmentGadgetParameters { - params: parameters, - _group: PhantomData, + params: parameters, + _group: PhantomData, _engine: PhantomData, _window: PhantomData, }) @@ -128,8 +128,8 @@ where let parameters = temp.borrow().clone(); Ok(PedersenCommitmentGadgetParameters { - params: parameters, - _group: PhantomData, + params: parameters, + _group: PhantomData, _engine: PhantomData, _window: PhantomData, }) diff --git a/crypto-primitives/src/commitment/pedersen/mod.rs b/crypto-primitives/src/commitment/pedersen/mod.rs index cc729d0..369c19b 100644 --- a/crypto-primitives/src/commitment/pedersen/mod.rs +++ b/crypto-primitives/src/commitment/pedersen/mod.rs @@ -23,11 +23,11 @@ pub mod constraints; #[derive(Clone)] pub struct PedersenParameters { pub randomness_generator: Vec, - pub generators: Vec>, + pub generators: Vec>, } pub struct PedersenCommitment { - group: PhantomData, + group: PhantomData, window: PhantomData, } diff --git a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs index eaba73f..5a077ec 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/constraints.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/constraints.rs @@ -21,10 +21,10 @@ pub struct BoweHopwoodPedersenCRHGadgetParameters< ConstraintF: Field, GG: GroupGadget, > { - params: BoweHopwoodPedersenParameters, + params: BoweHopwoodPedersenParameters, _group_g: PhantomData, - _engine: PhantomData, - _window: PhantomData, + _engine: PhantomData, + _window: PhantomData, } pub struct BoweHopwoodPedersenCRHGadget< @@ -32,9 +32,9 @@ pub struct BoweHopwoodPedersenCRHGadget< ConstraintF: Field, GG: GroupGadget, > { - _group: PhantomData<*const G>, + _group: PhantomData<*const G>, _group_gadget: PhantomData<*const GG>, - _engine: PhantomData, + _engine: PhantomData, } impl FixedLengthCRHGadget, ConstraintF> diff --git a/crypto-primitives/src/crh/bowe_hopwood/mod.rs b/crypto-primitives/src/crh/bowe_hopwood/mod.rs index a0ad3c4..f7d9681 100644 --- a/crypto-primitives/src/crh/bowe_hopwood/mod.rs +++ b/crypto-primitives/src/crh/bowe_hopwood/mod.rs @@ -23,7 +23,7 @@ pub struct BoweHopwoodPedersenParameters { } pub struct BoweHopwoodPedersenCRH { - group: PhantomData, + group: PhantomData, window: PhantomData, } diff --git a/crypto-primitives/src/crh/injective_map/constraints.rs b/crypto-primitives/src/crh/injective_map/constraints.rs index 29bf585..599e5f3 100644 --- a/crypto-primitives/src/crh/injective_map/constraints.rs +++ b/crypto-primitives/src/crh/injective_map/constraints.rs @@ -97,9 +97,9 @@ where GG: GroupGadget, IG: InjectiveMapGadget, { - _compressor: PhantomData, + _compressor: PhantomData, _compressor_gadget: PhantomData, - _crh: PedersenCRHGadget, + _crh: PedersenCRHGadget, } impl FixedLengthCRHGadget, ConstraintF> diff --git a/crypto-primitives/src/crh/injective_map/mod.rs b/crypto-primitives/src/crh/injective_map/mod.rs index 64bcb9e..0f88f28 100644 --- a/crypto-primitives/src/crh/injective_map/mod.rs +++ b/crypto-primitives/src/crh/injective_map/mod.rs @@ -46,9 +46,9 @@ impl InjectiveMap> for TECompressor { } pub struct PedersenCRHCompressor, W: PedersenWindow> { - _group: PhantomData, + _group: PhantomData, _compressor: PhantomData, - _crh: PedersenCRH, + _crh: PedersenCRH, } impl, W: PedersenWindow> FixedLengthCRH diff --git a/crypto-primitives/src/crh/pedersen/constraints.rs b/crypto-primitives/src/crh/pedersen/constraints.rs index 6ec30df..4404e2d 100644 --- a/crypto-primitives/src/crh/pedersen/constraints.rs +++ b/crypto-primitives/src/crh/pedersen/constraints.rs @@ -18,19 +18,19 @@ pub struct PedersenCRHGadgetParameters< ConstraintF: Field, GG: GroupGadget, > { - params: PedersenParameters, + params: PedersenParameters, _group_g: PhantomData, - _engine: PhantomData, - _window: PhantomData, + _engine: PhantomData, + _window: PhantomData, } 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> diff --git a/crypto-primitives/src/crh/pedersen/mod.rs b/crypto-primitives/src/crh/pedersen/mod.rs index 5f01c50..d1d6000 100644 --- a/crypto-primitives/src/crh/pedersen/mod.rs +++ b/crypto-primitives/src/crh/pedersen/mod.rs @@ -25,7 +25,7 @@ pub struct PedersenParameters { } pub struct PedersenCRH { - group: PhantomData, + group: PhantomData, window: PhantomData, } diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index ecc8745..2861def 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -82,13 +82,13 @@ impl MerkleTreePath

{ } pub struct MerkleHashTree { - tree: Vec<::Output>, + tree: Vec<::Output>, padding_tree: Vec<( ::Output, ::Output, )>, - parameters: ::Parameters, - root: Option<::Output>, + parameters: ::Parameters, + root: Option<::Output>, } impl MerkleHashTree

{ @@ -248,7 +248,7 @@ impl core::fmt::Display for MerkleTreeError { let msg = match self { MerkleTreeError::IncorrectLeafIndex(index) => { format!("incorrect leaf index: {}", index) - }, + } MerkleTreeError::IncorrectPathLength(len) => format!("incorrect path length: {}", len), }; write!(f, "{}", msg) diff --git a/crypto-primitives/src/nizk/gm17/constraints.rs b/crypto-primitives/src/nizk/gm17/constraints.rs index fdf2361..dc95a8a 100644 --- a/crypto-primitives/src/nizk/gm17/constraints.rs +++ b/crypto-primitives/src/nizk/gm17/constraints.rs @@ -28,12 +28,12 @@ pub struct VerifyingKeyGadget< ConstraintF: Field, P: PairingGadget, > { - pub h_g2: P::G2Gadget, + pub h_g2: P::G2Gadget, pub g_alpha_g1: P::G1Gadget, - pub h_beta_g2: P::G2Gadget, + pub h_beta_g2: P::G2Gadget, pub g_gamma_g1: P::G1Gadget, pub h_gamma_g2: P::G2Gadget, - pub query: Vec, + pub query: Vec, } impl> @@ -72,14 +72,14 @@ pub struct PreparedVerifyingKeyGadget< ConstraintF: Field, P: PairingGadget, > { - pub g_alpha: P::G1Gadget, - pub h_beta: P::G2Gadget, + pub g_alpha: P::G1Gadget, + pub h_beta: P::G2Gadget, pub g_alpha_pc: P::G1PreparedGadget, - pub h_beta_pc: P::G2PreparedGadget, + pub h_beta_pc: P::G2PreparedGadget, pub g_gamma_pc: P::G1PreparedGadget, pub h_gamma_pc: P::G2PreparedGadget, - pub h_pc: P::G2PreparedGadget, - pub query: Vec, + pub h_pc: P::G2PreparedGadget, + pub query: Vec, } pub struct Gm17VerifierGadget @@ -89,7 +89,7 @@ where P: PairingGadget, { _pairing_engine: PhantomData, - _engine: PhantomData, + _engine: PhantomData, _pairing_gadget: PhantomData

, } @@ -412,7 +412,7 @@ mod test { type TestVkGadget = VerifyingKeyGadget; struct Bench { - inputs: Vec>, + inputs: Vec>, num_constraints: usize, } @@ -564,7 +564,7 @@ mod test_recursive { #[derive(Clone)] struct Bench { - inputs: Vec>, + inputs: Vec>, num_constraints: usize, } @@ -612,7 +612,7 @@ mod test_recursive { struct Wrapper { inputs: Vec>, params: Parameters, - proof: Proof, + proof: Proof, } impl ConstraintSynthesizer for Wrapper { @@ -709,7 +709,7 @@ mod test_recursive { let c = Wrapper { inputs: inputs.clone(), params: inner_params.clone(), - proof: inner_proof.clone(), + proof: inner_proof.clone(), }; generate_random_parameters(c, rng).unwrap() @@ -722,7 +722,7 @@ mod test_recursive { let c = Wrapper { inputs: inputs.clone(), params: inner_params.clone(), - proof: inner_proof.clone(), + proof: inner_proof.clone(), }; // Create a groth16 proof with our parameters. create_random_proof(c, ¶ms, rng).unwrap() diff --git a/crypto-primitives/src/nizk/gm17/mod.rs b/crypto-primitives/src/nizk/gm17/mod.rs index 80732a3..82c312c 100644 --- a/crypto-primitives/src/nizk/gm17/mod.rs +++ b/crypto-primitives/src/nizk/gm17/mod.rs @@ -23,9 +23,9 @@ pub struct Gm17< V: ToConstraintField + ?Sized, > { #[doc(hidden)] - _engine: PhantomData, + _engine: PhantomData, #[doc(hidden)] - _circuit: PhantomData, + _circuit: PhantomData, #[doc(hidden)] _verifier_input: PhantomData, } diff --git a/crypto-primitives/src/nizk/groth16/constraints.rs b/crypto-primitives/src/nizk/groth16/constraints.rs index dfb9b74..e238185 100644 --- a/crypto-primitives/src/nizk/groth16/constraints.rs +++ b/crypto-primitives/src/nizk/groth16/constraints.rs @@ -28,10 +28,10 @@ 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 alpha_g1: P::G1Gadget, + pub beta_g2: P::G2Gadget, + pub gamma_g2: P::G2Gadget, + pub delta_g2: P::G2Gadget, pub gamma_abc_g1: Vec, } @@ -78,9 +78,9 @@ pub struct PreparedVerifyingKeyGadget< 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 gamma_g2_neg_pc: P::G2PreparedGadget, + pub delta_g2_neg_pc: P::G2PreparedGadget, + pub gamma_abc_g1: Vec, } pub struct Groth16VerifierGadget @@ -90,7 +90,7 @@ where P: PairingGadget, { _pairing_engine: PhantomData, - _engine: PhantomData, + _engine: PhantomData, _pairing_gadget: PhantomData

, } @@ -359,7 +359,7 @@ mod test { type TestVkGadget = VerifyingKeyGadget; struct Bench { - inputs: Vec>, + inputs: Vec>, num_constraints: usize, } @@ -511,7 +511,7 @@ mod test_recursive { #[derive(Clone)] struct Bench { - inputs: Vec>, + inputs: Vec>, num_constraints: usize, } @@ -559,7 +559,7 @@ mod test_recursive { struct Wrapper { inputs: Vec>, params: Parameters, - proof: Proof, + proof: Proof, } impl ConstraintSynthesizer for Wrapper { @@ -656,7 +656,7 @@ mod test_recursive { let c = Wrapper { inputs: inputs.clone(), params: inner_params.clone(), - proof: inner_proof.clone(), + proof: inner_proof.clone(), }; generate_random_parameters(c, rng).unwrap() @@ -669,7 +669,7 @@ mod test_recursive { let c = Wrapper { inputs: inputs.clone(), params: inner_params.clone(), - proof: inner_proof.clone(), + proof: inner_proof.clone(), }; // Create a groth16 proof with our parameters. create_random_proof(c, ¶ms, rng).unwrap() diff --git a/crypto-primitives/src/nizk/groth16/mod.rs b/crypto-primitives/src/nizk/groth16/mod.rs index ba9062f..44faec9 100644 --- a/crypto-primitives/src/nizk/groth16/mod.rs +++ b/crypto-primitives/src/nizk/groth16/mod.rs @@ -23,9 +23,9 @@ pub struct Groth16< V: ToConstraintField + ?Sized, > { #[doc(hidden)] - _engine: PhantomData, + _engine: PhantomData, #[doc(hidden)] - _circuit: PhantomData, + _circuit: PhantomData, #[doc(hidden)] _verifier_input: PhantomData, } diff --git a/crypto-primitives/src/nizk/mod.rs b/crypto-primitives/src/nizk/mod.rs index c003dab..268c824 100644 --- a/crypto-primitives/src/nizk/mod.rs +++ b/crypto-primitives/src/nizk/mod.rs @@ -67,17 +67,17 @@ mod test { #[derive(Copy, Clone)] struct R1CSCircuit { - x: Option, + x: Option, sum: Option, - w: Option, + w: Option, } impl R1CSCircuit { pub(super) fn new(x: Fr, sum: Fr, w: Fr) -> Self { Self { - x: Some(x), + x: Some(x), sum: Some(sum), - w: Some(w), + w: Some(w), } } } diff --git a/crypto-primitives/src/prf/blake2s/constraints.rs b/crypto-primitives/src/prf/blake2s/constraints.rs index 2d779f0..7695f4c 100644 --- a/crypto-primitives/src/prf/blake2s/constraints.rs +++ b/crypto-primitives/src/prf/blake2s/constraints.rs @@ -664,14 +664,14 @@ mod test { match b { Boolean::Is(b) => { assert!(s.next().unwrap() == b.get_value().unwrap()); - }, + } Boolean::Not(b) => { assert!(s.next().unwrap() != b.get_value().unwrap()); - }, + } Boolean::Constant(b) => { assert!(input_len == 0); assert!(s.next().unwrap() == b); - }, + } } } } diff --git a/crypto-primitives/src/prf/blake2s/mod.rs b/crypto-primitives/src/prf/blake2s/mod.rs index 0aa15a5..c1ce030 100644 --- a/crypto-primitives/src/prf/blake2s/mod.rs +++ b/crypto-primitives/src/prf/blake2s/mod.rs @@ -30,17 +30,17 @@ impl PRF for Blake2s { #[derive(Clone)] pub struct Blake2sWithParameterBlock { - pub digest_length: u8, - pub key_length: u8, - pub fan_out: u8, - pub depth: u8, - pub leaf_length: u32, - pub node_offset: u32, + pub digest_length: u8, + pub key_length: u8, + pub fan_out: u8, + pub depth: u8, + pub leaf_length: u32, + pub node_offset: u32, pub xof_digest_length: u16, - pub node_depth: u8, - pub inner_length: u8, - pub salt: [u8; 8], - pub personalization: [u8; 8], + pub node_depth: u8, + pub inner_length: u8, + pub salt: [u8; 8], + pub personalization: [u8; 8], } impl Blake2sWithParameterBlock { diff --git a/crypto-primitives/src/signature/schnorr/constraints.rs b/crypto-primitives/src/signature/schnorr/constraints.rs index 558fcd1..5790659 100644 --- a/crypto-primitives/src/signature/schnorr/constraints.rs +++ b/crypto-primitives/src/signature/schnorr/constraints.rs @@ -12,8 +12,8 @@ use digest::Digest; pub struct SchnorrSigGadgetParameters> { generator: GG, - _group: PhantomData<*const G>, - _engine: PhantomData<*const ConstraintF>, + _group: PhantomData<*const G>, + _engine: PhantomData<*const ConstraintF>, } impl> Clone @@ -22,8 +22,8 @@ impl> Clone fn clone(&self) -> Self { Self { generator: self.generator.clone(), - _group: PhantomData, - _engine: PhantomData, + _group: PhantomData, + _engine: PhantomData, } } } @@ -38,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> @@ -81,7 +81,7 @@ where )?; Ok(SchnorrSigGadgetPk { pub_key: rand_pk, - _group: PhantomData, + _group: PhantomData, _engine: PhantomData, }) } diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index 445ab49..b7519bb 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -15,15 +15,15 @@ pub mod constraints; pub struct SchnorrSignature { _group: PhantomData, - _hash: PhantomData, + _hash: PhantomData, } #[derive(Derivative)] #[derivative(Clone(bound = "G: Group, H: Digest"))] pub struct SchnorrSigParameters { - _hash: PhantomData, + _hash: PhantomData, pub generator: G, - pub salt: [u8; 32], + pub salt: [u8; 32], } pub type SchnorrPublicKey = G; @@ -42,7 +42,7 @@ impl ToBytes for SchnorrSecretKey { #[derive(Derivative)] #[derivative(Clone(bound = "G: Group"), Default(bound = "G: Group"))] pub struct SchnorrSig { - pub prover_response: G::ScalarField, + pub prover_response: G::ScalarField, pub verifier_challenge: G::ScalarField, } @@ -198,7 +198,7 @@ where } let new_sig = SchnorrSig { - prover_response: *prover_response - &(*verifier_challenge * &multiplier), + prover_response: *prover_response - &(*verifier_challenge * &multiplier), verifier_challenge: *verifier_challenge, }; end_timer!(rand_signature_time); diff --git a/r1cs-std/src/bits/boolean.rs b/r1cs-std/src/bits/boolean.rs index 22d2c1c..b696055 100644 --- a/r1cs-std/src/bits/boolean.rs +++ b/r1cs-std/src/bits/boolean.rs @@ -9,7 +9,7 @@ use r1cs_core::{ConstraintSystem, ConstraintVar, LinearCombination, SynthesisErr #[derive(Copy, Clone, Debug)] pub struct AllocatedBit { variable: Variable, - value: Option, + value: Option, } impl AllocatedBit { @@ -69,7 +69,7 @@ impl AllocatedBit { Ok(AllocatedBit { variable: result_var, - value: result_value, + value: result_value, }) } @@ -108,7 +108,7 @@ impl AllocatedBit { Ok(AllocatedBit { variable: result_var, - value: result_value, + value: result_value, }) } @@ -145,7 +145,7 @@ impl AllocatedBit { Ok(AllocatedBit { variable: result_var, - value: result_value, + value: result_value, }) } @@ -183,7 +183,7 @@ impl AllocatedBit { Ok(AllocatedBit { variable: result_var, - value: result_value, + value: result_value, }) } @@ -221,7 +221,7 @@ impl AllocatedBit { Ok(AllocatedBit { variable: result_var, - value: result_value, + value: result_value, }) } } @@ -362,7 +362,7 @@ fn cond_select_helper>( ); Ok(AllocatedBit { - value: result_val, + value: result_val, variable: result_var, }) } @@ -400,11 +400,11 @@ impl Boolean { } else { LinearCombination::::zero() } - }, + } Boolean::Is(ref v) => (coeff, v.get_variable()).into(), Boolean::Not(ref v) => { LinearCombination::::zero() + (coeff, one) - (coeff, v.get_variable()) - }, + } } } @@ -458,12 +458,12 @@ impl Boolean { (is @ &Boolean::Is(_), not @ &Boolean::Not(_)) | (not @ &Boolean::Not(_), is @ &Boolean::Is(_)) => { Ok(Boolean::xor(cs, is, ¬.not())?.not()) - }, + } // a XOR b = (NOT a) XOR (NOT b) (&Boolean::Is(ref a), &Boolean::Is(ref b)) | (&Boolean::Not(ref a), &Boolean::Not(ref b)) => { Ok(Boolean::Is(AllocatedBit::xor(cs, a, b)?)) - }, + } } } @@ -477,16 +477,16 @@ impl Boolean { (&Boolean::Constant(false), x) | (x, &Boolean::Constant(false)) => Ok(*x), (&Boolean::Constant(true), _) | (_, &Boolean::Constant(true)) => { Ok(Boolean::Constant(true)) - }, + } // a OR b = NOT ((NOT a) AND b) (a @ &Boolean::Is(_), b @ &Boolean::Not(_)) | (b @ &Boolean::Not(_), a @ &Boolean::Is(_)) | (b @ &Boolean::Not(_), a @ &Boolean::Not(_)) => { Ok(Boolean::and(cs, &a.not(), &b.not())?.not()) - }, + } (&Boolean::Is(ref a), &Boolean::Is(ref b)) => { AllocatedBit::or(cs, a, b).map(Boolean::from) - }, + } } } @@ -504,22 +504,22 @@ impl Boolean { // false AND x is always false (&Boolean::Constant(false), _) | (_, &Boolean::Constant(false)) => { Ok(Boolean::Constant(false)) - }, + } // true AND x is always x (&Boolean::Constant(true), x) | (x, &Boolean::Constant(true)) => Ok(*x), // a AND (NOT b) (&Boolean::Is(ref is), &Boolean::Not(ref not)) | (&Boolean::Not(ref not), &Boolean::Is(ref is)) => { Ok(Boolean::Is(AllocatedBit::and_not(cs, is, not)?)) - }, + } // (NOT a) AND (NOT b) = a NOR b (&Boolean::Not(ref a), &Boolean::Not(ref b)) => { Ok(Boolean::Is(AllocatedBit::nor(cs, a, b)?)) - }, + } // a AND b (&Boolean::Is(ref a), &Boolean::Is(ref b)) => { Ok(Boolean::Is(AllocatedBit::and(cs, a, b)?)) - }, + } } } @@ -559,7 +559,7 @@ impl Boolean { ); Ok(()) - }, + } Boolean::Not(ref res) => { cs.enforce( || "enforce nand", @@ -569,7 +569,7 @@ impl Boolean { ); Ok(()) - }, + } } } @@ -760,25 +760,25 @@ impl ConditionalEqGadget for Boolean { // 1 - a (Constant(true), Is(a)) | (Is(a), Constant(true)) => { LinearCombination::zero() + one - a.get_variable() - }, + } // a - 0 = a (Constant(false), Is(a)) | (Is(a), Constant(false)) => { LinearCombination::zero() + a.get_variable() - }, + } // 1 - !a = 1 - (1 - a) = a (Constant(true), Not(a)) | (Not(a), Constant(true)) => { LinearCombination::zero() + a.get_variable() - }, + } // !a - 0 = !a = 1 - a (Constant(false), Not(a)) | (Not(a), Constant(false)) => { LinearCombination::zero() + one - a.get_variable() - }, + } // b - a, (Is(a), Is(b)) => LinearCombination::zero() + b.get_variable() - a.get_variable(), // !b - a = (1 - b) - a (Is(a), Not(b)) | (Not(b), Is(a)) => { LinearCombination::zero() + one - b.get_variable() - a.get_variable() - }, + } // !b - !a = (1 - b) - (1 - a) = a - b, (Not(a), Not(b)) => LinearCombination::zero() + a.get_variable() - b.get_variable(), }; @@ -831,7 +831,7 @@ impl CondSelectGadget for Boolean { Boolean::Constant(false) => Ok(false_value.clone()), cond @ Boolean::Not(_) => { Self::conditionally_select(cs, &cond.not(), false_value, true_value) - }, + } cond @ Boolean::Is(_) => match (true_value, false_value) { (x, &Boolean::Constant(false)) => Boolean::and(cs.ns(|| "and"), cond, x).into(), (&Boolean::Constant(false), x) => Boolean::and(cs.ns(|| "and"), &cond.not(), x), @@ -847,7 +847,7 @@ impl CondSelectGadget for Boolean { cond_select_helper(cs, cond, (a.get_value(), a_lc), (b.get_value(), b_lc))? .into(), ) - }, + } }, } } @@ -1138,42 +1138,42 @@ mod test { let mut b = Boolean::from(AllocatedBit::alloc(&mut cs, || Ok(true)).unwrap()); match b { - Boolean::Is(_) => {}, + Boolean::Is(_) => {} _ => panic!("unexpected value"), } b = b.not(); match b { - Boolean::Not(_) => {}, + Boolean::Not(_) => {} _ => panic!("unexpected value"), } b = b.not(); match b { - Boolean::Is(_) => {}, + Boolean::Is(_) => {} _ => panic!("unexpected value"), } b = Boolean::constant(true); match b { - Boolean::Constant(true) => {}, + Boolean::Constant(true) => {} _ => panic!("unexpected value"), } b = b.not(); match b { - Boolean::Constant(false) => {}, + Boolean::Constant(false) => {} _ => panic!("unexpected value"), } b = b.not(); match b { - Boolean::Constant(true) => {}, + Boolean::Constant(true) => {} _ => panic!("unexpected value"), } } @@ -1215,16 +1215,16 @@ mod test { OperandType::False => Boolean::constant(false), OperandType::AllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()) - }, + } OperandType::AllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()) - }, + } OperandType::NegatedAllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()).not() - }, + } OperandType::NegatedAllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()).not() - }, + } } }; @@ -1237,22 +1237,22 @@ mod test { assert!(cs.is_satisfied()); match (first_operand, second_operand, c) { - (OperandType::True, OperandType::True, Boolean::Constant(false)) => {}, - (OperandType::True, OperandType::False, Boolean::Constant(true)) => {}, - (OperandType::True, OperandType::AllocatedTrue, Boolean::Not(_)) => {}, - (OperandType::True, OperandType::AllocatedFalse, Boolean::Not(_)) => {}, - (OperandType::True, OperandType::NegatedAllocatedTrue, Boolean::Is(_)) => {}, - (OperandType::True, OperandType::NegatedAllocatedFalse, Boolean::Is(_)) => {}, - - (OperandType::False, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::False, OperandType::False, Boolean::Constant(false)) => {}, - (OperandType::False, OperandType::AllocatedTrue, Boolean::Is(_)) => {}, - (OperandType::False, OperandType::AllocatedFalse, Boolean::Is(_)) => {}, - (OperandType::False, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {}, - (OperandType::False, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {}, - - (OperandType::AllocatedTrue, OperandType::True, Boolean::Not(_)) => {}, - (OperandType::AllocatedTrue, OperandType::False, Boolean::Is(_)) => {}, + (OperandType::True, OperandType::True, Boolean::Constant(false)) => {} + (OperandType::True, OperandType::False, Boolean::Constant(true)) => {} + (OperandType::True, OperandType::AllocatedTrue, Boolean::Not(_)) => {} + (OperandType::True, OperandType::AllocatedFalse, Boolean::Not(_)) => {} + (OperandType::True, OperandType::NegatedAllocatedTrue, Boolean::Is(_)) => {} + (OperandType::True, OperandType::NegatedAllocatedFalse, Boolean::Is(_)) => {} + + (OperandType::False, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::False, OperandType::False, Boolean::Constant(false)) => {} + (OperandType::False, OperandType::AllocatedTrue, Boolean::Is(_)) => {} + (OperandType::False, OperandType::AllocatedFalse, Boolean::Is(_)) => {} + (OperandType::False, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {} + (OperandType::False, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {} + + (OperandType::AllocatedTrue, OperandType::True, Boolean::Not(_)) => {} + (OperandType::AllocatedTrue, OperandType::False, Boolean::Is(_)) => {} ( OperandType::AllocatedTrue, OperandType::AllocatedTrue, @@ -1260,7 +1260,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedTrue, OperandType::AllocatedFalse, @@ -1268,7 +1268,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedTrue, @@ -1276,7 +1276,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedFalse, @@ -1284,10 +1284,10 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } - (OperandType::AllocatedFalse, OperandType::True, Boolean::Not(_)) => {}, - (OperandType::AllocatedFalse, OperandType::False, Boolean::Is(_)) => {}, + (OperandType::AllocatedFalse, OperandType::True, Boolean::Not(_)) => {} + (OperandType::AllocatedFalse, OperandType::False, Boolean::Is(_)) => {} ( OperandType::AllocatedFalse, OperandType::AllocatedTrue, @@ -1295,7 +1295,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedFalse, OperandType::AllocatedFalse, @@ -1303,7 +1303,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedTrue, @@ -1311,7 +1311,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedFalse, @@ -1319,10 +1319,10 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } - (OperandType::NegatedAllocatedTrue, OperandType::True, Boolean::Is(_)) => {}, - (OperandType::NegatedAllocatedTrue, OperandType::False, Boolean::Not(_)) => {}, + (OperandType::NegatedAllocatedTrue, OperandType::True, Boolean::Is(_)) => {} + (OperandType::NegatedAllocatedTrue, OperandType::False, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedTrue, @@ -1330,7 +1330,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedFalse, @@ -1338,7 +1338,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedTrue, @@ -1346,7 +1346,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedFalse, @@ -1354,10 +1354,10 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } - (OperandType::NegatedAllocatedFalse, OperandType::True, Boolean::Is(_)) => {}, - (OperandType::NegatedAllocatedFalse, OperandType::False, Boolean::Not(_)) => {}, + (OperandType::NegatedAllocatedFalse, OperandType::True, Boolean::Is(_)) => {} + (OperandType::NegatedAllocatedFalse, OperandType::False, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedTrue, @@ -1365,7 +1365,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedFalse, @@ -1373,7 +1373,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedTrue, @@ -1381,7 +1381,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedFalse, @@ -1389,7 +1389,7 @@ mod test { ) => { assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } _ => panic!("this should never be encountered"), } @@ -1426,18 +1426,18 @@ mod test { OperandType::False => Boolean::constant(false), OperandType::AllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()) - }, + } OperandType::AllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()) - }, + } OperandType::NegatedAllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()) .not() - }, + } OperandType::NegatedAllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()) .not() - }, + } } }; @@ -1498,16 +1498,16 @@ mod test { OperandType::False => Boolean::constant(false), OperandType::AllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()) - }, + } OperandType::AllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()) - }, + } OperandType::NegatedAllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()).not() - }, + } OperandType::NegatedAllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()).not() - }, + } } }; @@ -1520,159 +1520,159 @@ mod test { assert!(cs.is_satisfied()); match (first_operand, second_operand, c) { - (OperandType::True, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::True, OperandType::False, Boolean::Constant(true)) => {}, - (OperandType::True, OperandType::AllocatedTrue, Boolean::Constant(true)) => {}, - (OperandType::True, OperandType::AllocatedFalse, Boolean::Constant(true)) => {}, + (OperandType::True, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::True, OperandType::False, Boolean::Constant(true)) => {} + (OperandType::True, OperandType::AllocatedTrue, Boolean::Constant(true)) => {} + (OperandType::True, OperandType::AllocatedFalse, Boolean::Constant(true)) => {} ( OperandType::True, OperandType::NegatedAllocatedTrue, Boolean::Constant(true), - ) => {}, + ) => {} ( OperandType::True, OperandType::NegatedAllocatedFalse, Boolean::Constant(true), - ) => {}, + ) => {} - (OperandType::False, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::False, OperandType::False, Boolean::Constant(false)) => {}, - (OperandType::False, OperandType::AllocatedTrue, Boolean::Is(_)) => {}, - (OperandType::False, OperandType::AllocatedFalse, Boolean::Is(_)) => {}, - (OperandType::False, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {}, - (OperandType::False, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {}, + (OperandType::False, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::False, OperandType::False, Boolean::Constant(false)) => {} + (OperandType::False, OperandType::AllocatedTrue, Boolean::Is(_)) => {} + (OperandType::False, OperandType::AllocatedFalse, Boolean::Is(_)) => {} + (OperandType::False, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {} + (OperandType::False, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {} - (OperandType::AllocatedTrue, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::AllocatedTrue, OperandType::False, Boolean::Is(_)) => {}, + (OperandType::AllocatedTrue, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::AllocatedTrue, OperandType::False, Boolean::Is(_)) => {} ( OperandType::AllocatedTrue, OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedTrue, OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } - (OperandType::AllocatedFalse, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::AllocatedFalse, OperandType::False, Boolean::Is(_)) => {}, + (OperandType::AllocatedFalse, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::AllocatedFalse, OperandType::False, Boolean::Is(_)) => {} ( OperandType::AllocatedFalse, OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedFalse, OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::True, Boolean::Constant(true), - ) => {}, - (OperandType::NegatedAllocatedTrue, OperandType::False, Boolean::Not(_)) => {}, + ) => {} + (OperandType::NegatedAllocatedTrue, OperandType::False, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::True, Boolean::Constant(true), - ) => {}, - (OperandType::NegatedAllocatedFalse, OperandType::False, Boolean::Not(_)) => {}, + ) => {} + (OperandType::NegatedAllocatedFalse, OperandType::False, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value, Some(false)); - }, + } _ => panic!( "this should never be encountered, in case: (a = {:?}, b = {:?}, c = {:?})", @@ -1710,16 +1710,16 @@ mod test { OperandType::False => Boolean::constant(false), OperandType::AllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()) - }, + } OperandType::AllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()) - }, + } OperandType::NegatedAllocatedTrue => { Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()).not() - }, + } OperandType::NegatedAllocatedFalse => { Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()).not() - }, + } } }; @@ -1732,33 +1732,31 @@ mod test { assert!(cs.is_satisfied()); match (first_operand, second_operand, c) { - (OperandType::True, OperandType::True, Boolean::Constant(true)) => {}, - (OperandType::True, OperandType::False, Boolean::Constant(false)) => {}, - (OperandType::True, OperandType::AllocatedTrue, Boolean::Is(_)) => {}, - (OperandType::True, OperandType::AllocatedFalse, Boolean::Is(_)) => {}, - (OperandType::True, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {}, - (OperandType::True, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {}, - - (OperandType::False, OperandType::True, Boolean::Constant(false)) => {}, - (OperandType::False, OperandType::False, Boolean::Constant(false)) => {}, - (OperandType::False, OperandType::AllocatedTrue, Boolean::Constant(false)) => { - }, + (OperandType::True, OperandType::True, Boolean::Constant(true)) => {} + (OperandType::True, OperandType::False, Boolean::Constant(false)) => {} + (OperandType::True, OperandType::AllocatedTrue, Boolean::Is(_)) => {} + (OperandType::True, OperandType::AllocatedFalse, Boolean::Is(_)) => {} + (OperandType::True, OperandType::NegatedAllocatedTrue, Boolean::Not(_)) => {} + (OperandType::True, OperandType::NegatedAllocatedFalse, Boolean::Not(_)) => {} + + (OperandType::False, OperandType::True, Boolean::Constant(false)) => {} + (OperandType::False, OperandType::False, Boolean::Constant(false)) => {} + (OperandType::False, OperandType::AllocatedTrue, Boolean::Constant(false)) => {} (OperandType::False, OperandType::AllocatedFalse, Boolean::Constant(false)) => { - }, + } ( OperandType::False, OperandType::NegatedAllocatedTrue, Boolean::Constant(false), - ) => {}, + ) => {} ( OperandType::False, OperandType::NegatedAllocatedFalse, Boolean::Constant(false), - ) => {}, + ) => {} - (OperandType::AllocatedTrue, OperandType::True, Boolean::Is(_)) => {}, - (OperandType::AllocatedTrue, OperandType::False, Boolean::Constant(false)) => { - }, + (OperandType::AllocatedTrue, OperandType::True, Boolean::Is(_)) => {} + (OperandType::AllocatedTrue, OperandType::False, Boolean::Constant(false)) => {} ( OperandType::AllocatedTrue, OperandType::AllocatedTrue, @@ -1766,7 +1764,7 @@ mod test { ) => { assert!(cs.get("and result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::AllocatedTrue, OperandType::AllocatedFalse, @@ -1774,7 +1772,7 @@ mod test { ) => { assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedTrue, @@ -1782,7 +1780,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedTrue, OperandType::NegatedAllocatedFalse, @@ -1790,11 +1788,11 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } - (OperandType::AllocatedFalse, OperandType::True, Boolean::Is(_)) => {}, + (OperandType::AllocatedFalse, OperandType::True, Boolean::Is(_)) => {} (OperandType::AllocatedFalse, OperandType::False, Boolean::Constant(false)) => { - }, + } ( OperandType::AllocatedFalse, OperandType::AllocatedTrue, @@ -1802,7 +1800,7 @@ mod test { ) => { assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedFalse, OperandType::AllocatedFalse, @@ -1810,7 +1808,7 @@ mod test { ) => { assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedTrue, @@ -1818,7 +1816,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::AllocatedFalse, OperandType::NegatedAllocatedFalse, @@ -1826,14 +1824,14 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } - (OperandType::NegatedAllocatedTrue, OperandType::True, Boolean::Not(_)) => {}, + (OperandType::NegatedAllocatedTrue, OperandType::True, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedTrue, OperandType::False, Boolean::Constant(false), - ) => {}, + ) => {} ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedTrue, @@ -1841,7 +1839,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::AllocatedFalse, @@ -1849,7 +1847,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedTrue, @@ -1857,7 +1855,7 @@ mod test { ) => { assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedTrue, OperandType::NegatedAllocatedFalse, @@ -1865,14 +1863,14 @@ mod test { ) => { assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } - (OperandType::NegatedAllocatedFalse, OperandType::True, Boolean::Not(_)) => {}, + (OperandType::NegatedAllocatedFalse, OperandType::True, Boolean::Not(_)) => {} ( OperandType::NegatedAllocatedFalse, OperandType::False, Boolean::Constant(false), - ) => {}, + ) => {} ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedTrue, @@ -1880,7 +1878,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::AllocatedFalse, @@ -1888,7 +1886,7 @@ mod test { ) => { assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedTrue, @@ -1896,7 +1894,7 @@ mod test { ) => { assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); - }, + } ( OperandType::NegatedAllocatedFalse, OperandType::NegatedAllocatedFalse, @@ -1904,14 +1902,14 @@ mod test { ) => { assert!(cs.get("nor result") == Fr::one()); assert_eq!(v.value, Some(true)); - }, + } _ => { panic!( "unexpected behavior at {:?} AND {:?}", first_operand, second_operand ); - }, + } } } } @@ -2072,7 +2070,7 @@ mod test { match r { Boolean::Is(ref r) => { assert_eq!(r.value.unwrap(), expected); - }, + } _ => unreachable!(), } } diff --git a/r1cs-std/src/bits/uint32.rs b/r1cs-std/src/bits/uint32.rs index 846d5a2..6029015 100644 --- a/r1cs-std/src/bits/uint32.rs +++ b/r1cs-std/src/bits/uint32.rs @@ -13,7 +13,7 @@ use crate::{ #[derive(Clone, Debug)] pub struct UInt32 { // Least significant bit_gadget first - bits: Vec, + bits: Vec, value: Option, } @@ -55,7 +55,7 @@ impl UInt32 { } v - }, + } None => vec![None; 32], }; @@ -94,19 +94,19 @@ impl UInt32 { if b { value.as_mut().map(|v| *v |= 1); } - }, + } &Boolean::Is(ref b) => match b.get_value() { Some(true) => { value.as_mut().map(|v| *v |= 1); - }, - Some(false) => {}, + } + Some(false) => {} None => value = None, }, &Boolean::Not(ref b) => match b.get_value() { Some(false) => { value.as_mut().map(|v| *v |= 1); - }, - Some(true) => {}, + } + Some(true) => {} None => value = None, }, } @@ -128,7 +128,7 @@ impl UInt32 { .collect(); UInt32 { - bits: new_bits, + bits: new_bits, value: self.value.map(|v| v.rotate_right(by as u32)), } } @@ -193,12 +193,12 @@ impl UInt32 { match op.value { Some(val) => { result_value.as_mut().map(|v| *v += u64::from(val)); - }, + } None => { // If any of our operands have unknown value, we won't // know the value of the result result_value = None; - }, + } } // Iterate over each bit_gadget of the operand and add the operand to @@ -211,18 +211,18 @@ impl UInt32 { // Add coeff * bit_gadget lc += (coeff, bit.get_variable()); - }, + } Boolean::Not(ref bit) => { all_constants = false; // Add coeff * (1 - bit_gadget) = coeff * ONE - coeff * bit_gadget lc = lc + (coeff, CS::one()) - (coeff, bit.get_variable()); - }, + } Boolean::Constant(bit) => { if bit { lc += (coeff, CS::one()); } - }, + } } coeff.double_in_place(); @@ -269,7 +269,7 @@ impl UInt32 { result_bits.truncate(32); Ok(UInt32 { - bits: result_bits, + bits: result_bits, value: modular_value, }) } @@ -298,7 +298,7 @@ impl ToBytesGadget for UInt32 { let mut bytes = Vec::new(); for (i, chunk8) in self.to_bits_le().chunks(8).enumerate() { let byte = UInt8 { - bits: chunk8.to_vec(), + bits: chunk8.to_vec(), value: value_chunks[i], }; bytes.push(byte); @@ -362,7 +362,7 @@ mod test { match bit_gadget { &Boolean::Constant(bit_gadget) => { assert!(bit_gadget == ((b.value.unwrap() >> i) & 1 == 1)); - }, + } _ => unreachable!(), } } @@ -371,8 +371,8 @@ mod test { for x in v.iter().zip(expected_to_be_same.iter()) { match x { - (&Boolean::Constant(true), &Boolean::Constant(true)) => {}, - (&Boolean::Constant(false), &Boolean::Constant(false)) => {}, + (&Boolean::Constant(true), &Boolean::Constant(true)) => {} + (&Boolean::Constant(false), &Boolean::Constant(false)) => {} _ => unreachable!(), } } @@ -407,13 +407,13 @@ mod test { match b { &Boolean::Is(ref b) => { assert!(b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Not(ref b) => { assert!(!b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Constant(b) => { assert!(b == (expected & 1 == 1)); - }, + } } expected >>= 1; @@ -448,7 +448,7 @@ mod test { &Boolean::Not(_) => panic!(), &Boolean::Constant(b) => { assert!(b == (expected & 1 == 1)); - }, + } } expected >>= 1; @@ -486,10 +486,10 @@ mod test { match b { &Boolean::Is(ref b) => { assert!(b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Not(ref b) => { assert!(!b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Constant(_) => unreachable!(), } @@ -525,7 +525,7 @@ mod test { match b { &Boolean::Constant(b) => { assert_eq!(b, tmp & 1 == 1); - }, + } _ => unreachable!(), } diff --git a/r1cs-std/src/bits/uint8.rs b/r1cs-std/src/bits/uint8.rs index d55e804..6cb67e0 100644 --- a/r1cs-std/src/bits/uint8.rs +++ b/r1cs-std/src/bits/uint8.rs @@ -10,7 +10,7 @@ use core::borrow::Borrow; #[derive(Clone, Debug)] pub struct UInt8 { // Least significant bit_gadget first - pub(crate) bits: Vec, + pub(crate) bits: Vec, pub(crate) value: Option, } @@ -134,19 +134,19 @@ impl UInt8 { if b { value.as_mut().map(|v| *v |= 1); } - }, + } Boolean::Is(ref b) => match b.get_value() { Some(true) => { value.as_mut().map(|v| *v |= 1); - }, - Some(false) => {}, + } + Some(false) => {} None => value = None, }, Boolean::Not(ref b) => match b.get_value() { Some(false) => { value.as_mut().map(|v| *v |= 1); - }, - Some(true) => {}, + } + Some(true) => {} None => value = None, }, } @@ -233,7 +233,7 @@ impl AllocGadget for UInt8 { } v - }, + } _ => vec![None; 8], }; @@ -272,7 +272,7 @@ impl AllocGadget for UInt8 { } v - }, + } _ => vec![None; 8], }; @@ -342,7 +342,7 @@ mod test { match bit_gadget { &Boolean::Constant(bit_gadget) => { assert!(bit_gadget == ((b.value.unwrap() >> i) & 1 == 1)); - }, + } _ => unreachable!(), } } @@ -351,8 +351,8 @@ mod test { for x in v.iter().zip(expected_to_be_same.iter()) { match x { - (&Boolean::Constant(true), &Boolean::Constant(true)) => {}, - (&Boolean::Constant(false), &Boolean::Constant(false)) => {}, + (&Boolean::Constant(true), &Boolean::Constant(true)) => {} + (&Boolean::Constant(false), &Boolean::Constant(false)) => {} _ => unreachable!(), } } @@ -387,13 +387,13 @@ mod test { match b { &Boolean::Is(ref b) => { assert!(b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Not(ref b) => { assert!(!b.get_value().unwrap() == (expected & 1 == 1)); - }, + } &Boolean::Constant(b) => { assert!(b == (expected & 1 == 1)); - }, + } } expected >>= 1; diff --git a/r1cs-std/src/fields/fp/cmp.rs b/r1cs-std/src/fields/fp/cmp.rs index 8034ec8..1414aea 100644 --- a/r1cs-std/src/fields/fp/cmp.rs +++ b/r1cs-std/src/fields/fp/cmp.rs @@ -111,14 +111,14 @@ impl FpGadget { Ordering::Less => { left = a; right = b; - }, + } Ordering::Greater => { left = b; right = a; - }, + } Ordering::Equal => { return Err(SynthesisError::Unsatisfiable); - }, + } }; let right_for_check = if should_also_check_equality { right.add_constant(cs.ns(|| "plus one"), &F::one())? @@ -252,7 +252,7 @@ mod test { true, ) .unwrap(); - }, + } Ordering::Greater => { a_var .enforce_cmp( @@ -270,8 +270,8 @@ mod test { true, ) .unwrap(); - }, - _ => {}, + } + _ => {} } if i == 0 { @@ -300,7 +300,7 @@ mod test { true, ) .unwrap(); - }, + } Ordering::Greater => { a_var .enforce_cmp( @@ -318,8 +318,8 @@ mod test { true, ) .unwrap(); - }, - _ => {}, + } + _ => {} } assert!(!cs.is_satisfied()); diff --git a/r1cs-std/src/fields/fp/mod.rs b/r1cs-std/src/fields/fp/mod.rs index df7ea1b..2f8c937 100644 --- a/r1cs-std/src/fields/fp/mod.rs +++ b/r1cs-std/src/fields/fp/mod.rs @@ -13,7 +13,7 @@ pub mod cmp; #[derive(Debug)] pub struct FpGadget { - pub value: Option, + pub value: Option, pub variable: ConstraintVar, } @@ -364,7 +364,7 @@ impl ToBitsGadget for FpGadget { assert_eq!(tmp.len(), num_bits as usize); tmp - }, + } None => vec![None; num_bits as usize], }; @@ -422,7 +422,7 @@ impl ToBytesGadget for FpGadget { let default = F::default(); let default_len = to_bytes![&default].unwrap().len(); vec![None; default_len] - }, + } }; let bytes = UInt8::alloc_vec(cs.ns(|| "Alloc bytes"), &byte_values)?; @@ -438,7 +438,7 @@ impl ToBytesGadget for FpGadget { Boolean::Is(bit) => { lc += (coeff, bit.get_variable()); coeff.double_in_place(); - }, + } Boolean::Constant(_) | Boolean::Not(_) => unreachable!(), } } @@ -577,7 +577,7 @@ impl ThreeBitCondNegLookupGadget for FpGadget { impl Clone for FpGadget { fn clone(&self) -> Self { Self { - value: self.value.clone(), + value: self.value.clone(), variable: self.variable.clone(), } } diff --git a/r1cs-std/src/fields/fp12.rs b/r1cs-std/src/fields/fp12.rs index 55a4691..7131676 100644 --- a/r1cs-std/src/fields/fp12.rs +++ b/r1cs-std/src/fields/fp12.rs @@ -31,8 +31,8 @@ where P: Fp12Parameters, ::Fp2Params: Fp2Parameters, { - pub c0: Fp6Gadget, - pub c1: Fp6Gadget, + pub c0: Fp6Gadget, + pub c1: Fp6Gadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -847,7 +847,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -872,7 +872,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/fields/fp2.rs b/r1cs-std/src/fields/fp2.rs index f38e2bb..5dbc369 100644 --- a/r1cs-std/src/fields/fp2.rs +++ b/r1cs-std/src/fields/fp2.rs @@ -11,8 +11,8 @@ use crate::{fields::fp::FpGadget, prelude::*, Vec}; #[derivative(Debug(bound = "P: Fp2Parameters, ConstraintF: PrimeField"))] #[must_use] pub struct Fp2Gadget, ConstraintF: PrimeField> { - pub c0: FpGadget, - pub c1: FpGadget, + pub c0: FpGadget, + pub c1: FpGadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -526,8 +526,8 @@ impl, ConstraintF: PrimeField> Clone { fn clone(&self) -> Self { Self { - c0: self.c0.clone(), - c1: self.c1.clone(), + c0: self.c0.clone(), + c1: self.c1.clone(), _params: PhantomData, } } @@ -624,7 +624,7 @@ impl, ConstraintF: PrimeField> AllocGadget { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -649,7 +649,7 @@ impl, ConstraintF: PrimeField> AllocGadget { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/fields/fp3.rs b/r1cs-std/src/fields/fp3.rs index ec705bb..39c6006 100644 --- a/r1cs-std/src/fields/fp3.rs +++ b/r1cs-std/src/fields/fp3.rs @@ -14,9 +14,9 @@ use crate::{fields::fp::FpGadget, prelude::*, Vec}; #[must_use] pub struct Fp3Gadget, ConstraintF: PrimeField + SquareRootField> { - pub c0: FpGadget, - pub c1: FpGadget, - pub c2: FpGadget, + pub c0: FpGadget, + pub c1: FpGadget, + pub c2: FpGadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -880,7 +880,7 @@ impl, ConstraintF: PrimeField + SquareRootFie Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1), Ok(fe.c2)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -907,7 +907,7 @@ impl, ConstraintF: PrimeField + SquareRootFie Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1), Ok(fe.c2)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/fields/fp4.rs b/r1cs-std/src/fields/fp4.rs index 085e065..8c05cb7 100644 --- a/r1cs-std/src/fields/fp4.rs +++ b/r1cs-std/src/fields/fp4.rs @@ -22,8 +22,8 @@ where P: Fp4Parameters, P::Fp2Params: Fp2Parameters, { - pub c0: Fp2Gadget, - pub c1: Fp2Gadget, + pub c0: Fp2Gadget, + pub c1: Fp2Gadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -569,8 +569,8 @@ where { fn clone(&self) -> Self { Self { - c0: self.c0.clone(), - c1: self.c1.clone(), + c0: self.c0.clone(), + c1: self.c1.clone(), _params: PhantomData, } } @@ -686,7 +686,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -711,7 +711,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/fields/fp6_2over3.rs b/r1cs-std/src/fields/fp6_2over3.rs index 7cd375a..29ec485 100644 --- a/r1cs-std/src/fields/fp6_2over3.rs +++ b/r1cs-std/src/fields/fp6_2over3.rs @@ -25,8 +25,8 @@ where P: Fp6Parameters, P::Fp3Params: Fp3Parameters, { - pub c0: Fp3Gadget, - pub c1: Fp3Gadget, + pub c0: Fp3Gadget, + pub c1: Fp3Gadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -557,8 +557,8 @@ where { fn clone(&self) -> Self { Self { - c0: self.c0.clone(), - c1: self.c1.clone(), + c0: self.c0.clone(), + c1: self.c1.clone(), _params: PhantomData, } } @@ -677,7 +677,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -702,7 +702,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1)) - }, + } Err(_) => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/fields/fp6_3over2.rs b/r1cs-std/src/fields/fp6_3over2.rs index b2635aa..a7f3b49 100644 --- a/r1cs-std/src/fields/fp6_3over2.rs +++ b/r1cs-std/src/fields/fp6_3over2.rs @@ -21,9 +21,9 @@ where P: Fp6Parameters, P::Fp2Params: Fp2Parameters, { - pub c0: Fp2Gadget, - pub c1: Fp2Gadget, - pub c2: Fp2Gadget, + pub c0: Fp2Gadget, + pub c1: Fp2Gadget, + pub c2: Fp2Gadget, #[derivative(Debug = "ignore")] _params: PhantomData

, } @@ -977,7 +977,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1), Ok(fe.c2)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -1004,7 +1004,7 @@ where Ok(fe) => { let fe = *fe.borrow(); (Ok(fe.c0), Ok(fe.c1), Ok(fe.c2)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/groups/curves/short_weierstrass/mnt4/mod.rs b/r1cs-std/src/groups/curves/short_weierstrass/mnt4/mod.rs index 8db3307..2ecfdbf 100644 --- a/r1cs-std/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/r1cs-std/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -27,8 +27,8 @@ pub type G2Gadget

= #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct G1PreparedGadget { - pub x: FpGadget, - pub y: FpGadget, + pub x: FpGadget, + pub y: FpGadget, pub x_twist: Fp2Gadget, pub y_twist: Fp2Gadget, } @@ -113,11 +113,11 @@ type Fp2G

= Fp2Gadget<

::Fp2Params,

#[derive(Derivative)] #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct G2PreparedGadget { - pub x: Fp2Gadget, - pub y: Fp2Gadget, - pub x_over_twist: Fp2Gadget, - pub y_over_twist: Fp2Gadget, - pub double_coefficients: Vec>, + pub x: Fp2Gadget, + pub y: Fp2Gadget, + pub x_over_twist: Fp2Gadget, + pub y_over_twist: Fp2Gadget, + pub double_coefficients: Vec>, pub addition_coefficients: Vec>, } @@ -222,11 +222,11 @@ impl G2PreparedGadget

{ let twist_inv = P::TWIST.inverse().unwrap(); let mut g2p = G2PreparedGadget { - x: q.x.clone(), - y: q.y.clone(), - x_over_twist: q.x.mul_by_constant(cs.ns(|| "x over twist"), &twist_inv)?, - y_over_twist: q.y.mul_by_constant(cs.ns(|| "y over twist"), &twist_inv)?, - double_coefficients: vec![], + x: q.x.clone(), + y: q.y.clone(), + x_over_twist: q.x.mul_by_constant(cs.ns(|| "x over twist"), &twist_inv)?, + y_over_twist: q.y.mul_by_constant(cs.ns(|| "y over twist"), &twist_inv)?, + double_coefficients: vec![], addition_coefficients: vec![], }; @@ -302,10 +302,10 @@ impl G2PreparedGadget

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct AteDoubleCoefficientsGadget { - pub c_h: Fp2Gadget, + pub c_h: Fp2Gadget, pub c_4c: Fp2Gadget, - pub c_j: Fp2Gadget, - pub c_l: Fp2Gadget, + pub c_j: Fp2Gadget, + pub c_l: Fp2Gadget, } impl ToBytesGadget for AteDoubleCoefficientsGadget

{ diff --git a/r1cs-std/src/groups/curves/short_weierstrass/mnt6/mod.rs b/r1cs-std/src/groups/curves/short_weierstrass/mnt6/mod.rs index 25cbef1..8929757 100644 --- a/r1cs-std/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/r1cs-std/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -27,8 +27,8 @@ pub type G2Gadget

= #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct G1PreparedGadget { - pub x: FpGadget, - pub y: FpGadget, + pub x: FpGadget, + pub y: FpGadget, pub x_twist: Fp3Gadget, pub y_twist: Fp3Gadget, } @@ -115,11 +115,11 @@ type Fp3G

= Fp3Gadget<

::Fp3Params,

#[derive(Derivative)] #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct G2PreparedGadget { - pub x: Fp3Gadget, - pub y: Fp3Gadget, - pub x_over_twist: Fp3Gadget, - pub y_over_twist: Fp3Gadget, - pub double_coefficients: Vec>, + pub x: Fp3Gadget, + pub y: Fp3Gadget, + pub x_over_twist: Fp3Gadget, + pub y_over_twist: Fp3Gadget, + pub double_coefficients: Vec>, pub addition_coefficients: Vec>, } @@ -224,11 +224,11 @@ impl G2PreparedGadget

{ let twist_inv = P::TWIST.inverse().unwrap(); let mut g2p = G2PreparedGadget { - x: q.x.clone(), - y: q.y.clone(), - x_over_twist: q.x.mul_by_constant(cs.ns(|| "x over twist"), &twist_inv)?, - y_over_twist: q.y.mul_by_constant(cs.ns(|| "y over twist"), &twist_inv)?, - double_coefficients: vec![], + x: q.x.clone(), + y: q.y.clone(), + x_over_twist: q.x.mul_by_constant(cs.ns(|| "x over twist"), &twist_inv)?, + y_over_twist: q.y.mul_by_constant(cs.ns(|| "y over twist"), &twist_inv)?, + double_coefficients: vec![], addition_coefficients: vec![], }; @@ -304,10 +304,10 @@ impl G2PreparedGadget

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct AteDoubleCoefficientsGadget { - pub c_h: Fp3Gadget, + pub c_h: Fp3Gadget, pub c_4c: Fp3Gadget, - pub c_j: Fp3Gadget, - pub c_l: Fp3Gadget, + pub c_j: Fp3Gadget, + pub c_l: Fp3Gadget, } impl ToBytesGadget for AteDoubleCoefficientsGadget

{ diff --git a/r1cs-std/src/groups/curves/short_weierstrass/mod.rs b/r1cs-std/src/groups/curves/short_weierstrass/mod.rs index 4c723f4..116e2d4 100644 --- a/r1cs-std/src/groups/curves/short_weierstrass/mod.rs +++ b/r1cs-std/src/groups/curves/short_weierstrass/mod.rs @@ -22,11 +22,11 @@ pub struct AffineGadget< ConstraintF: Field, F: FieldGadget, > { - pub x: F, - pub y: F, + pub x: F, + pub y: F, pub infinity: Boolean, - _params: PhantomData

, - _engine: PhantomData, + _params: PhantomData

, + _engine: PhantomData, } impl> @@ -53,7 +53,7 @@ impl { let ge = ge.into_affine(); (Ok(ge.x), Ok(ge.y), Ok(ge.infinity)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -107,7 +107,7 @@ where ) { (Some(x), Some(y), Some(infinity)) => { Some(SWAffine::new(x, y, infinity).into_projective()) - }, + } (None, None, None) => None, _ => unreachable!(), } @@ -450,7 +450,7 @@ where Ok(ge) => { let ge = ge.borrow().into_affine(); (Ok(ge.x), Ok(ge.y), Ok(ge.infinity)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -574,7 +574,7 @@ where Ok(ge) => { let ge = ge.borrow().into_affine(); (Ok(ge.x), Ok(ge.y), Ok(ge.infinity)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/groups/curves/twisted_edwards/mod.rs b/r1cs-std/src/groups/curves/twisted_edwards/mod.rs index fddfcb3..ed071b8 100644 --- a/r1cs-std/src/groups/curves/twisted_edwards/mod.rs +++ b/r1cs-std/src/groups/curves/twisted_edwards/mod.rs @@ -21,8 +21,8 @@ pub struct MontgomeryAffineGadget< ConstraintF: Field, F: FieldGadget, > { - pub x: F, - pub y: F, + pub x: F, + pub y: F, #[derivative(Debug = "ignore")] _params: PhantomData

, #[derivative(Debug = "ignore")] @@ -90,7 +90,7 @@ mod montgomery_affine_impl { t0.mul_assign(&invy); Ok(t0) - }, + } None => Err(SynthesisError::DivisionByZero), } })?; @@ -108,7 +108,7 @@ mod montgomery_affine_impl { t0.mul_assign(&t1); Ok(t0) - }, + } None => Err(SynthesisError::DivisionByZero), } })?; @@ -140,7 +140,7 @@ mod montgomery_affine_impl { Some(d) => { n.mul_assign(&d); Ok(n) - }, + } None => Err(SynthesisError::DivisionByZero), } })?; @@ -193,8 +193,8 @@ pub struct AffineGadget< ConstraintF: Field, F: FieldGadget, > { - pub x: F, - pub y: F, + pub x: F, + pub y: F, #[derivative(Debug = "ignore")] _params: PhantomData

, #[derivative(Debug = "ignore")] @@ -504,7 +504,7 @@ mod affine_impl { Ok(ge) => { let ge = *ge.borrow(); (Ok(ge.x), Ok(ge.y)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -621,7 +621,7 @@ mod affine_impl { Ok(ge) => { let ge = *ge.borrow(); (Ok(ge.x), Ok(ge.y)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -960,14 +960,14 @@ mod projective_impl { match edwards_result { None => { edwards_result = Some(segment_result); - }, + } Some(ref mut edwards_result) => { *edwards_result = GroupGadget::, ConstraintF>::add( &segment_result, cs.ns(|| "edwards addition"), edwards_result, )?; - }, + } } Ok(()) @@ -1050,13 +1050,13 @@ mod projective_impl { match result { None => { result = Some(tmp); - }, + } Some(ref mut result) => { *result = tmp.add( cs.ns(|| format!("addition of window {}, {}", segment_i, i)), result, )?; - }, + } } } @@ -1101,7 +1101,7 @@ mod projective_impl { Ok(ge) => { let ge = ge.borrow().into_affine(); (Ok(ge.x), Ok(ge.y)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -1223,7 +1223,7 @@ mod projective_impl { Ok(ge) => { let ge = ge.borrow().into_affine(); (Ok(ge.x), Ok(ge.y)) - }, + } _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), diff --git a/r1cs-std/src/pairing/bls12/mod.rs b/r1cs-std/src/pairing/bls12/mod.rs index 7cf32cb..6501248 100644 --- a/r1cs-std/src/pairing/bls12/mod.rs +++ b/r1cs-std/src/pairing/bls12/mod.rs @@ -36,7 +36,7 @@ impl PairingGadget

{ c1.c1 = c1.c1.mul(cs.ns(|| "mul c1.c1"), &p.x)?; *f = f.mul_by_014(cs.ns(|| "sparse mul f"), &c0, &c1, &c2)?; Ok(()) - }, + } TwistType::D => { let c0 = Fp2G::

::new(p.y.clone(), zero); let mut c1 = coeffs.0.clone(); @@ -46,7 +46,7 @@ impl PairingGadget

{ c1.c1 = c1.c1.mul(cs.ns(|| "mul c1.c1"), &p.x)?; *f = f.mul_by_034(cs.ns(|| "sparse mul f"), &c0, &c1, &c2)?; Ok(()) - }, + } } } diff --git a/r1cs-std/src/test_constraint_system.rs b/r1cs-std/src/test_constraint_system.rs index 765df33..41c1bb9 100644 --- a/r1cs-std/src/test_constraint_system.rs +++ b/r1cs-std/src/test_constraint_system.rs @@ -11,7 +11,7 @@ enum NamedObject { /// Constraint system for testing purposes. pub struct TestConstraintSystem { - named_objects: BTreeMap, + named_objects: BTreeMap, current_namespace: Vec, pub constraints: Vec<( LinearCombination, @@ -19,8 +19,8 @@ pub struct TestConstraintSystem { LinearCombination, String, )>, - inputs: Vec<(ConstraintF, String)>, - aux: Vec<(ConstraintF, String)>, + inputs: Vec<(ConstraintF, String)>, + aux: Vec<(ConstraintF, String)>, } impl TestConstraintSystem { @@ -54,11 +54,11 @@ impl TestConstraintSystem { ); TestConstraintSystem { - named_objects: map, + named_objects: map, current_namespace: vec![], - constraints: vec![], - inputs: vec![(ConstraintF::one(), "ONE".into())], - aux: vec![], + constraints: vec![], + inputs: vec![(ConstraintF::one(), "ONE".into())], + aux: vec![], } } diff --git a/rustfmt.toml b/rustfmt.toml index 0527c73..7171213 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,13 +1,9 @@ reorder_imports = true wrap_comments = true normalize_comments = true -format_strings = true -struct_field_align_threshold = 40 use_try_shorthand = true match_block_trailing_comma = true use_field_init_shorthand = true edition = "2018" condense_wildcard_suffixes = true merge_imports = true -imports_layout = "Mixed" -unstable_features = true