From 0486c30b3b2fa8675f45d9f6d3f4d31cfc293f7a Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Wed, 9 Dec 2020 11:05:07 -0800 Subject: [PATCH] Format --- bls12_377/src/curves/g1.rs | 9 +++++---- bls12_377/src/curves/g2.rs | 6 ++---- bls12_381/src/fields/fq6.rs | 12 ++++++------ bn254/src/curves/mod.rs | 20 ++++++++++++++++---- bn254/src/fields/fq12.rs | 24 ++++++++++++------------ bn254/src/fields/fq6.rs | 24 ++++++++++++------------ bw6_761/src/fields/fq3.rs | 5 ++++- curve-tests/src/fields.rs | 2 +- ed_on_bn254/src/curves/mod.rs | 2 -- ed_on_cp6_782/src/curves/mod.rs | 2 +- ed_on_mnt4_298/src/curves/mod.rs | 2 +- mnt4_298/src/curves/g1.rs | 2 +- mnt4_298/src/fields/fq2.rs | 5 +---- mnt6_298/src/curves/g1.rs | 2 +- mnt6_298/src/curves/g2.rs | 32 +++++++++++++++++++++++++------- mnt6_298/src/curves/mod.rs | 5 ++++- mnt6_753/src/curves/g1.rs | 2 +- mnt6_753/src/curves/g2.rs | 2 +- mnt6_753/src/curves/mod.rs | 2 +- 19 files changed, 95 insertions(+), 65 deletions(-) diff --git a/bls12_377/src/curves/g1.rs b/bls12_377/src/curves/g1.rs index 819d03f..74f140d 100644 --- a/bls12_377/src/curves/g1.rs +++ b/bls12_377/src/curves/g1.rs @@ -1,9 +1,10 @@ use ark_ec::models::{ModelParameters, SWModelParameters}; -use ark_ff::{ - field_new, Zero, -}; +use ark_ff::{field_new, Zero}; -use crate::{Fq, Fr, fields::{FQ_ZERO, FQ_ONE}}; +use crate::{ + fields::{FQ_ONE, FQ_ZERO}, + Fq, Fr, +}; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; diff --git a/bls12_377/src/curves/g2.rs b/bls12_377/src/curves/g2.rs index 12db65c..77cda3a 100644 --- a/bls12_377/src/curves/g2.rs +++ b/bls12_377/src/curves/g2.rs @@ -1,9 +1,7 @@ use ark_ec::models::{ModelParameters, SWModelParameters}; -use ark_ff::{ - field_new, Zero, -}; +use ark_ff::{field_new, Zero}; -use crate::{g1, Fq, Fq2, Fr, fields::FQ_ZERO}; +use crate::{fields::FQ_ZERO, g1, Fq, Fq2, Fr}; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; diff --git a/bls12_381/src/fields/fq6.rs b/bls12_381/src/fields/fq6.rs index e99a889..8adb477 100644 --- a/bls12_381/src/fields/fq6.rs +++ b/bls12_381/src/fields/fq6.rs @@ -19,32 +19,32 @@ impl Fp6Parameters for Fq6Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "1"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^1) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "0"), field_new!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^3) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "0"), field_new!(Fq, "1"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^5) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "0"), field_new!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), ), diff --git a/bn254/src/curves/mod.rs b/bn254/src/curves/mod.rs index a7c713d..1f241cc 100644 --- a/bn254/src/curves/mod.rs +++ b/bn254/src/curves/mod.rs @@ -26,13 +26,25 @@ impl BnParameters for Parameters { const TWIST_MUL_BY_Q_X: Fq2 = field_new!( Fq2, - field_new!(Fq, "21575463638280843010398324269430826099269044274347216827212613867836435027261"), - field_new!(Fq, "10307601595873709700152284273816112264069230130616436755625194854815875713954"), + field_new!( + Fq, + "21575463638280843010398324269430826099269044274347216827212613867836435027261" + ), + field_new!( + Fq, + "10307601595873709700152284273816112264069230130616436755625194854815875713954" + ), ); const TWIST_MUL_BY_Q_Y: Fq2 = field_new!( Fq2, - field_new!(Fq, "2821565182194536844548159561693502659359617185244120367078079554186484126554"), - field_new!(Fq, "3505843767911556378687030309984248845540243509899259641013678093033130930403"), + field_new!( + Fq, + "2821565182194536844548159561693502659359617185244120367078079554186484126554" + ), + field_new!( + Fq, + "3505843767911556378687030309984248845540243509899259641013678093033130930403" + ), ); const TWIST_TYPE: TwistType = TwistType::D; type Fp = Fq; diff --git a/bn254/src/fields/fq12.rs b/bn254/src/fields/fq12.rs index 8eae78e..9dcc521 100644 --- a/bn254/src/fields/fq12.rs +++ b/bn254/src/fields/fq12.rs @@ -14,62 +14,62 @@ impl Fp12Parameters for Fq12Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "1"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^1) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "8376118865763821496583973867626364092589906065868298776909617916018768340080"), field_new!(Fq, "16469823323077808223889137241176536799009286646108169935659301613961712198316"), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556617"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^3) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "11697423496358154304825782922584725312912383441159505038794027105778954184319"), field_new!(Fq, "303847389135065887422783454877609941456349188919719272345083954437860409601"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^5) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "3321304630594332808241809054958361220322477375291206261884409189760185844239"), field_new!(Fq, "5722266937896532885780051958958348231143373700109372999374820235121374419868"), ), // Fp2::NONRESIDUE^(((q^6) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "-1"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^7) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "13512124006075453725662431877630910996106405091429524885779419978626457868503"), field_new!(Fq, "5418419548761466998357268504080738289687024511189653727029736280683514010267"), ), // Fp2::NONRESIDUE^(((q^8) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^9) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "10190819375481120917420622822672549775783927716138318623895010788866272024264"), field_new!(Fq, "21584395482704209334823622290379665147239961968378104390343953940207365798982"), ), // Fp2::NONRESIDUE^(((q^10) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "2203960485148121921418603742825762020974279258880205651967"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^11) - 1) / 6) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "18566938241244942414004596690298913868373833782006617400804628704885040364344"), field_new!(Fq, "16165975933942742336466353786298926857552937457188450663314217659523851788715"), ), diff --git a/bn254/src/fields/fq6.rs b/bn254/src/fields/fq6.rs index 9c678b0..09777a4 100644 --- a/bn254/src/fields/fq6.rs +++ b/bn254/src/fields/fq6.rs @@ -16,32 +16,32 @@ impl Fp6Parameters for Fq6Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "1"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^1) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "21575463638280843010398324269430826099269044274347216827212613867836435027261"), field_new!(Fq, "10307601595873709700152284273816112264069230130616436755625194854815875713954"), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^3) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "3772000881919853776433695186713858239009073593817195771773381919316419345261"), field_new!(Fq, "2236595495967245188281701248203181795121068902605861227855261137820944008926"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^(((q^5) - 1) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "18429021223477853657660792034369865839114504446431234726392080002137598044644"), field_new!(Fq, "9344045779998320333812420223237981029506012124075525679208581902008406485703"), ), @@ -49,32 +49,32 @@ impl Fp6Parameters for Fq6Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "1"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "2581911344467009335267311115468803099551665605076196740867805258568234346338"), field_new!(Fq, "19937756971775647987995932169929341994314640652964949448313374472400716661030"), ), // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "5324479202449903542726783395506214481928257762400643279780343368557297135718"), field_new!(Fq, "16208900380737693084919495127334387981393726419856888799917914180988844123039"), ), // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"), field_new!(Fq, "0"), ), // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3) - field_new!(Fq2, + field_new!(Fq2, field_new!(Fq, "13981852324922362344252311234282257507216387789820983642040889267519694726527"), field_new!(Fq, "7629828391165209371577384193250820201684255241773809077146787135900891633097"), ), diff --git a/bw6_761/src/fields/fq3.rs b/bw6_761/src/fields/fq3.rs index 9e34460..63dd38d 100644 --- a/bw6_761/src/fields/fq3.rs +++ b/bw6_761/src/fields/fq3.rs @@ -3,7 +3,10 @@ use ark_ff::{ fields::fp3::{Fp3, Fp3Parameters}, }; -use crate::{Fq, fields::{FQ_ZERO, FQ_ONE}}; +use crate::{ + fields::{FQ_ONE, FQ_ZERO}, + Fq, +}; pub type Fq3 = Fp3; diff --git a/curve-tests/src/fields.rs b/curve-tests/src/fields.rs index acdaff4..94285ab 100644 --- a/curve-tests/src/fields.rs +++ b/curve-tests/src/fields.rs @@ -370,7 +370,7 @@ pub fn frobenius_test>(characteristic: C, maxpower: us for power in 1..maxpower { let mut a_qi = a; a_qi.frobenius_map(power); - assert_eq!(a_qi, a_q); + assert_eq!(a_qi, a_q, "failed on power {}", power); a_q = a_q.pow(&characteristic); } diff --git a/ed_on_bn254/src/curves/mod.rs b/ed_on_bn254/src/curves/mod.rs index e943ab1..69db4f3 100644 --- a/ed_on_bn254/src/curves/mod.rs +++ b/ed_on_bn254/src/curves/mod.rs @@ -11,8 +11,6 @@ mod tests; pub type EdwardsAffine = GroupAffine; pub type EdwardsProjective = GroupProjective; - - /// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the /// form: ax² + y² = 1 + dx²y². /// over some base finite field Fq. diff --git a/ed_on_cp6_782/src/curves/mod.rs b/ed_on_cp6_782/src/curves/mod.rs index f0a7895..4ae769b 100644 --- a/ed_on_cp6_782/src/curves/mod.rs +++ b/ed_on_cp6_782/src/curves/mod.rs @@ -2,7 +2,7 @@ use ark_ec::{ models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, twisted_edwards_extended::{GroupAffine, GroupProjective}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{fq::Fq, fr::Fr}; diff --git a/ed_on_mnt4_298/src/curves/mod.rs b/ed_on_mnt4_298/src/curves/mod.rs index 50d2352..ab12d93 100644 --- a/ed_on_mnt4_298/src/curves/mod.rs +++ b/ed_on_mnt4_298/src/curves/mod.rs @@ -2,7 +2,7 @@ use ark_ec::{ models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, twisted_edwards_extended::{GroupAffine, GroupProjective}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{fq::Fq, fr::Fr}; diff --git a/mnt4_298/src/curves/g1.rs b/mnt4_298/src/curves/g1.rs index 7dc5b93..1cfa47c 100644 --- a/mnt4_298/src/curves/g1.rs +++ b/mnt4_298/src/curves/g1.rs @@ -3,7 +3,7 @@ use ark_ec::{ mnt4, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; pub type G1Affine = mnt4::G1Affine; pub type G1Projective = mnt4::G1Projective; diff --git a/mnt4_298/src/fields/fq2.rs b/mnt4_298/src/fields/fq2.rs index 07e904e..46b9d42 100644 --- a/mnt4_298/src/fields/fq2.rs +++ b/mnt4_298/src/fields/fq2.rs @@ -19,10 +19,7 @@ impl Fp2Parameters for Fq2Parameters { /// The quadratic non-residue in Fp2 that is used /// in the computation of square roots is (8, 1), the same as that in /// [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L103) - const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = ( - field_new!(Fq, "8"), - FQ_ONE, - ); + const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = (field_new!(Fq, "8"), FQ_ONE); /// Precomputed coefficients: /// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]` diff --git a/mnt6_298/src/curves/g1.rs b/mnt6_298/src/curves/g1.rs index 13be4bf..da37c1c 100644 --- a/mnt6_298/src/curves/g1.rs +++ b/mnt6_298/src/curves/g1.rs @@ -2,7 +2,7 @@ use ark_ec::{ mnt6, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{Fq, Fr}; diff --git a/mnt6_298/src/curves/g2.rs b/mnt6_298/src/curves/g2.rs index a20fd27..b9ce22c 100644 --- a/mnt6_298/src/curves/g2.rs +++ b/mnt6_298/src/curves/g2.rs @@ -3,7 +3,7 @@ use ark_ec::{ mnt6::MNT6Parameters, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{g1, Fq, Fq3, Fr, FQ_ZERO}; @@ -81,10 +81,28 @@ const G2_GENERATOR_X: Fq3 = const G2_GENERATOR_Y: Fq3 = field_new!(Fq3, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); -pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427"); -pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114"); -pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558"); +pub const G2_GENERATOR_X_C0: Fq = field_new!( + Fq, + "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427" +); +pub const G2_GENERATOR_X_C1: Fq = field_new!( + Fq, + "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114" +); +pub const G2_GENERATOR_X_C2: Fq = field_new!( + Fq, + "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558" +); -pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377"); -pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678"); -pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903"); +pub const G2_GENERATOR_Y_C0: Fq = field_new!( + Fq, + "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377" +); +pub const G2_GENERATOR_Y_C1: Fq = field_new!( + Fq, + "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678" +); +pub const G2_GENERATOR_Y_C2: Fq = field_new!( + Fq, + "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903" +); diff --git a/mnt6_298/src/curves/mod.rs b/mnt6_298/src/curves/mod.rs index 9e1d728..94e180b 100644 --- a/mnt6_298/src/curves/mod.rs +++ b/mnt6_298/src/curves/mod.rs @@ -1,6 +1,9 @@ use ark_ff::{biginteger::BigInteger320, field_new, Fp3}; -use ark_ec::{models::mnt6::{MNT6Parameters, MNT6}, SWModelParameters}; +use ark_ec::{ + models::mnt6::{MNT6Parameters, MNT6}, + SWModelParameters, +}; use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, Fr}; diff --git a/mnt6_753/src/curves/g1.rs b/mnt6_753/src/curves/g1.rs index afc38a1..0df91b2 100644 --- a/mnt6_753/src/curves/g1.rs +++ b/mnt6_753/src/curves/g1.rs @@ -2,7 +2,7 @@ use ark_ec::{ mnt6, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{Fq, Fr, FR_ONE}; diff --git a/mnt6_753/src/curves/g2.rs b/mnt6_753/src/curves/g2.rs index b43911e..f875d83 100644 --- a/mnt6_753/src/curves/g2.rs +++ b/mnt6_753/src/curves/g2.rs @@ -3,7 +3,7 @@ use ark_ec::{ mnt6::MNT6Parameters, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{field_new}; +use ark_ff::field_new; use crate::{g1, Fq, Fq3, Fr, FQ_ZERO}; diff --git a/mnt6_753/src/curves/mod.rs b/mnt6_753/src/curves/mod.rs index 1242279..e7fe9ba 100644 --- a/mnt6_753/src/curves/mod.rs +++ b/mnt6_753/src/curves/mod.rs @@ -1,8 +1,8 @@ -use ark_ff::{biginteger::BigInteger768, field_new, Fp3}; use ark_ec::models::{ mnt6::{MNT6Parameters, MNT6}, SWModelParameters, }; +use ark_ff::{biginteger::BigInteger768, field_new, Fp3}; use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, Fr};