diff --git a/bls12_377/src/constraints/curves.rs b/bls12_377/src/constraints/curves.rs index f4c57d1..19869c8 100644 --- a/bls12_377/src/constraints/curves.rs +++ b/bls12_377/src/constraints/curves.rs @@ -1,4 +1,4 @@ -use ark_ec::{bls12::Bls12Parameters, ModelParameters}; +use ark_ec::{bls12::Bls12Parameters, CurveConfig}; use ark_r1cs_std::{ fields::fp::FpVar, groups::{bls12, curves::twisted_edwards::AffineVar as TEAffineVar}, @@ -14,7 +14,7 @@ pub type G2Var = bls12::G2Var; /// An element of G1 (in TE Affine form) in the BLS12-377 bilinear group. pub type G1TEAffineVar = TEAffineVar< ::G1Parameters, - FpVar<<::G1Parameters as ModelParameters>::BaseField>, + FpVar<<::G1Parameters as CurveConfig>::BaseField>, >; /// Represents the cached precomputation that can be performed on a G1 element diff --git a/bls12_377/src/curves/g1.rs b/bls12_377/src/curves/g1.rs index de2f5c9..6b8051f 100644 --- a/bls12_377/src/curves/g1.rs +++ b/bls12_377/src/curves/g1.rs @@ -1,21 +1,19 @@ use ark_ec::models::{ - twisted_edwards_extended::{ - GroupAffine as TEGroupAffine, GroupProjective as TEGroupProjective, + short_weierstrass::{Affine as SWAffine, SWCurveConfig}, + twisted_edwards::{ + Affine as TEAffine, MontCurveConfig, Projective as TEProjective, TECurveConfig, }, - ModelParameters, MontgomeryModelParameters, SWModelParameters, TEModelParameters, + CurveConfig, }; -use ark_ff::{MontFp, Zero}; +use ark_ff::{Field, MontFp, Zero}; use core::ops::Neg; -use crate::{ - fields::{FQ_ONE, FQ_ZERO}, - Fq, Fr, -}; +use crate::{Fq, Fr}; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -24,22 +22,18 @@ impl ModelParameters for Parameters { /// COFACTOR_INV = COFACTOR^{-1} mod r /// = 5285428838741532253824584287042945485047145357130994810877 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "5285428838741532253824584287042945485047145357130994810877" - ); + const COFACTOR_INV: Fr = MontFp!("5285428838741532253824584287042945485047145357130994810877"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 0 - const COEFF_A: Fq = FQ_ZERO; + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 1 - const COEFF_B: Fq = FQ_ONE; + const COEFF_B: Fq = Fq::ONE; /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1SWAffine = G1SWAffine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -47,8 +41,9 @@ impl SWModelParameters for Parameters { } } -pub type G1TEAffine = TEGroupAffine; -pub type G1TEProjective = TEGroupProjective; +pub type G1SWAffine = SWAffine; +pub type G1TEAffine = TEAffine; +pub type G1TEProjective = TEProjective; /// Bls12_377::G1 also has a twisted Edwards form. /// It can be obtained via the following script, implementing @@ -97,18 +92,17 @@ pub type G1TEProjective = TEGroupProjective; /// # b = -TE1d/TE1a /// TE2d = Fp(122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179) /// ``` -impl TEModelParameters for Parameters { +impl TECurveConfig for Parameters { /// COEFF_A = -1 - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = 122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179 mod q - const COEFF_D: Fq = MontFp!(Fq, "122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179"); + const COEFF_D: Fq = MontFp!("122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179"); /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (TE_GENERATOR_X, TE_GENERATOR_Y); + const GENERATOR: G1TEAffine = G1TEAffine::new_unchecked(TE_GENERATOR_X, TE_GENERATOR_Y); - type MontgomeryModelParameters = Parameters; + type MontCurveConfig = Parameters; /// Multiplication by `a` is multiply by `-1`. #[inline(always)] @@ -146,23 +140,23 @@ impl TEModelParameters for Parameters { // # MB = s // MB=Fp(10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931) // ``` -impl MontgomeryModelParameters for Parameters { +impl MontCurveConfig for Parameters { /// COEFF_A = 228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384 - const COEFF_A: Fq = MontFp!(Fq, "228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384"); + const COEFF_A: Fq = MontFp!("228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384"); /// COEFF_B = 10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931 - const COEFF_B: Fq = MontFp!(Fq, "10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931"); + const COEFF_B: Fq = MontFp!("10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931"); - type TEModelParameters = Parameters; + type TECurveConfig = Parameters; } /// G1_GENERATOR_X = /// 81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695"); +pub const G1_GENERATOR_X: Fq = MontFp!("81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695"); /// G1_GENERATOR_Y = /// 241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030"); +pub const G1_GENERATOR_Y: Fq = MontFp!("241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030"); // The generator for twisted Edward form is the same SW generator converted into // the normalized TE form (TE2). @@ -210,8 +204,8 @@ pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "241266749859715473739788878240585681 // ``` /// TE_GENERATOR_X = /// 71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393 -pub const TE_GENERATOR_X: Fq = MontFp!(Fq, "71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393"); +pub const TE_GENERATOR_X: Fq = MontFp!("71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393"); /// TE_GENERATOR_Y = /// 6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235 -pub const TE_GENERATOR_Y: Fq = MontFp!(Fq, "6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235"); +pub const TE_GENERATOR_Y: Fq = MontFp!("6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235"); diff --git a/bls12_377/src/curves/g2.rs b/bls12_377/src/curves/g2.rs index 84ecd2b..c84ab24 100644 --- a/bls12_377/src/curves/g2.rs +++ b/bls12_377/src/curves/g2.rs @@ -1,12 +1,16 @@ -use ark_ec::models::{ModelParameters, SWModelParameters}; -use ark_ff::{MontFp, QuadExt, Zero}; +use ark_ec::{ + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::Affine, +}; +use ark_ff::{Field, MontFp, Zero}; -use crate::{fields::FQ_ZERO, g1, Fq, Fq2, Fr}; +use crate::{g1, Fq, Fq2, Fr}; +pub type G2Affine = Affine; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq2; type ScalarField = Fr; @@ -26,15 +30,13 @@ impl ModelParameters for Parameters { /// COFACTOR_INV = COFACTOR^{-1} mod r /// = 6764900296503390671038341982857278410319949526107311149686707033187604810669 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "6764900296503390671038341982857278410319949526107311149686707033187604810669" - ); + const COFACTOR_INV: Fr = + MontFp!("6764900296503390671038341982857278410319949526107311149686707033187604810669"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = [0, 0] - const COEFF_A: Fq2 = QuadExt!(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A,); + const COEFF_A: Fq2 = Fq2::new(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A); // As per https://eprint.iacr.org/2012/072.pdf, // this curve has b' = b/i, where b is the COEFF_B of G1, and x^6 -i is @@ -42,14 +44,13 @@ impl SWModelParameters for Parameters { // In our case, i = u (App A.3, T_6). /// COEFF_B = [0, /// 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906] - const COEFF_B: Fq2 = QuadExt!( - FQ_ZERO, - MontFp!(Fq, "155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906"), + const COEFF_B: Fq2 = Fq2::new( + Fq::ZERO, + MontFp!("155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906"), ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -57,21 +58,21 @@ impl SWModelParameters for Parameters { } } -pub const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); -pub const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); +pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); +pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); /// G2_GENERATOR_X_C0 = /// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294 -pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294"); +pub const G2_GENERATOR_X_C0: Fq = MontFp!("233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294"); /// G2_GENERATOR_X_C1 = /// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118 -pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118"); +pub const G2_GENERATOR_X_C1: Fq = MontFp!("140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118"); /// G2_GENERATOR_Y_C0 = /// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423 -pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423"); +pub const G2_GENERATOR_Y_C0: Fq = MontFp!("63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423"); /// G2_GENERATOR_Y_C1 = /// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491 -pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491"); +pub const G2_GENERATOR_Y_C1: Fq = MontFp!("149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491"); diff --git a/bls12_377/src/curves/tests.rs b/bls12_377/src/curves/tests.rs index 89244c3..a000bd2 100755 --- a/bls12_377/src/curves/tests.rs +++ b/bls12_377/src/curves/tests.rs @@ -1,22 +1,19 @@ use ark_algebra_test_templates::{ curves::{curve_tests, edwards_tests, sw_tests}, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, generate_g2_test, - groups::group_test, msm::test_var_base_msm, }; -use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine}; +use ark_ec::{models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine}; use ark_ff::{ - fields::{Field, PrimeField, SquareRootField}, + fields::{Field, PrimeField}, One, Zero, }; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign}; -use crate::{ - g1, g2, Bls12_377, Fq, Fq12, Fr, G1Affine, G1Projective, G1TEProjective, G2Affine, G2Projective, -}; +use crate::{g1, g2, Bls12_377, Fq, Fq12, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; -generate_g1_test!(bls12_377; curve_tests; sw_tests; edwards_tests; te_group_tests;); +generate_g1_test!(bls12_377; curve_tests; sw_tests; edwards_tests;); generate_g2_test!(bls12_377; curve_tests; sw_tests;); generate_bilinearity_test!(Bls12_377, Fq12); generate_g1_generator_raw_test!(bls12_377, 1); diff --git a/bls12_377/src/fields/fq.rs b/bls12_377/src/fields/fq.rs index 6128f8b..30744c6 100644 --- a/bls12_377/src/fields/fq.rs +++ b/bls12_377/src/fields/fq.rs @@ -1,10 +1,7 @@ -use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp}; +use ark_ff::fields::{Fp384, MontBackend, MontConfig}; #[derive(MontConfig)] #[modulus = "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177"] #[generator = "15"] pub struct FqConfig; pub type Fq = Fp384>; - -pub const FQ_ONE: Fq = Fq::new(FqConfig::R); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); diff --git a/bls12_377/src/fields/fq12.rs b/bls12_377/src/fields/fq12.rs index b81f84d..e139072 100644 --- a/bls12_377/src/fields/fq12.rs +++ b/bls12_377/src/fields/fq12.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, CubicExt, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,65 +10,65 @@ pub struct Fq12Config; impl Fp12Config for Fq12Config { type Fp6Config = Fq6Config; - const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO); + const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO); const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 6) - QuadExt!(FQ_ONE, FQ_ZERO), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^(((q^1) - 1) / 6) - QuadExt!( - MontFp!(Fq, "92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"), - FQ_ZERO, + Fq2::new( + MontFp!("92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^2) - 1) / 6) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"), - FQ_ZERO, + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 6) - QuadExt!( - MontFp!(Fq, "216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"), - FQ_ZERO, + Fq2::new( + MontFp!("216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^4) - 1) / 6) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), - FQ_ZERO, + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 6) - QuadExt!( - MontFp!(Fq, "123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"), - FQ_ZERO, + Fq2::new( + MontFp!("123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^6) - 1) / 6) - QuadExt!( - MontFp!(Fq, "-1"), - FQ_ZERO, + Fq2::new( + MontFp!("-1"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^7) - 1) / 6) - QuadExt!( - MontFp!(Fq, "165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"), - FQ_ZERO, + Fq2::new( + MontFp!("165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^8) - 1) / 6) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^9) - 1) / 6) - QuadExt!( - MontFp!(Fq, "42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"), - FQ_ZERO, + Fq2::new( + MontFp!("42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^10) - 1) / 6) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^11) - 1) / 6) - QuadExt!( - MontFp!(Fq, "135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"), - FQ_ZERO, + Fq2::new( + MontFp!("135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"), + Fq::ZERO, ), ]; } diff --git a/bls12_377/src/fields/fq2.rs b/bls12_377/src/fields/fq2.rs index b818f1a..a6b2aa5 100644 --- a/bls12_377/src/fields/fq2.rs +++ b/bls12_377/src/fields/fq2.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config { type Fp = Fq; /// NONRESIDUE = -5 - const NONRESIDUE: Fq = MontFp!(Fq, "-5"); + const NONRESIDUE: Fq = MontFp!("-5"); /// Coefficients for the Frobenius automorphism. const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ // NONRESIDUE**(((q^0) - 1) / 2) - FQ_ONE, + Fq::ONE, // NONRESIDUE**(((q^1) - 1) / 2) - MontFp!(Fq, "-1"), + MontFp!("-1"), ]; #[inline(always)] @@ -28,6 +28,3 @@ impl Fp2Config for Fq2Config { fe - original } } - -pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO); -pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO); diff --git a/bls12_377/src/fields/fq6.rs b/bls12_377/src/fields/fq6.rs index 9b4454d..834227a 100644 --- a/bls12_377/src/fields/fq6.rs +++ b/bls12_377/src/fields/fq6.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -11,59 +11,59 @@ impl Fp6Config for Fq6Config { type Fp2Config = Fq2Config; /// NONRESIDUE = U - const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE); + const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE); const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 3) - QuadExt!(FQ_ONE, FQ_ZERO), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^(((q^1) - 1) / 3) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"), - FQ_ZERO, + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^2) - 1) / 3) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), - FQ_ZERO, + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 3) - QuadExt!(MontFp!(Fq, "-1"), FQ_ZERO), + Fq2::new(MontFp!("-1"), Fq::ZERO), // Fp2::NONRESIDUE^(((q^4) - 1) / 3) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 3) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"), + Fq::ZERO, ), ]; const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3) - QuadExt!(FQ_ONE, FQ_ZERO), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), - FQ_ZERO + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), + Fq::ZERO ), // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), + Fq::ZERO, ), // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3) - QuadExt!(FQ_ONE, FQ_ZERO), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3) - QuadExt!( - MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), - FQ_ZERO, + Fq2::new( + MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"), + Fq::ZERO, ), // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3) - QuadExt!( - MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), - FQ_ZERO, + Fq2::new( + MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"), + Fq::ZERO, ), ]; @@ -72,6 +72,6 @@ impl Fp6Config for Fq6Config { // Karatsuba multiplication with constant other = u. let c0 = Fq2Config::mul_fp_by_nonresidue(&fe.c1); let c1 = fe.c0; - QuadExt!(c0, c1) + Fq2::new(c0, c1) } } diff --git a/bls12_377/src/fields/tests.rs b/bls12_377/src/fields/tests.rs index daaea06..2a1ab8f 100644 --- a/bls12_377/src/fields/tests.rs +++ b/bls12_377/src/fields/tests.rs @@ -3,7 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::{BigInt, BigInteger, BigInteger384}, - fields::{FftField, Field, Fp6Config, PrimeField, SquareRootField}, + fields::{FftField, Field, Fp6Config, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; diff --git a/bls12_381/src/curves/g1.rs b/bls12_381/src/curves/g1.rs index b6adc9d..116e2d3 100644 --- a/bls12_381/src/curves/g1.rs +++ b/bls12_381/src/curves/g1.rs @@ -1,11 +1,11 @@ use ark_ec::{ bls12, bls12::Bls12Parameters, - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::GroupAffine, + models::CurveConfig, + short_weierstrass::{Affine, SWCurveConfig}, AffineCurve, ProjectiveCurve, }; -use ark_ff::{biginteger::BigInteger256, MontFp, Zero}; +use ark_ff::{biginteger::BigInteger256, Field, MontFp, Zero}; use ark_std::ops::Neg; use crate::*; @@ -16,7 +16,7 @@ pub type G1Projective = bls12::G1Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -25,22 +25,19 @@ impl ModelParameters for Parameters { /// COFACTOR_INV = COFACTOR^{-1} mod r /// = 52435875175126190458656871551744051925719901746859129887267498875565241663483 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "52435875175126190458656871551744051925719901746859129887267498875565241663483" - ); + const COFACTOR_INV: Fr = + MontFp!("52435875175126190458656871551744051925719901746859129887267498875565241663483"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 4 - const COEFF_B: Fq = MontFp!(Fq, "4"); + const COEFF_B: Fq = MontFp!("4"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -71,16 +68,16 @@ impl SWModelParameters for Parameters { /// G1_GENERATOR_X = /// 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"); +pub const G1_GENERATOR_X: Fq = MontFp!("3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"); /// G1_GENERATOR_Y = /// 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"); +pub const G1_GENERATOR_Y: Fq = MontFp!("1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"); /// BETA is a non-trivial cubic root of unity in Fq. -pub const BETA: Fq = MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"); +pub const BETA: Fq = MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"); -pub fn endomorphism(p: &GroupAffine) -> GroupAffine { +pub fn endomorphism(p: &Affine) -> Affine { // Endomorphism of the points on the curve. // endomorphism_p(x,y) = (BETA * x, y) // where BETA is a non-trivial cubic root of unity in Fq. diff --git a/bls12_381/src/curves/g2.rs b/bls12_381/src/curves/g2.rs index 485fcfe..aee6de6 100644 --- a/bls12_381/src/curves/g2.rs +++ b/bls12_381/src/curves/g2.rs @@ -1,11 +1,11 @@ use ark_ec::{ bls12, bls12::Bls12Parameters, - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::GroupAffine, + models::CurveConfig, + short_weierstrass::{Affine, SWCurveConfig}, AffineCurve, }; -use ark_ff::{BigInt, Field, MontFp, QuadExt, Zero}; +use ark_ff::{BigInt, Field, MontFp, Zero}; use crate::*; @@ -15,7 +15,7 @@ pub type G2Projective = bls12::G2Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq2; type ScalarField = Fr; @@ -36,22 +36,19 @@ impl ModelParameters for Parameters { /// COFACTOR_INV = COFACTOR^{-1} mod r /// 26652489039290660355457965112010883481355318854675681319708643586776743290055 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "26652489039290660355457965112010883481355318854675681319708643586776743290055" - ); + const COFACTOR_INV: Fr = + MontFp!("26652489039290660355457965112010883481355318854675681319708643586776743290055"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = [0, 0] - const COEFF_A: Fq2 = QuadExt!(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A,); + const COEFF_A: Fq2 = Fq2::new(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A); /// COEFF_B = [4, 4] - const COEFF_B: Fq2 = QuadExt!(g1::Parameters::COEFF_B, g1::Parameters::COEFF_B,); + const COEFF_B: Fq2 = Fq2::new(g1::Parameters::COEFF_B, g1::Parameters::COEFF_B); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -74,48 +71,45 @@ impl SWModelParameters for Parameters { } } -pub const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); -pub const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); +pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); +pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); /// G2_GENERATOR_X_C0 = /// 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160 -pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160"); +pub const G2_GENERATOR_X_C0: Fq = MontFp!("352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160"); /// G2_GENERATOR_X_C1 = /// 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758 -pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758"); +pub const G2_GENERATOR_X_C1: Fq = MontFp!("3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758"); /// G2_GENERATOR_Y_C0 = /// 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905 -pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905"); +pub const G2_GENERATOR_Y_C0: Fq = MontFp!("1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905"); /// G2_GENERATOR_Y_C1 = /// 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582 -pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582"); +pub const G2_GENERATOR_Y_C1: Fq = MontFp!("927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582"); // psi(x,y) = (x**p * PSI_X, y**p * PSI_Y) is the Frobenius composed // with the quadratic twist and its inverse // PSI_X = 1/(u+1)^((p-1)/3) -pub const P_POWER_ENDOMORPHISM_COEFF_0 : Fq2 = QuadExt!( - FQ_ZERO, +pub const P_POWER_ENDOMORPHISM_COEFF_0 : Fq2 = Fq2::new( + Fq::ZERO, MontFp!( - Fq, - "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437" + "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437" ) ); // PSI_Y = 1/(u+1)^((p-1)/2) -pub const P_POWER_ENDOMORPHISM_COEFF_1: Fq2 = QuadExt!( +pub const P_POWER_ENDOMORPHISM_COEFF_1: Fq2 = Fq2::new( MontFp!( - Fq, - "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), + "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), MontFp!( - Fq, - "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257") + "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257") ); -pub fn p_power_endomorphism(p: &GroupAffine) -> GroupAffine { +pub fn p_power_endomorphism(p: &Affine) -> Affine { // The p-power endomorphism for G2 is defined as follows: // 1. Note that G2 is defined on curve E': y^2 = x^3 + 4(u+1). // To map a point (x, y) in E' to (s, t) in E, diff --git a/bls12_381/src/curves/tests.rs b/bls12_381/src/curves/tests.rs index 2c5da8d..a5abf76 100755 --- a/bls12_381/src/curves/tests.rs +++ b/bls12_381/src/curves/tests.rs @@ -1,10 +1,12 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, - generate_g2_test, groups::*, msm::*, + generate_g2_test, msm::*, +}; +use ark_ec::{ + models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine, ProjectiveCurve, }; -use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{ - fields::{Field, PrimeField, SquareRootField}, + fields::{Field, PrimeField}, One, UniformRand, Zero, }; use ark_std::{rand::Rng, test_rng}; diff --git a/bls12_381/src/fields/fq.rs b/bls12_381/src/fields/fq.rs index 0fe7333..34517ff 100644 --- a/bls12_381/src/fields/fq.rs +++ b/bls12_381/src/fields/fq.rs @@ -1,10 +1,7 @@ -use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp}; +use ark_ff::fields::{Fp384, MontBackend, MontConfig}; #[derive(MontConfig)] #[modulus = "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"] #[generator = "2"] pub struct FqConfig; pub type Fq = Fp384>; - -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); diff --git a/bls12_381/src/fields/fq12.rs b/bls12_381/src/fields/fq12.rs index e94f8b1..32721b2 100644 --- a/bls12_381/src/fields/fq12.rs +++ b/bls12_381/src/fields/fq12.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, CubicExt, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,68 +10,68 @@ pub struct Fq12Config; impl Fp12Config for Fq12Config { type Fp6Config = Fq6Config; - const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO); + const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO); const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 6) - QuadExt!( - MontFp!(Fq, "1"), - MontFp!(Fq, "0"), + Fq2::new( + Fq::ONE, + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^1) - 1) / 6) - QuadExt!( - MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"), - MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"), + Fq2::new( + MontFp!("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"), + MontFp!("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 6) - QuadExt!( - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 6) - QuadExt!( - MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), - MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"), + Fq2::new( + MontFp!("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), + MontFp!("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 6) - QuadExt!( - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 6) - QuadExt!( - MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"), - MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"), + Fq2::new( + MontFp!("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"), + MontFp!("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"), ), // Fp2::NONRESIDUE^(((q^6) - 1) / 6) - QuadExt!( - MontFp!(Fq, "-1"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("-1"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^7) - 1) / 6) - QuadExt!( - MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"), - MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"), + Fq2::new( + MontFp!("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"), + MontFp!("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"), ), // Fp2::NONRESIDUE^(((q^8) - 1) / 6) - QuadExt!( - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^9) - 1) / 6) - QuadExt!( - MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"), - MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), + Fq2::new( + MontFp!("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"), + MontFp!("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"), ), // Fp2::NONRESIDUE^(((q^10) - 1) / 6) - QuadExt!( - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^11) - 1) / 6) - QuadExt!( - MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"), - MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"), + Fq2::new( + MontFp!("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"), + MontFp!("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"), ), ]; } diff --git a/bls12_381/src/fields/fq2.rs b/bls12_381/src/fields/fq2.rs index 848edea..4963080 100644 --- a/bls12_381/src/fields/fq2.rs +++ b/bls12_381/src/fields/fq2.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config { type Fp = Fq; /// NONRESIDUE = -1 - const NONRESIDUE: Fq = MontFp!(Fq, "-1"); + const NONRESIDUE: Fq = MontFp!("-1"); /// Coefficients for the Frobenius automorphism. const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ // Fq(-1)**(((q^0) - 1) / 2) - MontFp!(Fq, "1"), + Fq::ONE, // Fq(-1)**(((q^1) - 1) / 2) - MontFp!(Fq, "-1"), + MontFp!("-1"), ]; #[inline(always)] @@ -25,6 +25,3 @@ impl Fp2Config for Fq2Config { -(*fp) } } - -pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO); -pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO); diff --git a/bls12_381/src/fields/fq6.rs b/bls12_381/src/fields/fq6.rs index 3a649e0..0fd53d1 100644 --- a/bls12_381/src/fields/fq6.rs +++ b/bls12_381/src/fields/fq6.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -11,72 +11,72 @@ impl Fp6Config for Fq6Config { type Fp2Config = Fq2Config; /// NONRESIDUE = (U + 1) - const NONRESIDUE: Fq2 = QuadExt!(FQ_ONE, FQ_ONE); + const NONRESIDUE: Fq2 = Fq2::new(Fq::ONE, Fq::ONE); const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 3) - QuadExt!( - MontFp!(Fq, "1"), - MontFp!(Fq, "0"), + Fq2::new( + Fq::ONE, + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^1) - 1) / 3) - QuadExt!( - MontFp!(Fq, "0"), - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), + Fq2::new( + Fq::ZERO, + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 3) - QuadExt!( - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 3) - QuadExt!( - MontFp!(Fq, "0"), - MontFp!(Fq, "1"), + Fq2::new( + Fq::ZERO, + Fq::ONE, ), // Fp2::NONRESIDUE^(((q^4) - 1) / 3) - QuadExt!( - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 3) - QuadExt!( - MontFp!(Fq, "0"), - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), + Fq2::new( + Fq::ZERO, + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), ), ]; #[rustfmt::skip] const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ // Fq2(u + 1)**(((2q^0) - 2) / 3) - QuadExt!( - MontFp!(Fq, "1"), - MontFp!(Fq, "0"), + Fq2::new( + Fq::ONE, + Fq::ZERO, ), // Fq2(u + 1)**(((2q^1) - 2) / 3) - QuadExt!( - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"), + Fq::ZERO, ), // Fq2(u + 1)**(((2q^2) - 2) / 3) - QuadExt!( - MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"), + Fq::ZERO, ), // Fq2(u + 1)**(((2q^3) - 2) / 3) - QuadExt!( - MontFp!(Fq, "-1"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("-1"), + Fq::ZERO, ), // Fq2(u + 1)**(((2q^4) - 2) / 3) - QuadExt!( - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), + Fq::ZERO, ), // Fq2(u + 1)**(((2q^5) - 2) / 3) - QuadExt!( - MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"), + Fq::ZERO, ), ]; diff --git a/bls12_381/src/fields/tests.rs b/bls12_381/src/fields/tests.rs index d684f06..1891e63 100644 --- a/bls12_381/src/fields/tests.rs +++ b/bls12_381/src/fields/tests.rs @@ -3,7 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::{BigInt, BigInteger, BigInteger384}, - fields::{FftField, Field, Fp12Config, Fp2Config, Fp6Config, PrimeField, SquareRootField}, + fields::{FftField, Field, Fp12Config, Fp2Config, Fp6Config, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -21,7 +21,7 @@ generate_field_serialization_test!(bls12_381; fq2; fq6; fq12;); #[test] fn test_negative_one() { - let neg_one = Fq::new(BigInt::new([ + let neg_one = Fq::new_unchecked(BigInt::new([ 0x43f5fffffffcaaae, 0x32b7fff2ed47fffd, 0x7e83a49a2e99d69, @@ -739,23 +739,6 @@ fn test_frob_coeffs() { ); } -#[test] -fn test_neg_one() { - let o = -Fq::one(); - - let thing: [u64; 6] = [ - 0x43f5fffffffcaaae, - 0x32b7fff2ed47fffd, - 0x7e83a49a2e99d69, - 0xeca8f3318332bb7a, - 0xef148d1ea0f4c069, - 0x40ab3263eff0206, - ]; - let negative_one = Fq::new(BigInt::new(thing)); - - assert_eq!(negative_one, o); -} - #[test] fn test_fq_repr_from() { assert_eq!(BigInt::from(100u64), BigInt::new([100, 0, 0, 0, 0, 0])); diff --git a/bn254/src/curves/g1.rs b/bn254/src/curves/g1.rs index 5a1cd36..56fefff 100644 --- a/bn254/src/curves/g1.rs +++ b/bn254/src/curves/g1.rs @@ -1,12 +1,17 @@ -use ark_ec::models::{ModelParameters, SWModelParameters}; -use ark_ff::{MontFp, Zero}; +use ark_ec::{ + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::Affine, +}; +use ark_ff::{Field, MontFp, Zero}; use crate::{Fq, Fr}; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +pub type G1Affine = Affine; + +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -14,19 +19,18 @@ impl ModelParameters for Parameters { const COFACTOR: &'static [u64] = &[0x1]; /// COFACTOR_INV = COFACTOR^{-1} mod r = 1 - const COFACTOR_INV: Fr = MontFp!(Fr, "1"); + const COFACTOR_INV: Fr = Fr::ONE; } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 3 - const COEFF_B: Fq = MontFp!(Fq, "3"); + const COEFF_B: Fq = MontFp!("3"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -35,7 +39,7 @@ impl SWModelParameters for Parameters { } /// G1_GENERATOR_X = 1 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "1"); +pub const G1_GENERATOR_X: Fq = Fq::ONE; /// G1_GENERATOR_Y = 2 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "2"); +pub const G1_GENERATOR_Y: Fq = MontFp!("2"); diff --git a/bn254/src/curves/g2.rs b/bn254/src/curves/g2.rs index 290c78a..f4ef127 100644 --- a/bn254/src/curves/g2.rs +++ b/bn254/src/curves/g2.rs @@ -1,12 +1,17 @@ -use ark_ec::models::{ModelParameters, SWModelParameters}; -use ark_ff::{MontFp, QuadExt, Zero}; +use ark_ec::{ + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::Affine, +}; +use ark_ff::{Field, MontFp, Zero}; use crate::{Fq, Fq2, Fr}; +pub type G2Affine = Affine; + #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq2; type ScalarField = Fr; @@ -21,32 +26,23 @@ impl ModelParameters for Parameters { ]; /// COFACTOR_INV = COFACTOR^{-1} mod r - const COFACTOR_INV: Fr = MontFp!( - Fr, - "10944121435919637613327163357776759465618812564592884533313067514031822496649" - ); + const COFACTOR_INV: Fr = + MontFp!("10944121435919637613327163357776759465618812564592884533313067514031822496649"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = [0, 0] - const COEFF_A: Fq2 = QuadExt!(MontFp!(Fq, "0"), MontFp!(Fq, "0")); + const COEFF_A: Fq2 = Fq2::ZERO; /// COEFF_B = 3/(u+9) /// (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690) - const COEFF_B: Fq2 = QuadExt!( - MontFp!( - Fq, - "19485874751759354771024239261021720505790618469301721065564631296452457478373" - ), - MontFp!( - Fq, - "266929791119991161246907387137283842545076965332900288569378510910307636690" - ), + const COEFF_B: Fq2 = Fq2::new( + MontFp!("19485874751759354771024239261021720505790618469301721065564631296452457478373"), + MontFp!("266929791119991161246907387137283842545076965332900288569378510910307636690"), ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -54,33 +50,25 @@ impl SWModelParameters for Parameters { } } -pub const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); -pub const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); +pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); +pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); /// G2_GENERATOR_X_C0 = /// 10857046999023057135944570762232829481370756359578518086990519993285655852781 -pub const G2_GENERATOR_X_C0: Fq = MontFp!( - Fq, - "10857046999023057135944570762232829481370756359578518086990519993285655852781" -); +pub const G2_GENERATOR_X_C0: Fq = + MontFp!("10857046999023057135944570762232829481370756359578518086990519993285655852781"); /// G2_GENERATOR_X_C1 = /// 11559732032986387107991004021392285783925812861821192530917403151452391805634 -pub const G2_GENERATOR_X_C1: Fq = MontFp!( - Fq, - "11559732032986387107991004021392285783925812861821192530917403151452391805634" -); +pub const G2_GENERATOR_X_C1: Fq = + MontFp!("11559732032986387107991004021392285783925812861821192530917403151452391805634"); /// G2_GENERATOR_Y_C0 = /// 8495653923123431417604973247489272438418190587263600148770280649306958101930 -pub const G2_GENERATOR_Y_C0: Fq = MontFp!( - Fq, - "8495653923123431417604973247489272438418190587263600148770280649306958101930" -); +pub const G2_GENERATOR_Y_C0: Fq = + MontFp!("8495653923123431417604973247489272438418190587263600148770280649306958101930"); /// G2_GENERATOR_Y_C1 = /// 4082367875863433681332203403145435568316851327593401208105741076214120093531 -pub const G2_GENERATOR_Y_C1: Fq = MontFp!( - Fq, - "4082367875863433681332203403145435568316851327593401208105741076214120093531" -); +pub const G2_GENERATOR_Y_C1: Fq = + MontFp!("4082367875863433681332203403145435568316851327593401208105741076214120093531"); diff --git a/bn254/src/curves/mod.rs b/bn254/src/curves/mod.rs index 873bcab..4c3a540 100644 --- a/bn254/src/curves/mod.rs +++ b/bn254/src/curves/mod.rs @@ -2,7 +2,7 @@ use ark_ec::{ bn, bn::{Bn, BnParameters, TwistType}, }; -use ark_ff::{MontFp, QuadExt}; +use ark_ff::MontFp; use crate::*; @@ -24,25 +24,13 @@ impl BnParameters for Parameters { -1, 0, 0, 1, 0, 1, 1, ]; - const TWIST_MUL_BY_Q_X: Fq2 = QuadExt!( - MontFp!( - Fq, - "21575463638280843010398324269430826099269044274347216827212613867836435027261" - ), - MontFp!( - Fq, - "10307601595873709700152284273816112264069230130616436755625194854815875713954" - ), + const TWIST_MUL_BY_Q_X: Fq2 = Fq2::new( + MontFp!("21575463638280843010398324269430826099269044274347216827212613867836435027261"), + MontFp!("10307601595873709700152284273816112264069230130616436755625194854815875713954"), ); - const TWIST_MUL_BY_Q_Y: Fq2 = QuadExt!( - MontFp!( - Fq, - "2821565182194536844548159561693502659359617185244120367078079554186484126554" - ), - MontFp!( - Fq, - "3505843767911556378687030309984248845540243509899259641013678093033130930403" - ), + const TWIST_MUL_BY_Q_Y: Fq2 = Fq2::new( + MontFp!("2821565182194536844548159561693502659359617185244120367078079554186484126554"), + MontFp!("3505843767911556378687030309984248845540243509899259641013678093033130930403"), ); const TWIST_TYPE: TwistType = TwistType::D; type Fp = Fq; diff --git a/bn254/src/curves/tests.rs b/bn254/src/curves/tests.rs index 5f540f0..270d139 100755 --- a/bn254/src/curves/tests.rs +++ b/bn254/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::{ - curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*, + curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine}; use ark_ff::{ diff --git a/bn254/src/fields/fq.rs b/bn254/src/fields/fq.rs index a2f0cb6..26deabf 100644 --- a/bn254/src/fields/fq.rs +++ b/bn254/src/fields/fq.rs @@ -1,10 +1,7 @@ -use ark_ff::fields::{Fp256, MontBackend, MontConfig, MontFp}; +use ark_ff::fields::{Fp256, MontBackend, MontConfig}; #[derive(MontConfig)] #[modulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"] #[generator = "3"] pub struct FqConfig; pub type Fq = Fp256>; - -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); diff --git a/bn254/src/fields/fq12.rs b/bn254/src/fields/fq12.rs index fcc9649..e59a5d6 100644 --- a/bn254/src/fields/fq12.rs +++ b/bn254/src/fields/fq12.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, CubicExt, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,108 +10,78 @@ pub struct Fq12Config; impl Fp12Config for Fq12Config { type Fp6Config = Fq6Config; - const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO); + const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO); const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 6) - QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^(((q^1) - 1) / 6) - QuadExt!( + Fq2::new( + MontFp!("8376118865763821496583973867626364092589906065868298776909617916018768340080"), MontFp!( - Fq, - "8376118865763821496583973867626364092589906065868298776909617916018768340080" - ), - MontFp!( - Fq, "16469823323077808223889137241176536799009286646108169935659301613961712198316" ), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556617" ), - MontFp!(Fq, "0"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "11697423496358154304825782922584725312912383441159505038794027105778954184319" ), - MontFp!( - Fq, - "303847389135065887422783454877609941456349188919719272345083954437860409601" - ), + MontFp!("303847389135065887422783454877609941456349188919719272345083954437860409601"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616" ), - MontFp!(Fq, "0"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 6) - QuadExt!( - MontFp!( - Fq, - "3321304630594332808241809054958361220322477375291206261884409189760185844239" - ), - MontFp!( - Fq, - "5722266937896532885780051958958348231143373700109372999374820235121374419868" - ), + Fq2::new( + MontFp!("3321304630594332808241809054958361220322477375291206261884409189760185844239"), + MontFp!("5722266937896532885780051958958348231143373700109372999374820235121374419868"), ), // Fp2::NONRESIDUE^(((q^6) - 1) / 6) - QuadExt!(MontFp!(Fq, "-1"), MontFp!(Fq, "0"),), + Fq2::new(MontFp!("-1"), Fq::ZERO), // Fp2::NONRESIDUE^(((q^7) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "13512124006075453725662431877630910996106405091429524885779419978626457868503" ), - MontFp!( - Fq, - "5418419548761466998357268504080738289687024511189653727029736280683514010267" - ), + MontFp!("5418419548761466998357268504080738289687024511189653727029736280683514010267"), ), // Fp2::NONRESIDUE^(((q^8) - 1) / 6) - QuadExt!( - MontFp!( - Fq, - "2203960485148121921418603742825762020974279258880205651966" - ), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("2203960485148121921418603742825762020974279258880205651966"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^9) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "10190819375481120917420622822672549775783927716138318623895010788866272024264" ), MontFp!( - Fq, "21584395482704209334823622290379665147239961968378104390343953940207365798982" ), ), // Fp2::NONRESIDUE^(((q^10) - 1) / 6) - QuadExt!( - MontFp!( - Fq, - "2203960485148121921418603742825762020974279258880205651967" - ), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("2203960485148121921418603742825762020974279258880205651967"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^11) - 1) / 6) - QuadExt!( + Fq2::new( MontFp!( - Fq, "18566938241244942414004596690298913868373833782006617400804628704885040364344" ), MontFp!( - Fq, "16165975933942742336466353786298926857552937457188450663314217659523851788715" ), ), diff --git a/bn254/src/fields/fq2.rs b/bn254/src/fields/fq2.rs index 906efd1..e0c80a5 100644 --- a/bn254/src/fields/fq2.rs +++ b/bn254/src/fields/fq2.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config { type Fp = Fq; /// NONRESIDUE = -1 - const NONRESIDUE: Fq = MontFp!(Fq, "-1"); + const NONRESIDUE: Fq = MontFp!("-1"); /// Coefficients for the Frobenius automorphism. const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ // NONRESIDUE**(((q^0) - 1) / 2) - MontFp!(Fq, "1"), + Fq::ONE, // NONRESIDUE**(((q^1) - 1) / 2) - MontFp!(Fq, "-1"), + MontFp!("-1"), ]; #[inline(always)] @@ -25,6 +25,3 @@ impl Fp2Config for Fq2Config { -(*fe) } } - -pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO); -pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO); diff --git a/bn254/src/fields/fq6.rs b/bn254/src/fields/fq6.rs index 92747f1..ef30442 100644 --- a/bn254/src/fields/fq6.rs +++ b/bn254/src/fields/fq6.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::*, MontFp, QuadExt}; +use ark_ff::{fields::*, MontFp}; use crate::*; @@ -11,113 +11,81 @@ impl Fp6Config for Fq6Config { type Fp2Config = Fq2Config; /// NONRESIDUE = U+9 - const NONRESIDUE: Fq2 = QuadExt!(MontFp!(Fq, "9"), MontFp!(Fq, "1")); + const NONRESIDUE: Fq2 = Fq2::new(MontFp!("9"), Fq::ONE); const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ // Fp2::NONRESIDUE^(((q^0) - 1) / 3) - QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^(((q^1) - 1) / 3) - QuadExt!( + Fq2::new( MontFp!( - Fq, "21575463638280843010398324269430826099269044274347216827212613867836435027261" ), MontFp!( - Fq, "10307601595873709700152284273816112264069230130616436755625194854815875713954" ), ), // Fp2::NONRESIDUE^(((q^2) - 1) / 3) - QuadExt!( + Fq2::new( MontFp!( - Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616" ), - MontFp!(Fq, "0"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^3) - 1) / 3) - QuadExt!( - MontFp!( - Fq, - "3772000881919853776433695186713858239009073593817195771773381919316419345261" - ), - MontFp!( - Fq, - "2236595495967245188281701248203181795121068902605861227855261137820944008926" - ), + Fq2::new( + MontFp!("3772000881919853776433695186713858239009073593817195771773381919316419345261"), + MontFp!("2236595495967245188281701248203181795121068902605861227855261137820944008926"), ), // Fp2::NONRESIDUE^(((q^4) - 1) / 3) - QuadExt!( - MontFp!( - Fq, - "2203960485148121921418603742825762020974279258880205651966" - ), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("2203960485148121921418603742825762020974279258880205651966"), + Fq::ZERO, ), // Fp2::NONRESIDUE^(((q^5) - 1) / 3) - QuadExt!( + Fq2::new( MontFp!( - Fq, "18429021223477853657660792034369865839114504446431234726392080002137598044644" ), - MontFp!( - Fq, - "9344045779998320333812420223237981029506012124075525679208581902008406485703" - ), + MontFp!("9344045779998320333812420223237981029506012124075525679208581902008406485703"), ), ]; const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3) - QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),), + Fq2::new(Fq::ONE, Fq::ZERO), // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3) - QuadExt!( + Fq2::new( + MontFp!("2581911344467009335267311115468803099551665605076196740867805258568234346338"), MontFp!( - Fq, - "2581911344467009335267311115468803099551665605076196740867805258568234346338" - ), - MontFp!( - Fq, "19937756971775647987995932169929341994314640652964949448313374472400716661030" ), ), // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3) - QuadExt!( - MontFp!( - Fq, - "2203960485148121921418603742825762020974279258880205651966" - ), - MontFp!(Fq, "0"), + Fq2::new( + MontFp!("2203960485148121921418603742825762020974279258880205651966"), + Fq::ZERO, ), // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3) - QuadExt!( + Fq2::new( + MontFp!("5324479202449903542726783395506214481928257762400643279780343368557297135718"), MontFp!( - Fq, - "5324479202449903542726783395506214481928257762400643279780343368557297135718" - ), - MontFp!( - Fq, "16208900380737693084919495127334387981393726419856888799917914180988844123039" ), ), // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3) - QuadExt!( + Fq2::new( MontFp!( - Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616" ), - MontFp!(Fq, "0"), + Fq::ZERO, ), // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3) - QuadExt!( + Fq2::new( MontFp!( - Fq, "13981852324922362344252311234282257507216387789820983642040889267519694726527" ), - MontFp!( - Fq, - "7629828391165209371577384193250820201684255241773809077146787135900891633097" - ), + MontFp!("7629828391165209371577384193250820201684255241773809077146787135900891633097"), ), ]; @@ -128,6 +96,6 @@ impl Fp6Config for Fq6Config { f.double_in_place().double_in_place().double_in_place(); let c0 = f.c0 + fe.c0 + Fq2Config::mul_fp_by_nonresidue(&fe.c1); let c1 = f.c1 + fe.c1 + fe.c0; - QuadExt!(c0, c1) + Fq2::new(c0, c1) } } diff --git a/bn254/src/fields/tests.rs b/bn254/src/fields/tests.rs index 7db7426..b49e20c 100644 --- a/bn254/src/fields/tests.rs +++ b/bn254/src/fields/tests.rs @@ -3,7 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::{BigInt, BigInteger, BigInteger256}, - fields::{FftField, Field, Fp6Config, PrimeField, SquareRootField}, + fields::{FftField, Field, Fp6Config, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; diff --git a/bw6_761/src/curves/g1.rs b/bw6_761/src/curves/g1.rs index c35a9a5..022a731 100644 --- a/bw6_761/src/curves/g1.rs +++ b/bw6_761/src/curves/g1.rs @@ -1,18 +1,18 @@ use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::{Affine, Projective}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; use crate::{Fq, Fr}; -pub type G1Affine = GroupAffine; -pub type G1Projective = GroupProjective; +pub type G1Affine = Affine; +pub type G1Projective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -30,19 +30,18 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804 - const COFACTOR_INV: Fr = MontFp!(Fr, "91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804"); + const COFACTOR_INV: Fr = MontFp!("91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = -1 - const COEFF_B: Fq = MontFp!(Fq, "-1"); + const COEFF_B: Fq = MontFp!("-1"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); #[inline(always)] fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField { use ark_ff::Zero; @@ -52,8 +51,8 @@ impl SWModelParameters for Parameters { /// G1_GENERATOR_X = /// 6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237"); +pub const G1_GENERATOR_X: Fq = MontFp!("6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237"); /// G1_GENERATOR_Y = /// 2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099"); +pub const G1_GENERATOR_Y: Fq = MontFp!("2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099"); diff --git a/bw6_761/src/curves/g2.rs b/bw6_761/src/curves/g2.rs index 7bd0205..31a2334 100644 --- a/bw6_761/src/curves/g2.rs +++ b/bw6_761/src/curves/g2.rs @@ -1,18 +1,18 @@ use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::{Affine, Projective}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; use crate::{Fq, Fr}; -pub type G2Affine = GroupAffine; -pub type G2Projective = GroupProjective; +pub type G2Affine = Affine; +pub type G2Projective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -30,19 +30,18 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124 - const COFACTOR_INV: Fr = MontFp!(Fr, "214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124"); + const COFACTOR_INV: Fr = MontFp!("214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 4 - const COEFF_B: Fq = MontFp!(Fq, "4"); + const COEFF_B: Fq = MontFp!("4"); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField { @@ -53,8 +52,8 @@ impl SWModelParameters for Parameters { /// G2_GENERATOR_X = /// 6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428 -pub const G2_GENERATOR_X: Fq = MontFp!(Fq, "6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428"); +pub const G2_GENERATOR_X: Fq = MontFp!("6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428"); /// G2_GENERATOR_Y = /// 562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041 -pub const G2_GENERATOR_Y: Fq = MontFp!(Fq, "562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041"); +pub const G2_GENERATOR_Y: Fq = MontFp!("562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041"); diff --git a/bw6_761/src/curves/tests.rs b/bw6_761/src/curves/tests.rs index 063d603..34ec0c2 100644 --- a/bw6_761/src/curves/tests.rs +++ b/bw6_761/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::{ - curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*, + curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine}; use ark_ff::{Field, One, PrimeField}; diff --git a/bw6_761/src/fields/fq.rs b/bw6_761/src/fields/fq.rs index 365e8d9..e891c55 100644 --- a/bw6_761/src/fields/fq.rs +++ b/bw6_761/src/fields/fq.rs @@ -1,10 +1,7 @@ -use ark_ff::fields::{Fp768, MontBackend, MontConfig, MontFp}; +use ark_ff::fields::{Fp768, MontBackend, MontConfig}; #[derive(MontConfig)] #[modulus = "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299"] #[generator = "2"] pub struct FqConfig; pub type Fq = Fp768>; - -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); diff --git a/bw6_761/src/fields/fq3.rs b/bw6_761/src/fields/fq3.rs index 91037d8..fe18682 100644 --- a/bw6_761/src/fields/fq3.rs +++ b/bw6_761/src/fields/fq3.rs @@ -1,12 +1,9 @@ use ark_ff::{ fields::fp3::{Fp3, Fp3Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{ - fields::{FQ_ONE, FQ_ZERO}, - Fq, -}; +use crate::Fq; pub type Fq3 = Fp3; @@ -17,7 +14,7 @@ impl Fp3Config for Fq3Config { /// NONRESIDUE = -4 // Fq3 = Fq\[u\]/u^3+4 - const NONRESIDUE: Fq = MontFp!(Fq, "-4"); + const NONRESIDUE: Fq = MontFp!("-4"); // (MODULUS^3 - 1) % 2^TWO_ADICITY == 0 const TWO_ADICITY: u32 = 1; @@ -64,24 +61,24 @@ impl Fp3Config for Fq3Config { ]; // NONRESIDUE^T % q - const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!( - MontFp!(Fq, "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068298"), - FQ_ZERO, - FQ_ZERO, + const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new( + MontFp!("6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068298"), + Fq::ZERO, + Fq::ZERO, ); // NQR ^ (MODULUS^i - 1)/3, i=0,1,2 with NQR = u = (0,1,0) const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), - MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), + Fq::ONE, + MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), + MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), ]; // NQR ^ (2*MODULUS^i - 2)/3, i=0,1,2 with NQR = u = (0,1,0) const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), - MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), + Fq::ONE, + MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), + MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), ]; #[inline(always)] diff --git a/bw6_761/src/fields/fq6.rs b/bw6_761/src/fields/fq6.rs index e3f1cab..056dd64 100644 --- a/bw6_761/src/fields/fq6.rs +++ b/bw6_761/src/fields/fq6.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp6_2over3::{Fp6, Fp6Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq3, Fq3Config}; pub type Fq6 = Fp6; @@ -13,14 +13,14 @@ impl Fp6Config for Fq6Config { type Fp3Config = Fq3Config; /// NONRESIDUE = (0, 1, 0) - const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const NONRESIDUE: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"), - MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), - MontFp!(Fq, "-1"), - MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), - MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"), + Fq::ONE, + MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"), + MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"), + MontFp!("-1"), + MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"), + MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"), ]; } diff --git a/bw6_761/src/fields/tests.rs b/bw6_761/src/fields/tests.rs index b1dc786..e4a0cf1 100644 --- a/bw6_761/src/fields/tests.rs +++ b/bw6_761/src/fields/tests.rs @@ -1,12 +1,12 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; use crate::*; -generate_field_test!(bw6_761; fq3; fq6; mont(12, 6); ); +generate_field_test!(bw6_761; fq3; fq6_2_on_3; false; mont(12, 6); ); generate_field_serialization_test!(bw6_761;); diff --git a/cp6_782/src/curves/g1.rs b/cp6_782/src/curves/g1.rs index c920a3f..caa1bea 100644 --- a/cp6_782/src/curves/g1.rs +++ b/cp6_782/src/curves/g1.rs @@ -1,18 +1,18 @@ use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, + short_weierstrass::{Affine, Projective}, }; use ark_ff::MontFp; use crate::{Fq, Fr}; -pub type G1Affine = GroupAffine; -pub type G1Projective = GroupProjective; +pub type G1Affine = Affine; +pub type G1Projective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -31,25 +31,24 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788 - const COFACTOR_INV: Fr = MontFp!(Fr, "163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788"); + const COFACTOR_INV: Fr = MontFp!("163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 5 - const COEFF_A: Fq = MontFp!(Fq, "5"); + const COEFF_A: Fq = MontFp!("5"); /// COEFF_B = 17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414 - const COEFF_B: Fq = MontFp!(Fq, "17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414"); + const COEFF_B: Fq = MontFp!("17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); } /// G1_GENERATOR_X = /// 5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646"); +pub const G1_GENERATOR_X: Fq = MontFp!("5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646"); /// G1_GENERATOR_Y = /// 7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443"); +pub const G1_GENERATOR_Y: Fq = MontFp!("7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443"); diff --git a/cp6_782/src/curves/g2.rs b/cp6_782/src/curves/g2.rs index 1b345f7..d891540 100644 --- a/cp6_782/src/curves/g2.rs +++ b/cp6_782/src/curves/g2.rs @@ -1,18 +1,18 @@ use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::CurveConfig, + short_weierstrass::{Affine, Projective, SWCurveConfig}, }; -use ark_ff::{CubicExt, MontFp}; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fq3, Fr, FQ_ZERO}; +use crate::{Fq, Fq3, Fr}; -pub type G2Affine = GroupAffine; -pub type G2Projective = GroupProjective; +pub type G2Affine = Affine; +pub type G2Projective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq3; type ScalarField = Fr; @@ -55,50 +55,49 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598 - const COFACTOR_INV: Fr = MontFp!(Fr, "45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598"); + const COFACTOR_INV: Fr = MontFp!("45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598"); } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = (0, 0, COEFF_A * TWIST^2) = (0, 0, 5) - const COEFF_A: Fq3 = CubicExt!(FQ_ZERO, FQ_ZERO, MontFp!(Fq, "5"),); + const COEFF_A: Fq3 = Fq3::new(Fq::ZERO, Fq::ZERO, MontFp!("5")); /// COEFF_B = (G1::COEFF_B * TWIST^3, 0, 0) = /// (7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612, /// 0, 0) - const COEFF_B: Fq3 = CubicExt!( - MontFp!(Fq, "7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612"), - FQ_ZERO, - FQ_ZERO, + const COEFF_B: Fq3 = Fq3::new( + MontFp!("7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612"), + Fq::ZERO, + Fq::ZERO, ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); } -const G2_GENERATOR_X: Fq3 = CubicExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); -const G2_GENERATOR_Y: Fq3 = CubicExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); +const G2_GENERATOR_X: Fq3 = Fq3::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); +const G2_GENERATOR_Y: Fq3 = Fq3::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); /// G2_GENERATOR_X_C0 = /// 13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338 -pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338"); +pub const G2_GENERATOR_X_C0: Fq = MontFp!("13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338"); /// G2_GENERATOR_X_C1 = /// 20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610 -pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610"); +pub const G2_GENERATOR_X_C1: Fq = MontFp!("20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610"); /// G2_GENERATOR_X_C2 = /// 3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980 -pub const G2_GENERATOR_X_C2: Fq = MontFp!(Fq, "3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980"); +pub const G2_GENERATOR_X_C2: Fq = MontFp!("3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980"); /// G2_GENERATOR_Y_C0 = /// 8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243 -pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243"); +pub const G2_GENERATOR_Y_C0: Fq = MontFp!("8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243"); /// G2_GENERATOR_Y_C1 = /// 3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752 -pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752"); +pub const G2_GENERATOR_Y_C1: Fq = MontFp!("3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752"); /// G2_GENERATOR_Y_C2 = /// 10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721 -pub const G2_GENERATOR_Y_C2: Fq = MontFp!(Fq, "10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721"); +pub const G2_GENERATOR_Y_C2: Fq = MontFp!("10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721"); diff --git a/cp6_782/src/curves/mod.rs b/cp6_782/src/curves/mod.rs index 712e665..64bab97 100644 --- a/cp6_782/src/curves/mod.rs +++ b/cp6_782/src/curves/mod.rs @@ -1,11 +1,11 @@ -use ark_ec::{models::SWModelParameters, PairingEngine}; +use ark_ec::{models::short_weierstrass::SWCurveConfig, PairingEngine}; use ark_ff::{ biginteger::BigInteger832, fields::{BitIteratorBE, Field}, - BigInt, CubicExt, One, + BigInt, One, }; -use crate::{Fq, Fq3, Fq6, Fr, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq3, Fq6, Fr}; pub mod g1; pub use self::g1::{G1Affine, G1Projective}; @@ -87,7 +87,7 @@ impl CP6_782 { let x = py_twist_squared; let y = gamma_old_rx - &old_ry - &gamma_twist_px; - let ell_rr_at_p = Fq6::new(x, y); + let ell_rr_at_p: Fq6 = Fq6::new(x, y); rx = gamma.square() - &old_rx.double(); ry = gamma * &(old_rx - &rx) - &old_ry; @@ -105,7 +105,7 @@ impl CP6_782 { let x = py_twist_squared; let y = gamma_qx - &qy - &gamma_twist_px; - let ell_rq_at_p = Fq6::new(x, y); + let ell_rq_at_p: Fq6 = Fq6::new(x, y); rx = gamma.square() - &old_rx - &qx; ry = gamma * &(old_rx - &rx) - &old_ry; @@ -153,7 +153,7 @@ impl CP6_782 { } /// TWIST = (0, 1, 0) -pub const TWIST: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); +pub const TWIST: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); /// ATE_IS_LOOP_COUNT_NEG = false pub const ATE_IS_LOOP_COUNT_NEG: bool = false; diff --git a/cp6_782/src/curves/tests.rs b/cp6_782/src/curves/tests.rs index f96607f..791098a 100644 --- a/cp6_782/src/curves/tests.rs +++ b/cp6_782/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::{ - curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*, + curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine}; use ark_ff::{Field, One, PrimeField}; diff --git a/cp6_782/src/fields/fq.rs b/cp6_782/src/fields/fq.rs index d5d1e5b..6d6c31f 100644 --- a/cp6_782/src/fields/fq.rs +++ b/cp6_782/src/fields/fq.rs @@ -1,10 +1,7 @@ -use ark_ff::fields::{Fp832, MontBackend, MontConfig, MontFp}; +use ark_ff::fields::{Fp832, MontBackend, MontConfig}; #[derive(MontConfig)] #[modulus = "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577"] #[generator = "13"] pub struct FqConfig; pub type Fq = Fp832>; - -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); diff --git a/cp6_782/src/fields/fq3.rs b/cp6_782/src/fields/fq3.rs index 116a4ae..3511abe 100644 --- a/cp6_782/src/fields/fq3.rs +++ b/cp6_782/src/fields/fq3.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp3::{Fp3, Fp3Config}, - CubicExt, Field, MontFp, + Field, MontFp, }; -use crate::{fields::FQ_ZERO, Fq}; +use crate::Fq; pub type Fq3 = Fp3; @@ -13,7 +13,7 @@ impl Fp3Config for Fq3Config { type Fp = Fq; /// NONRESIDUE = 13 - const NONRESIDUE: Fq = MontFp!(Fq, "13"); + const NONRESIDUE: Fq = MontFp!("13"); const TWO_ADICITY: u32 = 3; @@ -58,22 +58,22 @@ impl Fp3Config for Fq3Config { 0x2b87fda171, ]; - const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!( - MontFp!(Fq, "5759691735434357221228070840130186543101559976323700017469395641639510585333061695996665166662748527158637897523704071820491869715512532675375604262649010727161924084052120196921150869218319839231115277876207074651754402338718419191428"), - FQ_ZERO, - FQ_ZERO, + const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new( + MontFp!("5759691735434357221228070840130186543101559976323700017469395641639510585333061695996665166662748527158637897523704071820491869715512532675375604262649010727161924084052120196921150869218319839231115277876207074651754402338718419191428"), + Fq::ZERO, + Fq::ZERO, ); const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), - MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), + Fq::ONE, + MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), + MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), ]; const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), - MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), + Fq::ONE, + MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), + MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), ]; #[inline(always)] diff --git a/cp6_782/src/fields/fq6.rs b/cp6_782/src/fields/fq6.rs index bd6f229..f32601c 100644 --- a/cp6_782/src/fields/fq6.rs +++ b/cp6_782/src/fields/fq6.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp6_2over3::{Fp6, Fp6Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq3, Fq3Config}; pub type Fq6 = Fp6; @@ -13,14 +13,14 @@ impl Fp6Config for Fq6Config { type Fp3Config = Fq3Config; /// NONRESIDUE = (0, 1, 0). - const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const NONRESIDUE: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"), - MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), - MontFp!(Fq, "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"), - MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), - MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"), + Fq::ONE, + MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"), + MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"), + MontFp!("22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"), + MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"), + MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"), ]; } diff --git a/cp6_782/src/fields/tests.rs b/cp6_782/src/fields/tests.rs index 01aa430..b9e8970 100644 --- a/cp6_782/src/fields/tests.rs +++ b/cp6_782/src/fields/tests.rs @@ -1,12 +1,12 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; use crate::*; -generate_field_test!(cp6_782; fq3; fq6; mont(13, 6); ); +generate_field_test!(cp6_782; fq3; fq6_2_on_3; mont(13, 6); ); generate_field_serialization_test!(cp6_782;); diff --git a/curve-benches/benches/bls12_377.rs b/curve-benches/benches/bls12_377.rs index 96d1986..49bc9f1 100644 --- a/curve-benches/benches/bls12_377.rs +++ b/curve-benches/benches/bls12_377.rs @@ -8,7 +8,7 @@ use ark_bls12_377::{ use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{ biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, - BigInteger, Field, PrimeField, SquareRootField, UniformRand, + BigInteger, Field, PrimeField, UniformRand, }; mod g1 { diff --git a/curve-benches/benches/bls12_381.rs b/curve-benches/benches/bls12_381.rs index 080bff0..9090817 100644 --- a/curve-benches/benches/bls12_381.rs +++ b/curve-benches/benches/bls12_381.rs @@ -8,7 +8,7 @@ use ark_bls12_381::{ use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{ biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, - BigInteger, Field, PrimeField, SquareRootField, UniformRand, + BigInteger, Field, PrimeField, UniformRand, }; mod g1 { diff --git a/curve-benches/benches/bn254.rs b/curve-benches/benches/bn254.rs index a6f252d..1d6e2ca 100644 --- a/curve-benches/benches/bn254.rs +++ b/curve-benches/benches/bn254.rs @@ -6,9 +6,7 @@ use ark_bn254::{ G2Projective as G2, }; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{ - biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand, -}; +use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; mod g1 { use super::*; diff --git a/curve-benches/benches/bw6_761.rs b/curve-benches/benches/bw6_761.rs index 311875c..2e8dd42 100644 --- a/curve-benches/benches/bw6_761.rs +++ b/curve-benches/benches/bw6_761.rs @@ -8,7 +8,7 @@ use ark_bw6_761::{ use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{ biginteger::{BigInteger384 as FrRepr, BigInteger768 as FqRepr}, - BigInteger, Field, PrimeField, SquareRootField, UniformRand, + BigInteger, Field, PrimeField, UniformRand, }; mod g1 { diff --git a/curve-benches/benches/cp6_782.rs b/curve-benches/benches/cp6_782.rs index 290563f..58c7930 100644 --- a/curve-benches/benches/cp6_782.rs +++ b/curve-benches/benches/cp6_782.rs @@ -8,7 +8,7 @@ use ark_cp6_782::{ use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{ biginteger::{BigInteger384 as FrRepr, BigInteger832 as FqRepr}, - BigInteger, Field, PrimeField, SquareRootField, UniformRand, + BigInteger, Field, PrimeField, UniformRand, }; mod g1 { diff --git a/curve-benches/benches/ed_on_bls12_381.rs b/curve-benches/benches/ed_on_bls12_381.rs index 2c66671..e9b6893 100644 --- a/curve-benches/benches/ed_on_bls12_381.rs +++ b/curve-benches/benches/ed_on_bls12_381.rs @@ -3,9 +3,7 @@ use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::ProjectiveCurve; use ark_ed_on_bls12_381::{fq::Fq, fr::Fr, EdwardsAffine as GAffine, EdwardsProjective as G}; -use ark_ff::{ - biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand, -}; +use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; mod g { use super::*; diff --git a/curve-benches/benches/mnt4_298.rs b/curve-benches/benches/mnt4_298.rs index 947f17b..31e71ef 100644 --- a/curve-benches/benches/mnt4_298.rs +++ b/curve-benches/benches/mnt4_298.rs @@ -2,10 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{ - biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, - UniformRand, -}; +use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt4_298::{ fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, MNT4_298, diff --git a/curve-benches/benches/mnt4_753.rs b/curve-benches/benches/mnt4_753.rs index 1d15bb2..7bb384c 100644 --- a/curve-benches/benches/mnt4_753.rs +++ b/curve-benches/benches/mnt4_753.rs @@ -2,10 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{ - biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, - UniformRand, -}; +use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt4_753::{ fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, MNT4_753, diff --git a/curve-benches/benches/mnt6_298.rs b/curve-benches/benches/mnt6_298.rs index 006d797..d1974bb 100644 --- a/curve-benches/benches/mnt6_298.rs +++ b/curve-benches/benches/mnt6_298.rs @@ -2,10 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{ - biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, - UniformRand, -}; +use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt6_298::{ fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, MNT6_298, diff --git a/curve-benches/benches/mnt6_753.rs b/curve-benches/benches/mnt6_753.rs index 3310fd0..cf6034d 100644 --- a/curve-benches/benches/mnt6_753.rs +++ b/curve-benches/benches/mnt6_753.rs @@ -2,10 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{ - biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, - UniformRand, -}; +use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt6_753::{ fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, MNT6_753, diff --git a/curve-benches/benches/pallas.rs b/curve-benches/benches/pallas.rs index 0ffff41..e8bec42 100644 --- a/curve-benches/benches/pallas.rs +++ b/curve-benches/benches/pallas.rs @@ -2,9 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::ProjectiveCurve; -use ark_ff::{ - biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand, -}; +use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; use ark_pallas::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; mod g { diff --git a/curve-benches/benches/vesta.rs b/curve-benches/benches/vesta.rs index a0cd77a..2044fe1 100644 --- a/curve-benches/benches/vesta.rs +++ b/curve-benches/benches/vesta.rs @@ -2,9 +2,7 @@ use ark_curve_benches::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_ec::ProjectiveCurve; -use ark_ff::{ - biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand, -}; +use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; use ark_vesta::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; mod g { diff --git a/curve-benches/src/macros/ec.rs b/curve-benches/src/macros/ec.rs index fc37503..63a5230 100644 --- a/curve-benches/src/macros/ec.rs +++ b/curve-benches/src/macros/ec.rs @@ -223,6 +223,7 @@ macro_rules! ec_bench { } fn msm_131072(b: &mut $crate::bencher::Bencher) { + use ark_ec::msm::VariableBaseMSM; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; const SAMPLES: usize = 131072; @@ -234,7 +235,7 @@ macro_rules! ec_bench { .map(|_| Fr::rand(&mut rng).into_bigint()) .collect(); b.bench_n(1, |b| { - b.iter(|| ark_ec::msm::VariableBase::msm(&v, &scalars)); + b.iter(|| <$projective as VariableBaseMSM>::msm_bigint(&v, &scalars)); }) } diff --git a/curve-constraint-tests/src/lib.rs b/curve-constraint-tests/src/lib.rs index 349844d..623ad77 100755 --- a/curve-constraint-tests/src/lib.rs +++ b/curve-constraint-tests/src/lib.rs @@ -2,14 +2,14 @@ extern crate ark_relations; pub mod fields { - use ark_ff::{BitIteratorLE, Field, UniformRand}; + use ark_ff::{BigInteger, BitIteratorLE, Field, PrimeField, UniformRand}; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_std::{test_rng, vec::Vec}; pub fn field_test() -> Result<(), SynthesisError> where - F: Field, + F: PrimeField, ConstraintF: Field, AF: FieldVar, AF: TwoBitLookupGadget, @@ -176,10 +176,10 @@ pub mod fields { assert!(cs.is_satisfied().unwrap()); let bytes = r.to_non_unique_bytes()?; - assert_eq!(ark_ff::to_bytes!(r_native).unwrap(), bytes.value().unwrap()); + assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap()); assert!(cs.is_satisfied().unwrap()); let bytes = r.to_bytes()?; - assert_eq!(ark_ff::to_bytes!(r_native).unwrap(), bytes.value().unwrap()); + assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap()); assert!(cs.is_satisfied().unwrap()); let ab_false = &a + (AF::from(Boolean::Constant(false)) * b_native); @@ -231,8 +231,8 @@ pub mod fields { pub mod curves { use ark_ec::{ - short_weierstrass_jacobian::GroupProjective as SWProjective, - twisted_edwards_extended::GroupProjective as TEProjective, ProjectiveCurve, + short_weierstrass::Projective as SWProjective, twisted_edwards::Projective as TEProjective, + ProjectiveCurve, }; use ark_ff::{BitIteratorLE, Field, One, PrimeField}; use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; @@ -380,7 +380,7 @@ pub mod curves { pub fn sw_test() -> Result<(), SynthesisError> where - P: ark_ec::SWModelParameters, + P: ark_ec::models::short_weierstrass::SWCurveConfig, GG: CurveVar, ::BasePrimeField>, for<'a> &'a GG: GroupOpsBounds<'a, SWProjective

, GG>, { @@ -391,8 +391,6 @@ pub mod curves { AllocationMode::Constant, ]; for &mode in &modes { - use ark_ec::group::Group; - let mut rng = test_rng(); let cs = ConstraintSystem::<::BasePrimeField>::new_ref(); @@ -428,7 +426,7 @@ pub mod curves { gadget_a_zero.enforce_equal(&gadget_a)?; // Check doubling - let aa = Group::double(&a); + let aa = &a.double(); let aa_affine = aa.into_affine(); gadget_a.double_in_place()?; let aa_val = gadget_a.value()?.into_affine(); @@ -453,7 +451,7 @@ pub mod curves { pub fn te_test() -> Result<(), SynthesisError> where - P: ark_ec::TEModelParameters, + P: ark_ec::twisted_edwards::TECurveConfig, GG: CurveVar, ::BasePrimeField>, for<'a> &'a GG: GroupOpsBounds<'a, TEProjective

, GG>, { @@ -464,8 +462,6 @@ pub mod curves { AllocationMode::Constant, ]; for &mode in &modes { - use ark_ec::group::Group; - let mut rng = test_rng(); let cs = ConstraintSystem::<::BasePrimeField>::new_ref(); @@ -498,7 +494,7 @@ pub mod curves { assert!(cs.is_satisfied().unwrap()); // Check doubling - let aa = Group::double(&a); + let aa = &a.double(); let aa_affine = aa.into_affine(); gadget_a.double_in_place()?; let aa_val = gadget_a.value()?.into_affine(); diff --git a/ed_on_bls12_377/src/constraints/mod.rs b/ed_on_bls12_377/src/constraints/mod.rs index 889fa1e..2689059 100644 --- a/ed_on_bls12_377/src/constraints/mod.rs +++ b/ed_on_bls12_377/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_bls12_377`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_bls12_377/src/curves/mod.rs b/ed_on_bls12_377/src/curves/mod.rs index 8210521..f4caaa7 100644 --- a/ed_on_bls12_377/src/curves/mod.rs +++ b/ed_on_bls12_377/src/curves/mod.rs @@ -1,6 +1,6 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - twisted_edwards_extended::{GroupAffine, GroupProjective}, + models::CurveConfig, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::MontFp; @@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct EdwardsParameters; -impl ModelParameters for EdwardsParameters { +impl CurveConfig for EdwardsParameters { type BaseField = Fq; type ScalarField = Fr; @@ -24,23 +24,21 @@ impl ModelParameters for EdwardsParameters { /// COFACTOR_INV = /// 527778859339273151515551558673846658209717731602102048798421311598680340096 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "527778859339273151515551558673846658209717731602102048798421311598680340096" - ); + const COFACTOR_INV: Fr = + MontFp!("527778859339273151515551558673846658209717731602102048798421311598680340096"); } -impl TEModelParameters for EdwardsParameters { +impl TECurveConfig for EdwardsParameters { /// COEFF_A = -1 - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = 3021 - const COEFF_D: Fq = MontFp!(Fq, "3021"); + const COEFF_D: Fq = MontFp!("3021"); /// Generated randomly - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = EdwardsParameters; + type MontCurveConfig = EdwardsParameters; /// Multiplication by `a` is just negation. /// Is `a` 1 or -1? @@ -50,34 +48,26 @@ impl TEModelParameters for EdwardsParameters { } } -impl MontgomeryModelParameters for EdwardsParameters { +impl MontCurveConfig for EdwardsParameters { /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552 /// = 3990301581132929505568273333084066329187552697088022219156688740916631500114 - const COEFF_A: Fq = MontFp!( - Fq, - "3990301581132929505568273333084066329187552697088022219156688740916631500114" - ); + const COEFF_A: Fq = + MontFp!("3990301581132929505568273333084066329187552697088022219156688740916631500114"); /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD /// = 4454160168295440918680551605697480202188346638066041608778544715000777738925 - const COEFF_B: Fq = MontFp!( - Fq, - "4454160168295440918680551605697480202188346638066041608778544715000777738925" - ); + const COEFF_B: Fq = + MontFp!("4454160168295440918680551605697480202188346638066041608778544715000777738925"); - type TEModelParameters = EdwardsParameters; + type TECurveConfig = EdwardsParameters; } /// GENERATOR_X = /// 4497879464030519973909970603271755437257548612157028181994697785683032656389, -const GENERATOR_X: Fq = MontFp!( - Fq, - "4497879464030519973909970603271755437257548612157028181994697785683032656389" -); +const GENERATOR_X: Fq = + MontFp!("4497879464030519973909970603271755437257548612157028181994697785683032656389"); /// GENERATOR_Y = /// 4357141146396347889246900916607623952598927460421559113092863576544024487809 -const GENERATOR_Y: Fq = MontFp!( - Fq, - "4357141146396347889246900916607623952598927460421559113092863576544024487809" -); +const GENERATOR_Y: Fq = + MontFp!("4357141146396347889246900916607623952598927460421559113092863576544024487809"); diff --git a/ed_on_bls12_377/src/curves/tests.rs b/ed_on_bls12_377/src/curves/tests.rs index fe10970..0222891 100644 --- a/ed_on_bls12_377/src/curves/tests.rs +++ b/ed_on_bls12_377/src/curves/tests.rs @@ -1,6 +1,5 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; -use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_std::{rand::Rng, test_rng}; +use ark_algebra_test_templates::curves::*; +use ark_ec::AffineCurve; use crate::*; @@ -11,26 +10,6 @@ fn test_projective_curve() { edwards_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { let generator = EdwardsAffine::prime_subgroup_generator(); @@ -38,22 +17,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_bls12_377/src/fields/tests.rs b/ed_on_bls12_377/src/fields/tests.rs index ebcf9e7..31cca44 100644 --- a/ed_on_bls12_377/src/fields/tests.rs +++ b/ed_on_bls12_377/src/fields/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; use ark_ff::{ - fields::{Field, PrimeField, SquareRootField}, + fields::{Field, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; diff --git a/ed_on_bls12_381/src/constraints/mod.rs b/ed_on_bls12_381/src/constraints/mod.rs index eda12f8..c6680fa 100644 --- a/ed_on_bls12_381/src/constraints/mod.rs +++ b/ed_on_bls12_381/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_bls12_381`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_bls12_381/src/curves/mod.rs b/ed_on_bls12_381/src/curves/mod.rs index b8ebaec..4194bee 100644 --- a/ed_on_bls12_381/src/curves/mod.rs +++ b/ed_on_bls12_381/src/curves/mod.rs @@ -1,10 +1,7 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - short_weierstrass_jacobian::{ - GroupAffine as SWGroupAffine, GroupProjective as SWGroupProjective, - }, - twisted_edwards_extended::{GroupAffine, GroupProjective}, - SWModelParameters, + models::CurveConfig, + short_weierstrass::{self, SWCurveConfig}, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::MontFp; @@ -13,10 +10,10 @@ use crate::{Fq, Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; -pub type SWAffine = SWGroupAffine; -pub type SWProjective = SWGroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; +pub type SWAffine = short_weierstrass::Affine; +pub type SWProjective = short_weierstrass::Projective; /// `JubJub` is a twisted Edwards curve. These curves have equations of the /// form: ax² + y² = 1 - dx²y². @@ -56,7 +53,7 @@ pub struct JubjubParameters; pub type EdwardsParameters = JubjubParameters; pub type SWParameters = JubjubParameters; -impl ModelParameters for JubjubParameters { +impl CurveConfig for JubjubParameters { type BaseField = Fq; type ScalarField = Fr; @@ -65,26 +62,22 @@ impl ModelParameters for JubjubParameters { /// COFACTOR^(-1) mod r = /// 819310549611346726241370945440405716213240158234039660170669895299022906775 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "819310549611346726241370945440405716213240158234039660170669895299022906775" - ); + const COFACTOR_INV: Fr = + MontFp!("819310549611346726241370945440405716213240158234039660170669895299022906775"); } -impl TEModelParameters for JubjubParameters { +impl TECurveConfig for JubjubParameters { /// COEFF_A = -1 - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = (10240/10241) mod q - const COEFF_D: Fq = MontFp!( - Fq, - "19257038036680949359750312669786877991949435402254120286184196891950884077233" - ); + const COEFF_D: Fq = + MontFp!("19257038036680949359750312669786877991949435402254120286184196891950884077233"); /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = JubjubParameters; + type MontCurveConfig = JubjubParameters; /// Multiplication by `a` is simply negation here. #[inline(always)] @@ -93,52 +86,39 @@ impl TEModelParameters for JubjubParameters { } } -impl MontgomeryModelParameters for JubjubParameters { +impl MontCurveConfig for JubjubParameters { /// COEFF_A = 40962 - const COEFF_A: Fq = MontFp!(Fq, "40962"); + const COEFF_A: Fq = MontFp!("40962"); /// COEFF_B = -40964 - const COEFF_B: Fq = MontFp!(Fq, "-40964"); + const COEFF_B: Fq = MontFp!("-40964"); - type TEModelParameters = JubjubParameters; + type TECurveConfig = JubjubParameters; } -const GENERATOR_X: Fq = MontFp!( - Fq, - "8076246640662884909881801758704306714034609987455869804520522091855516602923" -); +const GENERATOR_X: Fq = + MontFp!("8076246640662884909881801758704306714034609987455869804520522091855516602923"); -const GENERATOR_Y: Fq = MontFp!( - Fq, - "13262374693698910701929044844600465831413122818447359594527400194675274060458" -); +const GENERATOR_Y: Fq = + MontFp!("13262374693698910701929044844600465831413122818447359594527400194675274060458"); -impl SWModelParameters for JubjubParameters { +impl SWCurveConfig for JubjubParameters { /// COEFF_A = 52296097456646850916096512823759002727550416093741407922227928430486925478210 - const COEFF_A: Self::BaseField = MontFp!( - Fq, - "52296097456646850916096512823759002727550416093741407922227928430486925478210" - ); + const COEFF_A: Self::BaseField = + MontFp!("52296097456646850916096512823759002727550416093741407922227928430486925478210"); /// COEFF_B = 48351165704696163914533707656614864561753505123260775585269522553028192119009 - const COEFF_B: Self::BaseField = MontFp!( - Fq, - "48351165704696163914533707656614864561753505123260775585269522553028192119009" - ); + const COEFF_B: Self::BaseField = + MontFp!("48351165704696163914533707656614864561753505123260775585269522553028192119009"); /// generators - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (SW_GENERATOR_X, SW_GENERATOR_Y); + const GENERATOR: SWAffine = SWAffine::new_unchecked(SW_GENERATOR_X, SW_GENERATOR_Y); } /// x coordinate for SW curve generator -const SW_GENERATOR_X: Fq = MontFp!( - Fq, - "33835869156188682335217394949746694649676633840125476177319971163079011318731" -); +const SW_GENERATOR_X: Fq = + MontFp!("33835869156188682335217394949746694649676633840125476177319971163079011318731"); /// y coordinate for SW curve generator -const SW_GENERATOR_Y: Fq = MontFp!( - Fq, - "43777270878440091394432848052353307184915192688165709016756678962558652055320" -); +const SW_GENERATOR_Y: Fq = + MontFp!("43777270878440091394432848052353307184915192688165709016756678962558652055320"); diff --git a/ed_on_bls12_381/src/curves/tests.rs b/ed_on_bls12_381/src/curves/tests.rs index c96802d..207331f 100644 --- a/ed_on_bls12_381/src/curves/tests.rs +++ b/ed_on_bls12_381/src/curves/tests.rs @@ -1,7 +1,7 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; +use ark_algebra_test_templates::curves::*; use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_ff::{bytes::FromBytes, Zero}; -use ark_std::{rand::Rng, str::FromStr, test_rng}; +use ark_ff::Zero; +use ark_std::str::FromStr; use crate::*; @@ -14,31 +14,6 @@ fn test_projective_curve() { sw_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - - let c = rng.gen(); - let d = rng.gen(); - - for _i in 0..100 { - group_test::(a, b); - group_test::(c, d); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { // edward curve @@ -52,22 +27,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_scalar_multiplication() { let f1 = Fr::from_str( @@ -98,19 +57,6 @@ fn test_scalar_multiplication() { assert_eq!(f1g.mul(f2).into_affine(), f1f2g); } -#[test] -fn test_bytes() { - let g_from_repr = EdwardsAffine::from_str( - "(1158870117176967269192899343636553522971009777237254192973081388797299308391, \ - 36933624999642413792569726058244472742169727126562409632889593958355839948294)", - ) - .unwrap(); - - let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap(); - let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap(); - assert_eq!(g_from_repr, g); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_bls12_381/src/fields/tests.rs b/ed_on_bls12_381/src/fields/tests.rs index f267fa2..483bc66 100644 --- a/ed_on_bls12_381/src/fields/tests.rs +++ b/ed_on_bls12_381/src/fields/tests.rs @@ -3,8 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::BigInteger256 as BigInteger, - bytes::{FromBytes, ToBytes}, - fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField}, + fields::{Field, LegendreSymbol::*, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -298,22 +297,6 @@ fn test_fq_legendre() { assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); } -#[test] -fn test_fq_bytes() { - let f1_from_repr = Fq::from(BigInteger::new([ - 0xab8a2535947d1a77, - 0x9ba74cbfda0bbcda, - 0xe928b59724d60baf, - 0x1cccaaeb9bb1680a, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fq::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} - #[test] fn test_fr_add() { let f1 = Fr::from(BigInteger::new([ @@ -360,22 +343,6 @@ fn test_fr_mul() { assert_eq!(f1 * &f2, f3); } -#[test] -fn test_fr_bytes() { - let f1_from_repr = Fr::from(BigInteger::new([ - 0xc81265fb4130fe0c, - 0xb308836c14e22279, - 0x699e887f96bff372, - 0x84ecc7e76c11ad, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fr::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} - #[test] fn test_fr_from_str() { let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0])); diff --git a/ed_on_bls12_381_bandersnatch/src/constraints/mod.rs b/ed_on_bls12_381_bandersnatch/src/constraints/mod.rs index d107fa4..0654067 100644 --- a/ed_on_bls12_381_bandersnatch/src/constraints/mod.rs +++ b/ed_on_bls12_381_bandersnatch/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_bandersnatch`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_bls12_381_bandersnatch/src/curves/mod.rs b/ed_on_bls12_381_bandersnatch/src/curves/mod.rs index 6cb033e..d1b039e 100644 --- a/ed_on_bls12_381_bandersnatch/src/curves/mod.rs +++ b/ed_on_bls12_381_bandersnatch/src/curves/mod.rs @@ -1,10 +1,7 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - short_weierstrass_jacobian::{ - GroupAffine as SWGroupAffine, GroupProjective as SWGroupProjective, - }, - twisted_edwards_extended::{GroupAffine, GroupProjective}, - SWModelParameters, + models::CurveConfig, + short_weierstrass::{self, SWCurveConfig}, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::{Field, MontFp}; @@ -13,11 +10,11 @@ use crate::{Fq, Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; -pub type SWAffine = SWGroupAffine; -pub type SWProjective = SWGroupProjective; +pub type SWAffine = short_weierstrass::Affine; +pub type SWProjective = short_weierstrass::Projective; /// `bandersnatch` is a twisted Edwards curve. These curves have equations of /// the form: ax² + y² = 1 - dx²y². @@ -57,7 +54,7 @@ pub struct BandersnatchParameters; pub type EdwardsParameters = BandersnatchParameters; pub type SWParameters = BandersnatchParameters; -impl ModelParameters for BandersnatchParameters { +impl CurveConfig for BandersnatchParameters { type BaseField = Fq; type ScalarField = Fr; @@ -66,28 +63,23 @@ impl ModelParameters for BandersnatchParameters { /// COFACTOR^(-1) mod r = /// 9831726595336160714896451345284868594481866920080427688839802480047265754601 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "9831726595336160714896451345284868594481866920080427688839802480047265754601" - ); + const COFACTOR_INV: Fr = + MontFp!("9831726595336160714896451345284868594481866920080427688839802480047265754601"); } -impl TEModelParameters for BandersnatchParameters { +impl TECurveConfig for BandersnatchParameters { /// COEFF_A = -5 - const COEFF_A: Fq = MontFp!(Fq, "-5"); + const COEFF_A: Fq = MontFp!("-5"); /// COEFF_D = (138827208126141220649022263972958607803/ /// 171449701953573178309673572579671231137) mod q - const COEFF_D: Fq = MontFp!( - Fq, - "45022363124591815672509500913686876175488063829319466900776701791074614335719" - ); + const COEFF_D: Fq = + MontFp!("45022363124591815672509500913686876175488063829319466900776701791074614335719"); /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (TE_GENERATOR_X, TE_GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(TE_GENERATOR_X, TE_GENERATOR_Y); - type MontgomeryModelParameters = BandersnatchParameters; + type MontCurveConfig = BandersnatchParameters; /// Multiplication by `a` is multiply by `-5`. #[inline(always)] @@ -97,20 +89,16 @@ impl TEModelParameters for BandersnatchParameters { } } -impl MontgomeryModelParameters for BandersnatchParameters { +impl MontCurveConfig for BandersnatchParameters { /// COEFF_A = 29978822694968839326280996386011761570173833766074948509196803838190355340952 - const COEFF_A: Fq = MontFp!( - Fq, - "29978822694968839326280996386011761570173833766074948509196803838190355340952" - ); + const COEFF_A: Fq = + MontFp!("29978822694968839326280996386011761570173833766074948509196803838190355340952"); /// COEFF_B = 25465760566081946422412445027709227188579564747101592991722834452325077642517 - const COEFF_B: Fq = MontFp!( - Fq, - "25465760566081946422412445027709227188579564747101592991722834452325077642517" - ); + const COEFF_B: Fq = + MontFp!("25465760566081946422412445027709227188579564747101592991722834452325077642517"); - type TEModelParameters = BandersnatchParameters; + type TECurveConfig = BandersnatchParameters; } // The TE form generator is generated following Zcash's fashion: @@ -123,43 +111,30 @@ impl MontgomeryModelParameters for BandersnatchParameters { // /// x coordinate for TE curve generator -const TE_GENERATOR_X: Fq = MontFp!( - Fq, - "18886178867200960497001835917649091219057080094937609519140440539760939937304" -); +const TE_GENERATOR_X: Fq = + MontFp!("18886178867200960497001835917649091219057080094937609519140440539760939937304"); /// y coordinate for TE curve generator -const TE_GENERATOR_Y: Fq = MontFp!( - Fq, - "19188667384257783945677642223292697773471335439753913231509108946878080696678" -); +const TE_GENERATOR_Y: Fq = + MontFp!("19188667384257783945677642223292697773471335439753913231509108946878080696678"); /// x coordinate for SW curve generator -const SW_GENERATOR_X: Fq = MontFp!( - Fq, - "30900340493481298850216505686589334086208278925799850409469406976849338430199" -); +const SW_GENERATOR_X: Fq = + MontFp!("30900340493481298850216505686589334086208278925799850409469406976849338430199"); /// y coordinate for SW curve generator -const SW_GENERATOR_Y: Fq = MontFp!( - Fq, - "12663882780877899054958035777720958383845500985908634476792678820121468453298" -); +const SW_GENERATOR_Y: Fq = + MontFp!("12663882780877899054958035777720958383845500985908634476792678820121468453298"); -impl SWModelParameters for BandersnatchParameters { +impl SWCurveConfig for BandersnatchParameters { /// COEFF_A = 10773120815616481058602537765553212789256758185246796157495669123169359657269 - const COEFF_A: Self::BaseField = MontFp!( - Fq, - "10773120815616481058602537765553212789256758185246796157495669123169359657269" - ); + const COEFF_A: Self::BaseField = + MontFp!("10773120815616481058602537765553212789256758185246796157495669123169359657269"); /// COEFF_B = 29569587568322301171008055308580903175558631321415017492731745847794083609535 - const COEFF_B: Self::BaseField = MontFp!( - Fq, - "29569587568322301171008055308580903175558631321415017492731745847794083609535" - ); + const COEFF_B: Self::BaseField = + MontFp!("29569587568322301171008055308580903175558631321415017492731745847794083609535"); /// generators - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (SW_GENERATOR_X, SW_GENERATOR_Y); + const GENERATOR: SWAffine = SWAffine::new_unchecked(SW_GENERATOR_X, SW_GENERATOR_Y); } diff --git a/ed_on_bls12_381_bandersnatch/src/curves/tests.rs b/ed_on_bls12_381_bandersnatch/src/curves/tests.rs index d031700..d836f64 100644 --- a/ed_on_bls12_381_bandersnatch/src/curves/tests.rs +++ b/ed_on_bls12_381_bandersnatch/src/curves/tests.rs @@ -1,7 +1,7 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; +use ark_algebra_test_templates::curves::*; use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_ff::{bytes::FromBytes, Zero}; -use ark_std::{rand::Rng, str::FromStr, test_rng}; +use ark_ff::Zero; +use ark_std::str::FromStr; use crate::*; @@ -14,31 +14,6 @@ fn test_projective_curve() { sw_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - - let c = rng.gen(); - let d = rng.gen(); - - for _i in 0..100 { - group_test::(a, b); - group_test::(c, d); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { // edward curve @@ -52,31 +27,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - // edward curve - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); - - // weierstrass curve - let mut rng = test_rng(); - let a: SWProjective = rng.gen(); - let b: SWProjective = rng.gen(); - let a_b = { (a + &b).double().double() }; - let a_b2 = (a + &b).double().double(); - assert_eq!(a_b.into_affine(), a_b2.into_affine()); -} - #[test] fn test_scalar_multiplication() { let f1 = Fr::from_str( @@ -107,19 +57,6 @@ fn test_scalar_multiplication() { assert_eq!(f1g.mul(f2).into_affine(), f1f2g); } -#[test] -fn test_bytes() { - let g_from_repr = EdwardsAffine::from_str( - "(29627151942733444043031429156003786749302466371339015363120350521834195802525, \ - 27488387519748396681411951718153463804682561779047093991696427532072116857978)", - ) - .unwrap(); - - let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap(); - let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap(); - assert_eq!(g_from_repr, g); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_bls12_381_bandersnatch/src/fields/tests.rs b/ed_on_bls12_381_bandersnatch/src/fields/tests.rs index 245d02b..b3cb56a 100644 --- a/ed_on_bls12_381_bandersnatch/src/fields/tests.rs +++ b/ed_on_bls12_381_bandersnatch/src/fields/tests.rs @@ -3,8 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::BigInteger256 as BigInteger, - bytes::{FromBytes, ToBytes}, - fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField}, + fields::{Field, LegendreSymbol::*, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -298,22 +297,6 @@ fn test_fq_legendre() { assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); } -#[test] -fn test_fq_bytes() { - let f1_from_repr = Fq::from(BigInteger::new([ - 0xab8a2535947d1a77, - 0x9ba74cbfda0bbcda, - 0xe928b59724d60baf, - 0x1cccaaeb9bb1680a, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fq::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} - #[test] fn test_fr_add() { let f1 = Fr::from(BigInteger::new([ @@ -360,22 +343,6 @@ fn test_fr_mul() { assert_eq!(f1 * &f2, f3); } -#[test] -fn test_fr_bytes() { - let f1_from_repr = Fr::from(BigInteger::new([ - 0xc81265fb4130fe0c, - 0xb308836c14e22279, - 0x699e887f96bff372, - 0x84ecc7e76c11ad, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fr::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} - #[test] fn test_fr_from_str() { let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0])); diff --git a/ed_on_bn254/src/constraints/mod.rs b/ed_on_bn254/src/constraints/mod.rs index c61c7dc..65179b5 100644 --- a/ed_on_bn254/src/constraints/mod.rs +++ b/ed_on_bn254/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_bn254`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_bn254/src/curves/mod.rs b/ed_on_bn254/src/curves/mod.rs index eb475e4..89a94ee 100644 --- a/ed_on_bn254/src/curves/mod.rs +++ b/ed_on_bn254/src/curves/mod.rs @@ -1,16 +1,16 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - twisted_edwards_extended::{GroupAffine, GroupProjective}, + models::CurveConfig, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; use crate::{Fq, Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; /// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the /// form: ax² + y² = 1 + dx²y². @@ -22,7 +22,7 @@ pub type EdwardsProjective = GroupProjective; #[derive(Clone, Default, PartialEq, Eq)] pub struct EdwardsParameters; -impl ModelParameters for EdwardsParameters { +impl CurveConfig for EdwardsParameters { type BaseField = Fq; type ScalarField = Fr; @@ -31,15 +31,13 @@ impl ModelParameters for EdwardsParameters { /// COFACTOR^(-1) mod r = /// 2394026564107420727433200628387514462817212225638746351800188703329891451411 - const COFACTOR_INV: Fr = MontFp!( - Fr, - "2394026564107420727433200628387514462817212225638746351800188703329891451411" - ); + const COFACTOR_INV: Fr = + MontFp!("2394026564107420727433200628387514462817212225638746351800188703329891451411"); } -impl TEModelParameters for EdwardsParameters { +impl TECurveConfig for EdwardsParameters { /// COEFF_A = 1 - const COEFF_A: Fq = MontFp!(Fq, "1"); + const COEFF_A: Fq = Fq::ONE; #[inline(always)] fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { @@ -48,32 +46,26 @@ impl TEModelParameters for EdwardsParameters { /// COEFF_D = 168696/168700 mod q /// = 9706598848417545097372247223557719406784115219466060233080913168975159366771 - const COEFF_D: Fq = MontFp!( - Fq, - "9706598848417545097372247223557719406784115219466060233080913168975159366771" - ); + const COEFF_D: Fq = + MontFp!("9706598848417545097372247223557719406784115219466060233080913168975159366771"); /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = EdwardsParameters; + type MontCurveConfig = EdwardsParameters; } -impl MontgomeryModelParameters for EdwardsParameters { +impl MontCurveConfig for EdwardsParameters { /// COEFF_A = 168698 - const COEFF_A: Fq = MontFp!(Fq, "168698"); + const COEFF_A: Fq = MontFp!("168698"); /// COEFF_B = 168700 - const COEFF_B: Fq = MontFp!(Fq, "168700"); + const COEFF_B: Fq = MontFp!("168700"); - type TEModelParameters = EdwardsParameters; + type TECurveConfig = EdwardsParameters; } -const GENERATOR_X: Fq = MontFp!( - Fq, - "19698561148652590122159747500897617769866003486955115824547446575314762165298" -); +const GENERATOR_X: Fq = + MontFp!("19698561148652590122159747500897617769866003486955115824547446575314762165298"); -const GENERATOR_Y: Fq = MontFp!( - Fq, - "19298250018296453272277890825869354524455968081175474282777126169995084727839" -); +const GENERATOR_Y: Fq = + MontFp!("19298250018296453272277890825869354524455968081175474282777126169995084727839"); diff --git a/ed_on_bn254/src/curves/tests.rs b/ed_on_bn254/src/curves/tests.rs index f3d220e..97943b0 100644 --- a/ed_on_bn254/src/curves/tests.rs +++ b/ed_on_bn254/src/curves/tests.rs @@ -1,7 +1,7 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; +use ark_algebra_test_templates::curves::*; use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_ff::{bytes::FromBytes, Zero}; -use ark_std::{rand::Rng, str::FromStr, test_rng}; +use ark_ff::Zero; +use ark_std::str::FromStr; use crate::*; @@ -12,26 +12,6 @@ fn test_projective_curve() { edwards_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { let generator = EdwardsAffine::prime_subgroup_generator(); @@ -39,22 +19,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_scalar_multiplication() { let f1 = Fr::from_str( @@ -85,19 +49,6 @@ fn test_scalar_multiplication() { assert_eq!(f1g.mul(f2).into_affine(), f1f2g); } -#[test] -fn test_bytes() { - let g_from_repr = EdwardsAffine::from_str( - "(15863623088992515880085393097393553694825975317405843389771115419751650972659, \ - 16950150798460657717958625567821834550301663161624707787222815936182638968203)", - ) - .unwrap(); - - let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap(); - let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap(); - assert_eq!(g_from_repr, g); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_bn254/src/fields/tests.rs b/ed_on_bn254/src/fields/tests.rs index 861a07b..91d01c6 100644 --- a/ed_on_bn254/src/fields/tests.rs +++ b/ed_on_bn254/src/fields/tests.rs @@ -3,8 +3,7 @@ use ark_algebra_test_templates::{ }; use ark_ff::{ biginteger::BigInteger256 as BigInteger, - bytes::{FromBytes, ToBytes}, - fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField}, + fields::{Field, LegendreSymbol::*, PrimeField}, One, UniformRand, Zero, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -293,22 +292,6 @@ fn test_fq_legendre() { assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); } -#[test] -fn test_fq_bytes() { - let f1_from_repr = Fq::from(BigInteger::new([ - 0xab8a2535947d1a77, - 0x9ba74cbfda0bbcda, - 0xe928b59724d60baf, - 0x1cccaaeb9bb1680a, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fq::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} - #[test] fn test_fr_add() { let f1 = Fr::from(BigInteger::new([ @@ -354,21 +337,6 @@ fn test_fr_mul() { ])); assert_eq!(f1 * &f2, f3); } -#[test] -fn test_fr_bytes() { - let f1_from_repr = Fr::from(BigInteger::new([ - 0xc81265fb4130fe0c, - 0xb308836c14e22279, - 0x699e887f96bff372, - 0x84ecc7e76c11ad, - ])); - - let mut f1_bytes = [0u8; 32]; - f1_from_repr.write(f1_bytes.as_mut()).unwrap(); - - let f1 = Fr::read(f1_bytes.as_ref()).unwrap(); - assert_eq!(f1_from_repr, f1); -} #[test] fn test_fr_from_str() { diff --git a/ed_on_bw6_761/src/constraints/mod.rs b/ed_on_bw6_761/src/constraints/mod.rs index bc3d0ec..6d58aa7 100644 --- a/ed_on_bw6_761/src/constraints/mod.rs +++ b/ed_on_bw6_761/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_bw6_761`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_cp6_782/src/constraints/mod.rs b/ed_on_cp6_782/src/constraints/mod.rs index e97a180..06f5a47 100644 --- a/ed_on_cp6_782/src/constraints/mod.rs +++ b/ed_on_cp6_782/src/constraints/mod.rs @@ -2,7 +2,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_cp6_782`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_cp6_782/src/curves/mod.rs b/ed_on_cp6_782/src/curves/mod.rs index ec8a16d..0955a25 100644 --- a/ed_on_cp6_782/src/curves/mod.rs +++ b/ed_on_cp6_782/src/curves/mod.rs @@ -1,6 +1,6 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - twisted_edwards_extended::{GroupAffine, GroupProjective}, + models::CurveConfig, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::MontFp; @@ -9,13 +9,13 @@ use crate::{Fq, Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct EdwardsParameters; -impl ModelParameters for EdwardsParameters { +impl CurveConfig for EdwardsParameters { type BaseField = Fq; type ScalarField = Fr; @@ -24,20 +24,20 @@ impl ModelParameters for EdwardsParameters { /// COFACTOR^(-1) mod r = /// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560 - const COFACTOR_INV: Fr = MontFp!(Fr, "12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560"); + const COFACTOR_INV: Fr = MontFp!("12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560"); } -impl TEModelParameters for EdwardsParameters { +impl TECurveConfig for EdwardsParameters { /// COEFF_A = -1 = - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = 79743 - const COEFF_D: Fq = MontFp!(Fq, "79743"); + const COEFF_D: Fq = MontFp!("79743"); /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = EdwardsParameters; + type MontCurveConfig = EdwardsParameters; /// Multiplication by `a` is just negation. #[inline(always)] @@ -46,20 +46,20 @@ impl TEModelParameters for EdwardsParameters { } } -impl MontgomeryModelParameters for EdwardsParameters { +impl MontCurveConfig for EdwardsParameters { /// COEFF_A = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535 - const COEFF_A: Fq = MontFp!(Fq, "90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765"); + const COEFF_A: Fq = MontFp!("90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765"); /// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA - const COEFF_B: Fq = MontFp!(Fq, "168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410"); + const COEFF_B: Fq = MontFp!("168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410"); - type TEModelParameters = EdwardsParameters; + type TECurveConfig = EdwardsParameters; } /// GENERATOR_X = /// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127 -const GENERATOR_X: Fq = MontFp!(Fq, "174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127"); +const GENERATOR_X: Fq = MontFp!("174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127"); /// GENERATOR_Y = /// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833 -const GENERATOR_Y: Fq = MontFp!(Fq, "208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833"); +const GENERATOR_Y: Fq = MontFp!("208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833"); diff --git a/ed_on_cp6_782/src/curves/tests.rs b/ed_on_cp6_782/src/curves/tests.rs index fe10970..0222891 100644 --- a/ed_on_cp6_782/src/curves/tests.rs +++ b/ed_on_cp6_782/src/curves/tests.rs @@ -1,6 +1,5 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; -use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_std::{rand::Rng, test_rng}; +use ark_algebra_test_templates::curves::*; +use ark_ec::AffineCurve; use crate::*; @@ -11,26 +10,6 @@ fn test_projective_curve() { edwards_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { let generator = EdwardsAffine::prime_subgroup_generator(); @@ -38,22 +17,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_cp6_782/src/fields/tests.rs b/ed_on_cp6_782/src/fields/tests.rs index c1a208b..ed0bbf8 100644 --- a/ed_on_cp6_782/src/fields/tests.rs +++ b/ed_on_cp6_782/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/ed_on_mnt4_298/src/constraints/mod.rs b/ed_on_mnt4_298/src/constraints/mod.rs index ed8b2b7..76607f0 100644 --- a/ed_on_mnt4_298/src/constraints/mod.rs +++ b/ed_on_mnt4_298/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_mnt4_298`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_mnt4_298/src/curves/mod.rs b/ed_on_mnt4_298/src/curves/mod.rs index 9066d3b..293ddb6 100644 --- a/ed_on_mnt4_298/src/curves/mod.rs +++ b/ed_on_mnt4_298/src/curves/mod.rs @@ -1,6 +1,6 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - twisted_edwards_extended::{GroupAffine, GroupProjective}, + models::CurveConfig, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::MontFp; @@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct EdwardsParameters; -impl ModelParameters for EdwardsParameters { +impl CurveConfig for EdwardsParameters { type BaseField = Fq; type ScalarField = Fr; @@ -25,7 +25,6 @@ impl ModelParameters for EdwardsParameters { /// COFACTOR_INV (mod r) = /// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158 const COFACTOR_INV: Fr = MontFp!( - Fr, "29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158" ); } @@ -35,23 +34,23 @@ impl ModelParameters for EdwardsParameters { // R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876 // R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545 -impl TEModelParameters for EdwardsParameters { +impl TECurveConfig for EdwardsParameters { /// COEFF_A = -1 /// Needs to be in the Montgomery residue form in Fq /// I.e., -1 * R for Fq /// = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261 - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = 4212 /// Needs to be in the Montgomery residue form in Fq /// I.e., 4212 * R for Fq /// = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000 - const COEFF_D: Fq = MontFp!(Fq, "4212"); + const COEFF_D: Fq = MontFp!("4212"); /// Generated randomly - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = EdwardsParameters; + type MontCurveConfig = EdwardsParameters; /// Multiplication by `a` is just negation. #[inline(always)] @@ -60,26 +59,24 @@ impl TEModelParameters for EdwardsParameters { } } -impl MontgomeryModelParameters for EdwardsParameters { +impl MontCurveConfig for EdwardsParameters { /// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204 - const COEFF_A: Fq = MontFp!(Fq, "203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204"); + const COEFF_A: Fq = MontFp!("203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204"); /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931 - const COEFF_B: Fq = MontFp!(Fq, "272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931"); + const COEFF_B: Fq = MontFp!("272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931"); - type TEModelParameters = EdwardsParameters; + type TECurveConfig = EdwardsParameters; } /// GENERATOR_X = /// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227 const GENERATOR_X: Fq = MontFp!( - Fq, "282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227" ); /// GENERATOR_Y = /// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703 const GENERATOR_Y: Fq = MontFp!( - Fq, "452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703" ); diff --git a/ed_on_mnt4_298/src/curves/tests.rs b/ed_on_mnt4_298/src/curves/tests.rs index 02a0b15..bcc49a6 100644 --- a/ed_on_mnt4_298/src/curves/tests.rs +++ b/ed_on_mnt4_298/src/curves/tests.rs @@ -1,37 +1,8 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; -use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_std::{rand::Rng, test_rng}; +use ark_algebra_test_templates::curves::*; +use ark_ec::AffineCurve; use crate::*; -#[test] -fn test_projective_curve() { - curve_tests::(); - - edwards_tests::(); -} - -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - - for _i in 0..100 { - group_test::(a, b); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { let generator = EdwardsAffine::prime_subgroup_generator(); @@ -39,22 +10,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_mnt4_298/src/fields/tests.rs b/ed_on_mnt4_298/src/fields/tests.rs index 83af9f5..c6d096e 100644 --- a/ed_on_mnt4_298/src/fields/tests.rs +++ b/ed_on_mnt4_298/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/ed_on_mnt4_753/src/constraints/mod.rs b/ed_on_mnt4_753/src/constraints/mod.rs index f38d437..8ecc6a6 100644 --- a/ed_on_mnt4_753/src/constraints/mod.rs +++ b/ed_on_mnt4_753/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_ed_on_mnt4_753`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/ed_on_mnt4_753/src/curves/mod.rs b/ed_on_mnt4_753/src/curves/mod.rs index 1926b53..c5a763c 100644 --- a/ed_on_mnt4_753/src/curves/mod.rs +++ b/ed_on_mnt4_753/src/curves/mod.rs @@ -1,6 +1,6 @@ use ark_ec::{ - models::{ModelParameters, MontgomeryModelParameters, TEModelParameters}, - twisted_edwards_extended::{GroupAffine, GroupProjective}, + models::CurveConfig, + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, }; use ark_ff::MontFp; @@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr}; #[cfg(test)] mod tests; -pub type EdwardsAffine = GroupAffine; -pub type EdwardsProjective = GroupProjective; +pub type EdwardsAffine = Affine; +pub type EdwardsProjective = Projective; #[derive(Clone, Default, PartialEq, Eq)] pub struct EdwardsParameters; -impl ModelParameters for EdwardsParameters { +impl CurveConfig for EdwardsParameters { type BaseField = Fq; type ScalarField = Fr; @@ -24,20 +24,20 @@ impl ModelParameters for EdwardsParameters { /// COFACTOR_INV (mod r) = /// 4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505 - const COFACTOR_INV: Fr = MontFp!(Fr, "4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505"); + const COFACTOR_INV: Fr = MontFp!("4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505"); } -impl TEModelParameters for EdwardsParameters { +impl TECurveConfig for EdwardsParameters { /// COEFF_A = -1 - const COEFF_A: Fq = MontFp!(Fq, "-1"); + const COEFF_A: Fq = MontFp!("-1"); /// COEFF_D = 317690 - const COEFF_D: Fq = MontFp!(Fq, "317690"); + const COEFF_D: Fq = MontFp!("317690"); /// Generated randomly - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y); + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); - type MontgomeryModelParameters = EdwardsParameters; + type MontCurveConfig = EdwardsParameters; /// Multiplication by `a` is just negation. #[inline(always)] @@ -46,20 +46,20 @@ impl TEModelParameters for EdwardsParameters { } } -impl MontgomeryModelParameters for EdwardsParameters { +impl MontCurveConfig for EdwardsParameters { /// COEFF_A = 40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419 - const COEFF_A: Fq = MontFp!(Fq, "40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419"); + const COEFF_A: Fq = MontFp!("40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419"); /// COEFF_B = 1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580 - const COEFF_B: Fq = MontFp!(Fq, "1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580"); + const COEFF_B: Fq = MontFp!("1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580"); - type TEModelParameters = EdwardsParameters; + type TECurveConfig = EdwardsParameters; } /// GENERATOR_X = /// 41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826 -const GENERATOR_X: Fq = MontFp!(Fq, "41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826"); +const GENERATOR_X: Fq = MontFp!("41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826"); /// GENERATOR_Y = /// 18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681 -const GENERATOR_Y: Fq = MontFp!(Fq, "18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681"); +const GENERATOR_Y: Fq = MontFp!("18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681"); diff --git a/ed_on_mnt4_753/src/curves/tests.rs b/ed_on_mnt4_753/src/curves/tests.rs index 02a0b15..0222891 100644 --- a/ed_on_mnt4_753/src/curves/tests.rs +++ b/ed_on_mnt4_753/src/curves/tests.rs @@ -1,6 +1,5 @@ -use ark_algebra_test_templates::{curves::*, groups::*}; -use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_std::{rand::Rng, test_rng}; +use ark_algebra_test_templates::curves::*; +use ark_ec::AffineCurve; use crate::*; @@ -11,27 +10,6 @@ fn test_projective_curve() { edwards_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a = rng.gen(); - let b = rng.gen(); - - for _i in 0..100 { - group_test::(a, b); - } -} - -#[test] -fn test_affine_group() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - for _i in 0..100 { - group_test::(a, b); - } -} - #[test] fn test_generator() { let generator = EdwardsAffine::prime_subgroup_generator(); @@ -39,22 +17,6 @@ fn test_generator() { assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } -#[test] -fn test_conversion() { - let mut rng = test_rng(); - let a: EdwardsAffine = rng.gen(); - let b: EdwardsAffine = rng.gen(); - let a_b = { - use ark_ec::group::Group; - (a + &b).double().double() - }; - let a_b2 = (a.into_projective() + &b.into_projective()) - .double() - .double(); - assert_eq!(a_b, a_b2.into_affine()); - assert_eq!(a_b.into_projective(), a_b2); -} - #[test] fn test_montgomery_conversion() { montgomery_conversion_test::(); diff --git a/ed_on_mnt4_753/src/fields/tests.rs b/ed_on_mnt4_753/src/fields/tests.rs index e0a079d..539bc47 100644 --- a/ed_on_mnt4_753/src/fields/tests.rs +++ b/ed_on_mnt4_753/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/mnt4_298/src/curves/g1.rs b/mnt4_298/src/curves/g1.rs index 9f03943..51c9935 100644 --- a/mnt4_298/src/curves/g1.rs +++ b/mnt4_298/src/curves/g1.rs @@ -1,10 +1,10 @@ use ark_ec::{ mnt4, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fr, FR_ONE}; +use crate::{Fq, Fr}; pub type G1Affine = mnt4::G1Affine; pub type G1Projective = mnt4::G1Projective; @@ -13,7 +13,7 @@ pub type G1Prepared = mnt4::G1Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -22,21 +22,20 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 1 - const COFACTOR_INV: Fr = FR_ONE; + const COFACTOR_INV: Fr = Fr::ONE; } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 2 /// Reference: - const COEFF_A: Fq = MontFp!(Fq, "2"); + const COEFF_A: Fq = MontFp!("2"); /// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685 /// Reference: - const COEFF_B: Fq = MontFp!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685"); + const COEFF_B: Fq = MontFp!("423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); } // Generator of G1 @@ -45,13 +44,11 @@ impl SWModelParameters for Parameters { /// G1_GENERATOR_X /// Reference: pub const G1_GENERATOR_X: Fq = MontFp!( - Fq, "60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838" ); /// G1_GENERATOR_Y /// Reference: pub const G1_GENERATOR_Y: Fq = MontFp!( - Fq, "363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306" ); diff --git a/mnt4_298/src/curves/g2.rs b/mnt4_298/src/curves/g2.rs index bda9a7d..39e79dd 100644 --- a/mnt4_298/src/curves/g2.rs +++ b/mnt4_298/src/curves/g2.rs @@ -1,11 +1,11 @@ use ark_ec::{ mnt4, mnt4::MNT4Parameters, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::{MontFp, QuadExt}; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE}; +use crate::{Fq, Fq2, Fr, G1_COEFF_A_NON_RESIDUE}; pub type G2Affine = mnt4::G2Affine; pub type G2Projective = mnt4::G2Projective; @@ -14,7 +14,7 @@ pub type G2Prepared = mnt4::G2Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq2; type ScalarField = Fr; @@ -31,7 +31,7 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665 - const COFACTOR_INV: Fr = MontFp!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665"); + const COFACTOR_INV: Fr = MontFp!("475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665"); } /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A @@ -40,7 +40,7 @@ pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE; /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE; -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A; // B coefficient of MNT4-298 G2 = // ``` @@ -51,23 +51,22 @@ impl SWModelParameters for Parameters { // = // (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430) // ``` - const COEFF_B: Fq2 = QuadExt!( - FQ_ZERO, - MontFp!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"), + const COEFF_B: Fq2 = Fq2::new( + Fq::ZERO, + MontFp!("67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"), ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(elt: &Fq2) -> Fq2 { - QuadExt!(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,) + Fq2::new(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1) } } -const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); -const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); +const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); +const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); // Generator of G2 // These are two Fq elements each because X and Y (and Z) are elements of Fq^2 @@ -76,21 +75,17 @@ const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); // Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482, // 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489, pub const G2_GENERATOR_X_C0: Fq = MontFp!( - Fq, "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708" ); pub const G2_GENERATOR_X_C1: Fq = MontFp!( - Fq, "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641" ); pub const G2_GENERATOR_Y_C0: Fq = MontFp!( - Fq, "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482" ); pub const G2_GENERATOR_Y_C1: Fq = MontFp!( - Fq, "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489" ); diff --git a/mnt4_298/src/curves/mod.rs b/mnt4_298/src/curves/mod.rs index ac02e6f..4092474 100644 --- a/mnt4_298/src/curves/mod.rs +++ b/mnt4_298/src/curves/mod.rs @@ -1,7 +1,7 @@ use ark_ec::models::mnt4::{MNT4Parameters, MNT4}; -use ark_ff::{biginteger::BigInteger320, BigInt, Fp2, MontFp, QuadExt}; +use ark_ff::{biginteger::BigInteger320, BigInt, Field, MontFp}; -use crate::{Fq, Fq2Config, Fq4Config, Fr}; +use crate::{Fq, Fq2, Fq2Config, Fq4Config, Fr}; pub mod g1; pub mod g2; @@ -19,14 +19,14 @@ pub type MNT4_298 = MNT4; pub struct Parameters; impl MNT4Parameters for Parameters { - const TWIST: Fp2 = QuadExt!(FQ_ZERO, FQ_ONE); + const TWIST: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE); // A coefficient of MNT4-298 G2 = // ``` // mnt4298_twist_coeff_a = mnt4298_Fq2(mnt4298_G1::coeff_a * non_residue, mnt6298_Fq::zero()); // = (A_COEFF * NONRESIDUE, ZERO) // = (34, ZERO) // ``` - const TWIST_COEFF_A: Fp2 = QuadExt!(G1_COEFF_A_NON_RESIDUE, FQ_ZERO); + const TWIST_COEFF_A: Fq2 = Fq2::new(G1_COEFF_A_NON_RESIDUE, Fq::ZERO); const ATE_LOOP_COUNT: &'static [u64] = &[993502997770534912, 5071219579242586943, 2027349]; const ATE_IS_LOOP_COUNT_NEG: bool = false; @@ -43,8 +43,4 @@ impl MNT4Parameters for Parameters { } // 34 -pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!(Fq, "34"); -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FR_ZERO: Fr = MontFp!(Fr, "0"); -pub const FR_ONE: Fr = MontFp!(Fr, "1"); +pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!("34"); diff --git a/mnt4_298/src/curves/tests.rs b/mnt4_298/src/curves/tests.rs index 45311f7..f44f717 100644 --- a/mnt4_298/src/curves/tests.rs +++ b/mnt4_298/src/curves/tests.rs @@ -1,6 +1,6 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, - generate_product_of_pairings_test, groups::*, msm::*, + generate_product_of_pairings_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; diff --git a/mnt4_298/src/fields/fq2.rs b/mnt4_298/src/fields/fq2.rs index 4e6ed02..2987488 100644 --- a/mnt4_298/src/fields/fq2.rs +++ b/mnt4_298/src/fields/fq2.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp2::{Fp2, Fp2Config}, - MontFp, + Field, MontFp, }; -use crate::{Fq, FQ_ONE}; +use crate::Fq; pub type Fq2 = Fp2; @@ -14,12 +14,12 @@ impl Fp2Config for Fq2Config { /// The quadratic non-residue (17) used to construct the extension is /// the same as that used in [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L102). - const NONRESIDUE: Fq = MontFp!(Fq, "17"); + const NONRESIDUE: Fq = MontFp!("17"); /// Precomputed coefficients: /// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]` const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[ - FQ_ONE, - MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"), + Fq::ONE, + MontFp!("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"), ]; } diff --git a/mnt4_298/src/fields/fq4.rs b/mnt4_298/src/fields/fq4.rs index 6417d7c..952fcd2 100644 --- a/mnt4_298/src/fields/fq4.rs +++ b/mnt4_298/src/fields/fq4.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp4::{Fp4, Fp4Config}, - MontFp, QuadExt, + Field, MontFp, }; -use crate::{Fq, Fq2, Fq2Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq2, Fq2Config}; pub type Fq4 = Fp4; @@ -12,7 +12,7 @@ pub struct Fq4Config; impl Fp4Config for Fq4Config { type Fp2Config = Fq2Config; - const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE); + const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE); // Coefficients for the Frobenius automorphism. // c1[0] = 1, @@ -23,9 +23,9 @@ impl Fp4Config for Fq4Config { // These are calculated as // `FROBENIUS_COEFF_FP4_C1[i] = Fp2Config::NONRESIDUE^((q^i - 1) / 4)`. const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"), - MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"), - MontFp!(Fq, "468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"), + Fq::ONE, + MontFp!("7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"), + MontFp!("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"), + MontFp!("468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"), ]; } diff --git a/mnt4_298/src/fields/tests.rs b/mnt4_298/src/fields/tests.rs index 45a18c3..584781e 100644 --- a/mnt4_298/src/fields/tests.rs +++ b/mnt4_298/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/mnt4_753/src/curves/g1.rs b/mnt4_753/src/curves/g1.rs index 78d30da..19334cf 100644 --- a/mnt4_753/src/curves/g1.rs +++ b/mnt4_753/src/curves/g1.rs @@ -1,10 +1,10 @@ use ark_ec::{ mnt4, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fr, FR_ONE}; +use crate::{Fq, Fr}; pub type G1Affine = mnt4::G1Affine; pub type G1Projective = mnt4::G1Projective; @@ -13,7 +13,7 @@ pub type G1Prepared = mnt4::G1Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -21,19 +21,18 @@ impl ModelParameters for Parameters { const COFACTOR: &'static [u64] = &[1]; /// COFACTOR^(-1) mod r = 1 - const COFACTOR_INV: Fr = FR_ONE; + const COFACTOR_INV: Fr = Fr::ONE; } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 2 - const COEFF_A: Fq = MontFp!(Fq, "2"); + const COEFF_A: Fq = MontFp!("2"); /// COEFF_B = 0x01373684A8C9DCAE7A016AC5D7748D3313CD8E39051C596560835DF0C9E50A5B59B882A92C78DC537E51A16703EC9855C77FC3D8BB21C8D68BB8CFB9DB4B8C8FBA773111C36C8B1B4E8F1ECE940EF9EAAD265458E06372009C9A0491678EF4 - const COEFF_B: Fq = MontFp!(Fq, "28798803903456388891410036793299405764940372360099938340752576406393880372126970068421383312482853541572780087363938442377933706865252053507077543420534380486492786626556269083255657125025963825610840222568694137138741554679540"); + const COEFF_B: Fq = MontFp!("28798803903456388891410036793299405764940372360099938340752576406393880372126970068421383312482853541572780087363938442377933706865252053507077543420534380486492786626556269083255657125025963825610840222568694137138741554679540"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); } // Generator of G1 @@ -41,8 +40,8 @@ impl SWModelParameters for Parameters { // Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648, /// G1_GENERATOR_X = /// 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569 -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569"); +pub const G1_GENERATOR_X: Fq = MontFp!("7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569"); /// G1_GENERATOR_Y = /// 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648 -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648"); +pub const G1_GENERATOR_Y: Fq = MontFp!("6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648"); diff --git a/mnt4_753/src/curves/g2.rs b/mnt4_753/src/curves/g2.rs index 4216b9a..ce18150 100644 --- a/mnt4_753/src/curves/g2.rs +++ b/mnt4_753/src/curves/g2.rs @@ -1,11 +1,11 @@ use ark_ec::{ mnt4, mnt4::MNT4Parameters, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::{MontFp, QuadExt}; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE}; +use crate::{Fq, Fq2, Fr, G1_COEFF_A_NON_RESIDUE}; pub type G2Affine = mnt4::G2Affine; pub type G2Projective = mnt4::G2Projective; @@ -14,7 +14,7 @@ pub type G2Prepared = mnt4::G2Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq2; type ScalarField = Fr; @@ -38,7 +38,7 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200 - const COFACTOR_INV: Fr = MontFp!(Fr, "102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200"); + const COFACTOR_INV: Fr = MontFp!("102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200"); } /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A @@ -47,7 +47,7 @@ pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE; /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE; -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A; // B coefficient of MNT4-753 G2 = // ``` @@ -58,23 +58,22 @@ impl SWModelParameters for Parameters { // = // (0, 39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212) // ``` - const COEFF_B: Fq2 = QuadExt!( - FQ_ZERO, - MontFp!(Fq, "39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212") + const COEFF_B: Fq2 = Fq2::new( + Fq::ZERO, + MontFp!("39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212") ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(elt: &Fq2) -> Fq2 { - QuadExt!(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,) + Fq2::new(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1) } } -const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); -const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); +const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1); +const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); // Generator of G2 // These are two Fq elements each because X and Y (and Z) are elements of Fq^2 @@ -82,10 +81,10 @@ const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1); // 19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000, // Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654, // 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245, -pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167"); +pub const G2_GENERATOR_X_C0: Fq = MontFp!("29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167"); -pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000"); +pub const G2_GENERATOR_X_C1: Fq = MontFp!("19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000"); -pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654"); +pub const G2_GENERATOR_Y_C0: Fq = MontFp!("39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654"); -pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245"); +pub const G2_GENERATOR_Y_C1: Fq = MontFp!("17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245"); diff --git a/mnt4_753/src/curves/mod.rs b/mnt4_753/src/curves/mod.rs index b8239e8..d5b4e21 100644 --- a/mnt4_753/src/curves/mod.rs +++ b/mnt4_753/src/curves/mod.rs @@ -1,7 +1,7 @@ use ark_ec::models::mnt4::{MNT4Parameters, MNT4}; use ark_ff::{ biginteger::{BigInt, BigInteger768}, - Fp2, MontFp, QuadExt, + Field, Fp2, MontFp, }; use crate::{Fq, Fq2Config, Fq4Config, Fr}; @@ -22,14 +22,14 @@ pub type MNT4_753 = MNT4; pub struct Parameters; impl MNT4Parameters for Parameters { - const TWIST: Fp2 = QuadExt!(FQ_ZERO, FQ_ONE); + const TWIST: Fp2 = Fp2::new(Fq::ZERO, Fq::ONE); // A coefficient of MNT4-753 G2 = // ``` // mnt4753_twist_coeff_a = mnt4753_Fq2(mnt4753_G1::coeff_a * non_residue, mnt6753_Fq::zero()); // = (A_COEFF * NONRESIDUE, ZERO) // = (26, ZERO) // ``` - const TWIST_COEFF_A: Fp2 = QuadExt!(G1_COEFF_A_NON_RESIDUE, FQ_ZERO,); + const TWIST_COEFF_A: Fp2 = Fp2::new(G1_COEFF_A_NON_RESIDUE, Fq::ZERO); // https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt4753.ml const ATE_LOOP_COUNT: &'static [u64] = &[ 8824542903220142080, @@ -66,9 +66,4 @@ impl MNT4Parameters for Parameters { } // 26 -pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!(Fq, "26"); - -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FR_ZERO: Fr = MontFp!(Fr, "0"); -pub const FR_ONE: Fr = MontFp!(Fr, "1"); +pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!("26"); diff --git a/mnt4_753/src/curves/tests.rs b/mnt4_753/src/curves/tests.rs index 8003b8c..bdab587 100644 --- a/mnt4_753/src/curves/tests.rs +++ b/mnt4_753/src/curves/tests.rs @@ -1,6 +1,6 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, - generate_product_of_pairings_test, groups::*, msm::*, + generate_product_of_pairings_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; diff --git a/mnt4_753/src/fields/fq2.rs b/mnt4_753/src/fields/fq2.rs index 0cb3322..a44e2fa 100644 --- a/mnt4_753/src/fields/fq2.rs +++ b/mnt4_753/src/fields/fq2.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp2::{Fp2, Fp2Config}, - MontFp, + Field, MontFp, }; -use crate::{Fq, FQ_ONE}; +use crate::Fq; pub type Fq2 = Fp2; @@ -13,13 +13,13 @@ impl Fp2Config for Fq2Config { type Fp = Fq; // non_residue = 13 - const NONRESIDUE: Fq = MontFp!(Fq, "13"); + const NONRESIDUE: Fq = MontFp!("13"); // Coefficients: // [1, 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600] // see https://github.com/o1-labs/snarky/blob/2cf5ef3a14989e57c17518832b3c52590068fc48/src/camlsnark_c/libsnark-caml/depends/libff/libff/algebra/curves/mnt753/mnt4753/mnt4753_init.cpp const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[ - FQ_ONE, - MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"), + Fq::ONE, + MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"), ]; } diff --git a/mnt4_753/src/fields/fq4.rs b/mnt4_753/src/fields/fq4.rs index c6585ac..8233d4a 100644 --- a/mnt4_753/src/fields/fq4.rs +++ b/mnt4_753/src/fields/fq4.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp4::{Fp4, Fp4Config}, - MontFp, QuadExt, + Field, MontFp, }; -use crate::{Fq, Fq2, Fq2Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq2, Fq2Config}; pub type Fq4 = Fp4; @@ -12,7 +12,7 @@ pub struct Fq4Config; impl Fp4Config for Fq4Config { type Fp2Config = Fq2Config; - const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE); + const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE); // Coefficients for the Frobenius automorphism. // c1[0] = 1, @@ -23,9 +23,9 @@ impl Fp4Config for Fq4Config { // These are calculated as `FROBENIUS_COEFF_FP4_C1[i] = // Fp2Config::NONRESIDUE^((q^i - 1) / 4)`. const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "18691656569803771296244054523431852464958959799019013859007259692542121208304602539555350517075508287829753932558576476751900235650227380562700444433662761577027341858128610410779088384480737679672900770810745291515010467307990"), - MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"), - MontFp!(Fq, "23206834398115182106100160267808784663211750120934935212776243228483231604266504233503543246714830633588317039329677309362453490879357004638891161288350364891904062489821230132228897943262725174047727280881395973788104254381611"), + Fq::ONE, + MontFp!("18691656569803771296244054523431852464958959799019013859007259692542121208304602539555350517075508287829753932558576476751900235650227380562700444433662761577027341858128610410779088384480737679672900770810745291515010467307990"), + MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"), + MontFp!("23206834398115182106100160267808784663211750120934935212776243228483231604266504233503543246714830633588317039329677309362453490879357004638891161288350364891904062489821230132228897943262725174047727280881395973788104254381611"), ]; } diff --git a/mnt4_753/src/fields/tests.rs b/mnt4_753/src/fields/tests.rs index 4fc5717..4406661 100644 --- a/mnt4_753/src/fields/tests.rs +++ b/mnt4_753/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/mnt6_298/src/curves/g1.rs b/mnt6_298/src/curves/g1.rs index 3cd49ef..5026f14 100644 --- a/mnt6_298/src/curves/g1.rs +++ b/mnt6_298/src/curves/g1.rs @@ -1,8 +1,8 @@ use ark_ec::{ mnt6, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; use crate::{Fq, Fr}; @@ -13,7 +13,7 @@ pub type G1Prepared = mnt6::G1Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -21,25 +21,24 @@ impl ModelParameters for Parameters { const COFACTOR: &'static [u64] = &[1]; /// COFACTOR^(-1) mod r = 1 - const COFACTOR_INV: Fr = MontFp!(Fr, "1"); + const COFACTOR_INV: Fr = Fr::ONE; } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 11 - const COEFF_A: Fq = MontFp!(Fq, "11"); + const COEFF_A: Fq = MontFp!("11"); /// COEFF_B = 106700080510851735677967319632585352256454251201367587890185989362936000262606668469523074 - const COEFF_B: Fq = MontFp!(Fq, "106700080510851735677967319632585352256454251201367587890185989362936000262606668469523074"); + const COEFF_B: Fq = MontFp!("106700080510851735677967319632585352256454251201367587890185989362936000262606668469523074"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); } /// G1_GENERATOR_X = #[rustfmt::skip] -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "336685752883082228109289846353937104185698209371404178342968838739115829740084426881123453"); +pub const G1_GENERATOR_X: Fq = MontFp!("336685752883082228109289846353937104185698209371404178342968838739115829740084426881123453"); /// G1_GENERATOR_Y = #[rustfmt::skip] -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "402596290139780989709332707716568920777622032073762749862342374583908837063963736098549800"); +pub const G1_GENERATOR_Y: Fq = MontFp!("402596290139780989709332707716568920777622032073762749862342374583908837063963736098549800"); diff --git a/mnt6_298/src/curves/g2.rs b/mnt6_298/src/curves/g2.rs index 1822c3b..7c3f7d3 100644 --- a/mnt6_298/src/curves/g2.rs +++ b/mnt6_298/src/curves/g2.rs @@ -1,11 +1,11 @@ use ark_ec::{ mnt6, mnt6::MNT6Parameters, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::{CubicExt, MontFp}; +use ark_ff::{Field, MontFp}; -use crate::{g1, Fq, Fq3, Fr, FQ_ZERO}; +use crate::{g1, Fq, Fq3, Fr}; pub type G2Affine = mnt6::G2Affine; pub type G2Projective = mnt6::G2Projective; @@ -14,7 +14,7 @@ pub type G2Prepared = mnt6::G2Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq3; type ScalarField = Fr; @@ -37,36 +37,34 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504 const COFACTOR_INV: Fr = MontFp!( - Fr, "79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504" ); } /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A = 5 * 11 -pub const MUL_BY_A_C0: Fq = MontFp!(Fq, "55"); +pub const MUL_BY_A_C0: Fq = MontFp!("55"); /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A -pub const MUL_BY_A_C1: Fq = MontFp!(Fq, "55"); +pub const MUL_BY_A_C1: Fq = MontFp!("55"); /// MUL_BY_A_C2 = COEFF_A pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A; -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A; - const COEFF_B: Fq3 = CubicExt!( + const COEFF_B: Fq3 = Fq3::new( // 5 * G1::COEFF_B - MontFp!(Fq, "57578116384997352636487348509878309737146377454014423897662211075515354005624851787652233"), - FQ_ZERO, - FQ_ZERO, + MontFp!("57578116384997352636487348509878309737146377454014423897662211075515354005624851787652233"), + Fq::ZERO, + Fq::ZERO, ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(elt: &Fq3) -> Fq3 { - CubicExt!( + Fq3::new( MUL_BY_A_C0 * &elt.c1, MUL_BY_A_C1 * &elt.c2, MUL_BY_A_C2 * &elt.c0, @@ -74,31 +72,25 @@ impl SWModelParameters for Parameters { } } -const G2_GENERATOR_X: Fq3 = CubicExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); -const G2_GENERATOR_Y: Fq3 = CubicExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); +const G2_GENERATOR_X: Fq3 = Fq3::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); +const G2_GENERATOR_Y: Fq3 = Fq3::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); pub const G2_GENERATOR_X_C0: Fq = MontFp!( - Fq, "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427" ); pub const G2_GENERATOR_X_C1: Fq = MontFp!( - Fq, "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114" ); pub const G2_GENERATOR_X_C2: Fq = MontFp!( - Fq, "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558" ); pub const G2_GENERATOR_Y_C0: Fq = MontFp!( - Fq, "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377" ); pub const G2_GENERATOR_Y_C1: Fq = MontFp!( - Fq, "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678" ); pub const G2_GENERATOR_Y_C2: Fq = MontFp!( - Fq, "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903" ); diff --git a/mnt6_298/src/curves/mod.rs b/mnt6_298/src/curves/mod.rs index 0ed900c..51115cc 100644 --- a/mnt6_298/src/curves/mod.rs +++ b/mnt6_298/src/curves/mod.rs @@ -1,8 +1,8 @@ use ark_ec::{ models::mnt6::{MNT6Parameters, MNT6}, - SWModelParameters, + short_weierstrass::SWCurveConfig, }; -use ark_ff::{biginteger::BigInteger320, BigInt, CubicExt, Fp3, MontFp}; +use ark_ff::{biginteger::BigInteger320, BigInt, Field, Fp3}; use crate::{Fq, Fq3Config, Fq6Config, Fr}; @@ -22,9 +22,9 @@ pub type MNT6_298 = MNT6; pub struct Parameters; impl MNT6Parameters for Parameters { - const TWIST: Fp3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const TWIST: Fp3 = Fp3::::new(Fq::ZERO, Fq::ONE, Fq::ZERO); const TWIST_COEFF_A: Fp3 = - CubicExt!(FQ_ZERO, FQ_ZERO, g1::Parameters::COEFF_A,); + Fp3::::new(Fq::ZERO, Fq::ZERO, g1::Parameters::COEFF_A); const ATE_LOOP_COUNT: &'static [u64] = &[0xdc9a1b671660000, 0x46609756bec2a33f, 0x1eef55]; const ATE_IS_LOOP_COUNT_NEG: bool = true; const FINAL_EXPONENT_LAST_CHUNK_1: BigInteger320 = BigInt::new([0x1, 0x0, 0x0, 0x0, 0x0]); @@ -38,6 +38,3 @@ impl MNT6Parameters for Parameters { type G1Parameters = self::g1::Parameters; type G2Parameters = self::g2::Parameters; } - -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); diff --git a/mnt6_298/src/curves/tests.rs b/mnt6_298/src/curves/tests.rs index e5986c4..fe7ee99 100644 --- a/mnt6_298/src/curves/tests.rs +++ b/mnt6_298/src/curves/tests.rs @@ -1,6 +1,6 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, - generate_product_of_pairings_test, groups::*, msm::*, + generate_product_of_pairings_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; diff --git a/mnt6_298/src/fields/fq3.rs b/mnt6_298/src/fields/fq3.rs index 9e14a82..938b1a3 100644 --- a/mnt6_298/src/fields/fq3.rs +++ b/mnt6_298/src/fields/fq3.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp3::{Fp3, Fp3Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{fq::Fq, FQ_ZERO}; +use crate::fq::Fq; pub type Fq3 = Fp3; @@ -12,7 +12,7 @@ pub struct Fq3Config; impl Fp3Config for Fq3Config { type Fp = Fq; - const NONRESIDUE: Fq = MontFp!(Fq, "5"); + const NONRESIDUE: Fq = MontFp!("5"); const TWO_ADICITY: u32 = 34; @@ -34,16 +34,16 @@ impl Fp3Config for Fq3Config { 0x6878f58, ]; - const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!( - MontFp!(Fq, "154361449678783505076984156275977937654331103361174469632346230549735979552469642799720052"), - FQ_ZERO, - FQ_ZERO, + const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new( + MontFp!("154361449678783505076984156275977937654331103361174469632346230549735979552469642799720052"), + Fq::ZERO, + Fq::ZERO, ); const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "471738898967521029133040851318449165997304108729558973770077319830005517129946578866686956"), - MontFp!(Fq, "4183387201740296620308398334599285547820769823264541783190415909159130177461911693276180"), + Fq::ONE, + MontFp!("471738898967521029133040851318449165997304108729558973770077319830005517129946578866686956"), + MontFp!("4183387201740296620308398334599285547820769823264541783190415909159130177461911693276180"), ]; const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ diff --git a/mnt6_298/src/fields/fq6.rs b/mnt6_298/src/fields/fq6.rs index d35fa11..b705170 100644 --- a/mnt6_298/src/fields/fq6.rs +++ b/mnt6_298/src/fields/fq6.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp6_2over3::{Fp6, Fp6Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq3, Fq3Config}; pub type Fq6 = Fp6; @@ -12,14 +12,14 @@ pub struct Fq6Config; impl Fp6Config for Fq6Config { type Fp3Config = Fq3Config; - const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const NONRESIDUE: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[ - MontFp!(Fq, "1"), - MontFp!(Fq, "471738898967521029133040851318449165997304108729558973770077319830005517129946578866686957"), - MontFp!(Fq, "471738898967521029133040851318449165997304108729558973770077319830005517129946578866686956"), - MontFp!(Fq, "475922286169261325753349249653048451545124878552823515553267735739164647307408490559963136"), - MontFp!(Fq, "4183387201740296620308398334599285547820769823264541783190415909159130177461911693276180"), - MontFp!(Fq, "4183387201740296620308398334599285547820769823264541783190415909159130177461911693276181"), + Fq::ONE, + MontFp!("471738898967521029133040851318449165997304108729558973770077319830005517129946578866686957"), + MontFp!("471738898967521029133040851318449165997304108729558973770077319830005517129946578866686956"), + MontFp!("475922286169261325753349249653048451545124878552823515553267735739164647307408490559963136"), + MontFp!("4183387201740296620308398334599285547820769823264541783190415909159130177461911693276180"), + MontFp!("4183387201740296620308398334599285547820769823264541783190415909159130177461911693276181"), ]; } diff --git a/mnt6_298/src/fields/tests.rs b/mnt6_298/src/fields/tests.rs index 96fd342..fbc66d2 100644 --- a/mnt6_298/src/fields/tests.rs +++ b/mnt6_298/src/fields/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; use ark_ff::{ - fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig, SquareRootField}, + fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig}, Field, PrimeField, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -11,7 +11,7 @@ use core::ops::{AddAssign, MulAssign, SubAssign}; use crate::*; -generate_field_test!(mnt6_298; fq3; fq6; mont(5, 5); ); +generate_field_test!(mnt6_298; fq3; fq6_2_on_3; mont(5, 5); ); generate_field_serialization_test!(mnt6_298;); #[test] diff --git a/mnt6_753/src/curves/g1.rs b/mnt6_753/src/curves/g1.rs index f13aad6..13aac9f 100644 --- a/mnt6_753/src/curves/g1.rs +++ b/mnt6_753/src/curves/g1.rs @@ -1,10 +1,10 @@ use ark_ec::{ mnt6, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::MontFp; +use ark_ff::{Field, MontFp}; -use crate::{Fq, Fr, FR_ONE}; +use crate::{Fq, Fr}; pub type G1Affine = mnt6::G1Affine; pub type G1Projective = mnt6::G1Projective; @@ -13,7 +13,7 @@ pub type G1Prepared = mnt6::G1Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq; type ScalarField = Fr; @@ -21,19 +21,18 @@ impl ModelParameters for Parameters { const COFACTOR: &'static [u64] = &[1]; /// COFACTOR^(-1) mod r = 1 - const COFACTOR_INV: Fr = FR_ONE; + const COFACTOR_INV: Fr = Fr::ONE; } -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { /// COEFF_A = 11 - const COEFF_A: Fq = MontFp!(Fq, "11"); + const COEFF_A: Fq = MontFp!("11"); /// COEFF_B = 0x7DA285E70863C79D56446237CE2E1468D14AE9BB64B2BB01B10E60A5D5DFE0A25714B7985993F62F03B22A9A3C737A1A1E0FCF2C43D7BF847957C34CCA1E3585F9A80A95F401867C4E80F4747FDE5ABA7505BA6FCF2485540B13DFC8468A - const COEFF_B: Fq = MontFp!(Fq, "11625908999541321152027340224010374716841167701783584648338908235410859267060079819722747939267925389062611062156601938166010098747920378738927832658133625454260115409075816187555055859490253375704728027944315501122723426879114"); + const COEFF_B: Fq = MontFp!("11625908999541321152027340224010374716841167701783584648338908235410859267060079819722747939267925389062611062156601938166010098747920378738927832658133625454260115409075816187555055859490253375704728027944315501122723426879114"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G1_GENERATOR_X, G1_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); } // Generator of G1 @@ -41,8 +40,8 @@ impl SWModelParameters for Parameters { // Y = 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569, /// G1_GENERATOR_X = /// 3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728, -pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728"); +pub const G1_GENERATOR_X: Fq = MontFp!("3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728"); /// G1_GENERATOR_Y = /// 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569, -pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569"); +pub const G1_GENERATOR_Y: Fq = MontFp!("27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569"); diff --git a/mnt6_753/src/curves/g2.rs b/mnt6_753/src/curves/g2.rs index 56fdebe..ba419a2 100644 --- a/mnt6_753/src/curves/g2.rs +++ b/mnt6_753/src/curves/g2.rs @@ -1,11 +1,11 @@ use ark_ec::{ mnt6, mnt6::MNT6Parameters, - models::{ModelParameters, SWModelParameters}, + models::{short_weierstrass::SWCurveConfig, CurveConfig}, }; -use ark_ff::{CubicExt, MontFp}; +use ark_ff::{Field, MontFp}; -use crate::{g1, Fq, Fq3, Fr, FQ_ZERO}; +use crate::{g1, Fq, Fq3, Fr}; pub type G2Affine = mnt6::G2Affine; pub type G2Projective = mnt6::G2Projective; @@ -14,7 +14,7 @@ pub type G2Prepared = mnt6::G2Prepared; #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; -impl ModelParameters for Parameters { +impl CurveConfig for Parameters { type BaseField = Fq3; type ScalarField = Fr; @@ -50,23 +50,23 @@ impl ModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200 - const COFACTOR_INV: Fr = MontFp!(Fr, "6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200"); + const COFACTOR_INV: Fr = MontFp!("6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200"); } /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A /// = 11 * 11 /// = 121 -pub const MUL_BY_A_C0: Fq = MontFp!(Fq, "121"); +pub const MUL_BY_A_C0: Fq = MontFp!("121"); /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A /// = 11 * 11 /// = 121 -pub const MUL_BY_A_C1: Fq = MontFp!(Fq, "121"); +pub const MUL_BY_A_C1: Fq = MontFp!("121"); /// MUL_BY_A_C2 = COEFF_A pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A; -impl SWModelParameters for Parameters { +impl SWCurveConfig for Parameters { const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A; // B coefficient of MNT6-753 G2 = // ``` @@ -78,19 +78,18 @@ impl SWModelParameters for Parameters { // (2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251, // 0, 0) // ``` - const COEFF_B: Fq3 = CubicExt!( - MontFp!(Fq, "2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251"), - FQ_ZERO, - FQ_ZERO, + const COEFF_B: Fq3 = Fq3::new( + MontFp!("2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251"), + Fq::ZERO, + Fq::ZERO, ); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G2_GENERATOR_X, G2_GENERATOR_Y); + const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] fn mul_by_a(elt: &Fq3) -> Fq3 { - CubicExt!( + Fq3::new( MUL_BY_A_C0 * &elt.c1, MUL_BY_A_C1 * &elt.c2, MUL_BY_A_C2 * &elt.c0, @@ -98,8 +97,8 @@ impl SWModelParameters for Parameters { } } -const G2_GENERATOR_X: Fq3 = CubicExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); -const G2_GENERATOR_Y: Fq3 = CubicExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); +const G2_GENERATOR_X: Fq3 = Fq3::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2); +const G2_GENERATOR_Y: Fq3 = Fq3::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2); // Generator of G2 // These are three Fq elements each because X and Y (and Z) are elements of Fq^3 @@ -109,10 +108,10 @@ const G2_GENERATOR_Y: Fq3 = CubicExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_G // Y = 2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615, // 7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497, // 21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689, -pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "27250797394340459586637772414334383652934225310678303542554641987990991970766156209996739240400887081904395745019996048910447071686918567661896491214767494514394154061111870331668445455228882471000120574964265209669155206168252"); -pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "35762481056967998715733586393399457882827322353696313323665483142561285210083843314423554450886956650265947502285422529615273790981238406393402603210224104850580302463396274854098657541573494421834514772635884262388058080180368"); -pub const G2_GENERATOR_X_C2: Fq = MontFp!(Fq, "36955296703808958167583270646821654948157955258947892285629161090141878438357164213613114995903637211606408001037026832604054121847388692538440756596264746452765613740820430501353237866984394057660379098674983614861254438847846"); +pub const G2_GENERATOR_X_C0: Fq = MontFp!("27250797394340459586637772414334383652934225310678303542554641987990991970766156209996739240400887081904395745019996048910447071686918567661896491214767494514394154061111870331668445455228882471000120574964265209669155206168252"); +pub const G2_GENERATOR_X_C1: Fq = MontFp!("35762481056967998715733586393399457882827322353696313323665483142561285210083843314423554450886956650265947502285422529615273790981238406393402603210224104850580302463396274854098657541573494421834514772635884262388058080180368"); +pub const G2_GENERATOR_X_C2: Fq = MontFp!("36955296703808958167583270646821654948157955258947892285629161090141878438357164213613114995903637211606408001037026832604054121847388692538440756596264746452765613740820430501353237866984394057660379098674983614861254438847846"); -pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615"); -pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497"); -pub const G2_GENERATOR_Y_C2: Fq = MontFp!(Fq, "21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689"); +pub const G2_GENERATOR_Y_C0: Fq = MontFp!("2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615"); +pub const G2_GENERATOR_Y_C1: Fq = MontFp!("7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497"); +pub const G2_GENERATOR_Y_C2: Fq = MontFp!("21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689"); diff --git a/mnt6_753/src/curves/mod.rs b/mnt6_753/src/curves/mod.rs index 783b037..962711f 100644 --- a/mnt6_753/src/curves/mod.rs +++ b/mnt6_753/src/curves/mod.rs @@ -1,8 +1,8 @@ use ark_ec::models::{ mnt6::{MNT6Parameters, MNT6}, - SWModelParameters, + short_weierstrass::SWCurveConfig, }; -use ark_ff::{biginteger::BigInteger768, BigInt, CubicExt, Fp3, MontFp}; +use ark_ff::{biginteger::BigInteger768, BigInt, Field, Fp3}; use crate::{Fq, Fq3Config, Fq6Config, Fr}; @@ -22,7 +22,7 @@ pub type MNT6_753 = MNT6; pub struct Parameters; impl MNT6Parameters for Parameters { - const TWIST: Fp3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const TWIST: Fp3 = Fp3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); // A coefficient of MNT6-753 G2 = // ``` // mnt6753_twist_coeff_a = mnt6753_Fq3(mnt6753_Fq::zero(), mnt6753_Fq::zero(), @@ -30,7 +30,7 @@ impl MNT6Parameters for Parameters { // = (ZERO, ZERO, A_COEFF); // ``` const TWIST_COEFF_A: Fp3 = - CubicExt!(FQ_ZERO, FQ_ZERO, g1::Parameters::COEFF_A,); + Fp3::new(Fq::ZERO, Fq::ZERO, g1::Parameters::COEFF_A); // https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt6753.ml const ATE_LOOP_COUNT: &'static [u64] = &[ @@ -66,8 +66,3 @@ impl MNT6Parameters for Parameters { type G1Parameters = self::g1::Parameters; type G2Parameters = self::g2::Parameters; } - -pub const FQ_ZERO: Fq = MontFp!(Fq, "0"); -pub const FQ_ONE: Fq = MontFp!(Fq, "1"); -pub const FR_ZERO: Fr = MontFp!(Fr, "0"); -pub const FR_ONE: Fr = MontFp!(Fr, "1"); diff --git a/mnt6_753/src/curves/tests.rs b/mnt6_753/src/curves/tests.rs index 97a0916..85883ad 100644 --- a/mnt6_753/src/curves/tests.rs +++ b/mnt6_753/src/curves/tests.rs @@ -1,6 +1,6 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, - generate_product_of_pairings_test, groups::*, msm::*, + generate_product_of_pairings_test, msm::*, }; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; diff --git a/mnt6_753/src/fields/fq3.rs b/mnt6_753/src/fields/fq3.rs index 308f1fa..71e3f8a 100644 --- a/mnt6_753/src/fields/fq3.rs +++ b/mnt6_753/src/fields/fq3.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp3::{Fp3, Fp3Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{fq::Fq, FQ_ONE, FQ_ZERO}; +use crate::fq::Fq; pub type Fq3 = Fp3; @@ -12,7 +12,7 @@ pub struct Fq3Config; impl Fp3Config for Fq3Config { type Fp = Fq; - const NONRESIDUE: Fq = MontFp!(Fq, "11"); + const NONRESIDUE: Fq = MontFp!("11"); const TWO_ADICITY: u32 = 30; @@ -56,10 +56,10 @@ impl Fp3Config for Fq3Config { ]; /// (11^T, 0, 0) - const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!( - MontFp!(Fq, "22168644070733283197994897338612733221095941481265408161807376791727499343083607817089033595478370212662133368413166734396127674284827734481031659015434501966360165723728649019457855887066657739809176476252080335185730833468062"), - FQ_ZERO, - FQ_ZERO, + const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new( + MontFp!("22168644070733283197994897338612733221095941481265408161807376791727499343083607817089033595478370212662133368413166734396127674284827734481031659015434501966360165723728649019457855887066657739809176476252080335185730833468062"), + Fq::ZERO, + Fq::ZERO, ); // Coefficients for the Frobenius automorphism. @@ -67,14 +67,14 @@ impl Fp3Config for Fq3Config { // c1[1] = 24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132 // c1[2] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868, const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), - MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), + Fq::ONE, + MontFp!("24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), + MontFp!("17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), ]; // c2 = {c1[0], c1[2], c1[1]} const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ - FQ_ONE, + Fq::ONE, Self::FROBENIUS_COEFF_FP3_C1[2], Self::FROBENIUS_COEFF_FP3_C1[1], ]; diff --git a/mnt6_753/src/fields/fq6.rs b/mnt6_753/src/fields/fq6.rs index 72ea558..0a41c0b 100644 --- a/mnt6_753/src/fields/fq6.rs +++ b/mnt6_753/src/fields/fq6.rs @@ -1,9 +1,9 @@ use ark_ff::{ fields::fp6_2over3::{Fp6, Fp6Config}, - CubicExt, MontFp, + Field, MontFp, }; -use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO}; +use crate::{Fq, Fq3, Fq3Config}; pub type Fq6 = Fp6; @@ -12,7 +12,7 @@ pub struct Fq6Config; impl Fp6Config for Fq6Config { type Fp3Config = Fq3Config; - const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO); + const NONRESIDUE: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); // Coefficients for the Frobenius automorphism. // c1[0] = 1, @@ -22,11 +22,11 @@ impl Fp6Config for Fq6Config { // c1[4] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868 // c1[5] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869 const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[ - FQ_ONE, - MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133"), - MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), - MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000"), - MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), - MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869"), + Fq::ONE, + MontFp!("24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133"), + MontFp!("24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), + MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000"), + MontFp!("17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), + MontFp!("17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869"), ]; } diff --git a/mnt6_753/src/fields/tests.rs b/mnt6_753/src/fields/tests.rs index 3cf0167..fbd1a5b 100644 --- a/mnt6_753/src/fields/tests.rs +++ b/mnt6_753/src/fields/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; use ark_ff::{ - fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig, SquareRootField}, + fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig}, Field, PrimeField, }; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; @@ -11,7 +11,7 @@ use core::ops::{AddAssign, MulAssign, SubAssign}; use crate::*; -generate_field_test!(mnt6_753; fq3; fq6; mont(12, 12); ); +generate_field_test!(mnt6_753; fq3; fq6_2_on_3; mont(12, 12); ); generate_field_serialization_test!(mnt6_753;); #[test] diff --git a/pallas/src/constraints/mod.rs b/pallas/src/constraints/mod.rs index e363da8..1a83de4 100644 --- a/pallas/src/constraints/mod.rs +++ b/pallas/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_pallas`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/pallas/src/curves/mod.rs b/pallas/src/curves/mod.rs index bb2c61a..3a04167 100644 --- a/pallas/src/curves/mod.rs +++ b/pallas/src/curves/mod.rs @@ -1,8 +1,8 @@ use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::CurveConfig, + short_weierstrass::{Affine, Projective, SWCurveConfig}, }; -use ark_ff::{MontFp, Zero}; +use ark_ff::{Field, MontFp, Zero}; use crate::{fq::Fq, fr::Fr}; @@ -12,7 +12,7 @@ mod tests; #[derive(Copy, Clone, Default, PartialEq, Eq)] pub struct PallasParameters; -impl ModelParameters for PallasParameters { +impl CurveConfig for PallasParameters { type BaseField = Fq; type ScalarField = Fr; @@ -20,22 +20,21 @@ impl ModelParameters for PallasParameters { const COFACTOR: &'static [u64] = &[0x1]; /// COFACTOR_INV = 1 - const COFACTOR_INV: Fr = MontFp!(Fr, "1"); + const COFACTOR_INV: Fr = Fr::ONE; } -pub type Affine = GroupAffine; -pub type Projective = GroupProjective; +pub type G1Affine = Affine; +pub type G1Projective = Projective; -impl SWModelParameters for PallasParameters { +impl SWCurveConfig for PallasParameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 5 - const COEFF_B: Fq = MontFp!(Fq, "5"); + const COEFF_B: Fq = MontFp!("5"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G_GENERATOR_X, G_GENERATOR_Y); + const GENERATOR: G1Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -44,7 +43,7 @@ impl SWModelParameters for PallasParameters { } /// G_GENERATOR_X = -1 -pub const G_GENERATOR_X: Fq = MontFp!(Fq, "-1"); +pub const G_GENERATOR_X: Fq = MontFp!("-1"); /// G_GENERATOR_Y = 2 -pub const G_GENERATOR_Y: Fq = MontFp!(Fq, "2"); +pub const G_GENERATOR_Y: Fq = MontFp!("2"); diff --git a/pallas/src/curves/tests.rs b/pallas/src/curves/tests.rs index f99a052..34c9eef 100755 --- a/pallas/src/curves/tests.rs +++ b/pallas/src/curves/tests.rs @@ -1,29 +1,17 @@ -use ark_algebra_test_templates::{ - curves::{curve_tests, sw_tests}, - groups::group_test, -}; +use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; use ark_ec::AffineCurve; -use ark_std::{rand::Rng, test_rng}; -use crate::{Affine, PallasParameters, Projective}; +use crate::{G1Affine, G1Projective, PallasParameters}; #[test] fn test_projective_curve() { - curve_tests::(); + curve_tests::(); sw_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a: Projective = rng.gen(); - let b: Projective = rng.gen(); - group_test(a, b); -} - #[test] fn test_generator() { - let generator = Affine::prime_subgroup_generator(); + let generator = G1Affine::prime_subgroup_generator(); assert!(generator.is_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } diff --git a/pallas/src/fields/tests.rs b/pallas/src/fields/tests.rs index 90ec6e4..d4e4a9d 100644 --- a/pallas/src/fields/tests.rs +++ b/pallas/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign}; diff --git a/vesta/src/constraints/mod.rs b/vesta/src/constraints/mod.rs index a2ac129..8a976e7 100644 --- a/vesta/src/constraints/mod.rs +++ b/vesta/src/constraints/mod.rs @@ -1,7 +1,7 @@ //! This module implements the R1CS equivalent of `ark_vesta`. //! //! It implements field variables for `crate::Fq`, -//! and group variables for `crate::GroupProjective`. +//! and group variables for `crate::Projective`. //! //! The field underlying these constraints is `crate::Fq`. //! diff --git a/vesta/src/curves/mod.rs b/vesta/src/curves/mod.rs index 1c0f229..a065720 100644 --- a/vesta/src/curves/mod.rs +++ b/vesta/src/curves/mod.rs @@ -1,9 +1,9 @@ use crate::{fq::Fq, fr::Fr}; use ark_ec::{ - models::{ModelParameters, SWModelParameters}, - short_weierstrass_jacobian::{GroupAffine, GroupProjective}, + models::CurveConfig, + short_weierstrass::{Affine, Projective, SWCurveConfig}, }; -use ark_ff::{MontFp, Zero}; +use ark_ff::{Field, MontFp, Zero}; #[cfg(test)] mod tests; @@ -11,7 +11,7 @@ mod tests; #[derive(Copy, Clone, Default, PartialEq, Eq)] pub struct VestaParameters; -impl ModelParameters for VestaParameters { +impl CurveConfig for VestaParameters { type BaseField = Fq; type ScalarField = Fr; @@ -19,22 +19,21 @@ impl ModelParameters for VestaParameters { const COFACTOR: &'static [u64] = &[0x1]; /// COFACTOR_INV = 1 - const COFACTOR_INV: Fr = MontFp!(Fr, "1"); + const COFACTOR_INV: Fr = Fr::ONE; } -pub type Affine = GroupAffine; -pub type Projective = GroupProjective; +pub type G1Affine = Affine; +pub type G1Projective = Projective; -impl SWModelParameters for VestaParameters { +impl SWCurveConfig for VestaParameters { /// COEFF_A = 0 - const COEFF_A: Fq = MontFp!(Fq, "0"); + const COEFF_A: Fq = Fq::ZERO; /// COEFF_B = 5 - const COEFF_B: Fq = MontFp!(Fq, "5"); + const COEFF_B: Fq = MontFp!("5"); /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) - const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = - (G_GENERATOR_X, G_GENERATOR_Y); + const GENERATOR: G1Affine = G1Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); #[inline(always)] fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { @@ -44,8 +43,8 @@ impl SWModelParameters for VestaParameters { /// G_GENERATOR_X = -1 /// Encoded in Montgomery form, so the value here is -R mod p. -pub const G_GENERATOR_X: Fq = MontFp!(Fq, "-1"); +pub const G_GENERATOR_X: Fq = MontFp!("-1"); /// G_GENERATOR_Y = 2 /// Encoded in Montgomery form, so the value here is 2R mod p. -pub const G_GENERATOR_Y: Fq = MontFp!(Fq, "2"); +pub const G_GENERATOR_Y: Fq = MontFp!("2"); diff --git a/vesta/src/curves/tests.rs b/vesta/src/curves/tests.rs index d632dd7..36ca9f3 100755 --- a/vesta/src/curves/tests.rs +++ b/vesta/src/curves/tests.rs @@ -1,29 +1,17 @@ -use ark_algebra_test_templates::{ - curves::{curve_tests, sw_tests}, - groups::group_test, -}; +use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; use ark_ec::AffineCurve; -use ark_std::{rand::Rng, test_rng}; -use crate::{Affine, Projective, VestaParameters}; +use crate::{G1Affine, G1Projective, VestaParameters}; #[test] fn test_projective_curve() { - curve_tests::(); + curve_tests::(); sw_tests::(); } -#[test] -fn test_projective_group() { - let mut rng = test_rng(); - let a: Projective = rng.gen(); - let b: Projective = rng.gen(); - group_test(a, b); -} - #[test] fn test_generator() { - let generator = Affine::prime_subgroup_generator(); + let generator = G1Affine::prime_subgroup_generator(); assert!(generator.is_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve()); } diff --git a/vesta/src/fields/tests.rs b/vesta/src/fields/tests.rs index c572b2d..712cca0 100644 --- a/vesta/src/fields/tests.rs +++ b/vesta/src/fields/tests.rs @@ -1,7 +1,7 @@ use ark_algebra_test_templates::{ fields::*, generate_field_serialization_test, generate_field_test, }; -use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_std::{rand::Rng, test_rng}; use core::ops::{AddAssign, MulAssign, SubAssign};