From 5f62fab1699bc55a1ef3a67e538964cbf2f794c2 Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Tue, 8 Dec 2020 23:38:10 -0800 Subject: [PATCH] Update `MNT6-753` --- mnt6_753/src/curves/g1.rs | 64 ++------------ mnt6_753/src/curves/g2.rs | 166 ++++------------------------------- mnt6_753/src/curves/mod.rs | 13 ++- mnt6_753/src/curves/tests.rs | 4 +- mnt6_753/src/fields/fq3.rs | 69 ++------------- mnt6_753/src/fields/fq6.rs | 76 ++-------------- 6 files changed, 43 insertions(+), 349 deletions(-) diff --git a/mnt6_753/src/curves/g1.rs b/mnt6_753/src/curves/g1.rs index a1ac6eb..afc38a1 100644 --- a/mnt6_753/src/curves/g1.rs +++ b/mnt6_753/src/curves/g1.rs @@ -2,7 +2,7 @@ use ark_ec::{ mnt6, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{biginteger::BigInteger768, field_new}; +use ark_ff::{field_new}; use crate::{Fq, Fr, FR_ONE}; @@ -21,37 +21,11 @@ impl ModelParameters for Parameters { impl SWModelParameters for Parameters { /// COEFF_A = 11 #[rustfmt::skip] - const COEFF_A: Fq = field_new!(Fq, BigInteger768([ - 5145524327033718740, - 14149824967095184544, - 5159730833497260295, - 3902941467692815387, - 15830098551216085679, - 8665641533746801158, - 17502192300007146323, - 14483698255198590748, - 546300946688995976, - 4331975528992054828, - 5311428878520309260, - 495362057711802, - ])); + const COEFF_A: Fq = field_new!(Fq, "11"); /// COEFF_B = 0x7DA285E70863C79D56446237CE2E1468D14AE9BB64B2BB01B10E60A5D5DFE0A25714B7985993F62F03B22A9A3C737A1A1E0FCF2C43D7BF847957C34CCA1E3585F9A80A95F401867C4E80F4747FDE5ABA7505BA6FCF2485540B13DFC8468A #[rustfmt::skip] - const COEFF_B: Fq = field_new!(Fq, BigInteger768([ - 8828711393625909642, - 12722539140758597443, - 2303826860244282256, - 8063890988281098391, - 6269149169423748670, - 3425772737529456013, - 1457017085322601211, - 5177155908178255133, - 18057960053344868113, - 10481469207136524576, - 17888199912367160320, - 290288558853910, - ])); + const COEFF_B: Fq = field_new!(Fq, "11625908999541321152027340224010374716841167701783584648338908235410859267060079819722747939267925389062611062156601938166010098747920378738927832658133625454260115409075816187555055859490253375704728027944315501122723426879114"); /// COFACTOR = 1 const COFACTOR: &'static [u64] = &[1]; @@ -70,35 +44,11 @@ impl SWModelParameters for Parameters { // X = 3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728, // Y = 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569, /// G1_GENERATOR_X = +/// 3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728, #[rustfmt::skip] -pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger768([ - 16404456614462158210, - 16873534995404346316, - 29580875041164893, - 12740551787746921884, - 16087583716780115490, - 15096170813200936110, - 930080103225705610, - 660122182606823185, - 5211213138865083410, - 15466479635231681544, - 11783401481713071326, - 20214808394592 -])); +pub const G1_GENERATOR_X: Fq = field_new!(Fq, "3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728"); /// G1_GENERATOR_Y = +/// 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569, #[rustfmt::skip] -pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([ - 11636140615878154554, - 15149343852908177063, - 14426639389651280896, - 12711360703798958610, - 3787948290527586979, - 7628180411662927078, - 17195203689728925717, - 6800476327444280291, - 2228796880865780105, - 15627033749683396124, - 13783535191786892346, - 61400438920476 -])); +pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569"); diff --git a/mnt6_753/src/curves/g2.rs b/mnt6_753/src/curves/g2.rs index eee092d..b43911e 100644 --- a/mnt6_753/src/curves/g2.rs +++ b/mnt6_753/src/curves/g2.rs @@ -3,7 +3,7 @@ use ark_ec::{ mnt6::MNT6Parameters, models::{ModelParameters, SWModelParameters}, }; -use ark_ff::{biginteger::BigInteger768, field_new}; +use ark_ff::{field_new}; use crate::{g1, Fq, Fq3, Fr, FQ_ZERO}; @@ -20,38 +20,16 @@ impl ModelParameters for Parameters { } /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A +/// = 11 * 11 +/// = 121 #[rustfmt::skip] -pub const MUL_BY_A_C0: Fq = field_new!(Fq, BigInteger768([ - 10895242587870565906, - 6757387713923212228, - 12683949709867392876, - 1229095484098138811, - 18111217745394181988, - 3648021353977015866, - 7900332254549424237, - 5988529219097278134, - 11544487525720487778, - 7317517692149492894, - 9905728181042915773, - 470678396104534 -])); +pub const MUL_BY_A_C0: Fq = field_new!(Fq, "121"); /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A +/// = 11 * 11 +/// = 121 #[rustfmt::skip] -pub const MUL_BY_A_C1: Fq = field_new!(Fq, BigInteger768([ - 10895242587870565906, - 6757387713923212228, - 12683949709867392876, - 1229095484098138811, - 18111217745394181988, - 3648021353977015866, - 7900332254549424237, - 5988529219097278134, - 11544487525720487778, - 7317517692149492894, - 9905728181042915773, - 470678396104534 -])); +pub const MUL_BY_A_C1: Fq = field_new!(Fq, "121"); /// MUL_BY_A_C2 = COEFF_A pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A; @@ -71,20 +49,7 @@ impl SWModelParameters for Parameters { #[rustfmt::skip] const COEFF_B: Fq3 = field_new!( Fq3, - field_new!(Fq, BigInteger768([ - 3284231658830416104, - 13720030246451177991, - 6276939417009443243, - 8340612253649729185, - 4863511590806861670, - 15883218135158530927, - 4865336109262680856, - 16600307443495218926, - 10112528487499131659, - 17308657107605697754, - 5326857497786417651, - 206191604157846 - ])), + field_new!(Fq, "2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251"), FQ_ZERO, FQ_ZERO, ); @@ -122,20 +87,7 @@ impl SWModelParameters for Parameters { /// COFACTOR^(-1) mod r = /// 6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200 #[rustfmt::skip] - const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([ - 9418103049026957703, - 3464743017686961509, - 7872172759259099794, - 17514322419398292337, - 1496353716802911167, - 16961719271566193274, - 15426671498718617736, - 9230857178223113223, - 11731938389074297274, - 16450973680014766981, - 431917267220694852, - 94637508603012 - ])); + const COFACTOR_INV: Fr = field_new!(Fr, "6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200"); /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = @@ -165,98 +117,10 @@ const G2_GENERATOR_Y: Fq3 = // Y = 2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615, // 7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497, // 21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689, -#[rustfmt::skip] -pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger768([ - 12772807549130126376, - 2873211972983293592, - 15999100872160401842, - 5277158980096688998, - 12258756012310206056, - 11885883517271414939, - 6373672746025419911, - 13662747456330091710, - 11960680427306056040, - 15150766304321120168, - 9480712498131729809, - 413066879180657 -])); - -#[rustfmt::skip] -pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger768([ - 10478274013728260378, - 15392361149861123784, - 17610084573134912261, - 14474130264887792371, - 16754378329454263996, - 3186303078832273968, - 7143189323629797683, - 897486443141339765, - 3675579496642106405, - 4429391539758461550, - 18414257413872084180, - 331209511183940 -])); - -#[rustfmt::skip] -pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, BigInteger768([ - 5133712986240959624, - 10763134357204872827, - 8672341403101541980, - 18084133226637702602, - 4689040548070804594, - 7352115990101270007, - 14358820512747653623, - 10167201669589504005, - 3117673189936726036, - 9407838052466059644, - 7246385421116647671, - 464288782946273 -])); +pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "27250797394340459586637772414334383652934225310678303542554641987990991970766156209996739240400887081904395745019996048910447071686918567661896491214767494514394154061111870331668445455228882471000120574964265209669155206168252"); +pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "35762481056967998715733586393399457882827322353696313323665483142561285210083843314423554450886956650265947502285422529615273790981238406393402603210224104850580302463396274854098657541573494421834514772635884262388058080180368"); +pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, "36955296703808958167583270646821654948157955258947892285629161090141878438357164213613114995903637211606408001037026832604054121847388692538440756596264746452765613740820430501353237866984394057660379098674983614861254438847846"); -#[rustfmt::skip] -pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger768([ - 710862246533630948, - 9314168172257972041, - 4722111556929662508, - 4408676313209842703, - 10491088158750500898, - 13211840969745661306, - 13985341743807087374, - 7111198859398088665, - 158194789363472891, - 7682183069894584797, - 9510326135325230913, - 338826428359581 -])); - -#[rustfmt::skip] -pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger768([ - 10889422482835557076, - 6073207585023077555, - 16059368148547235058, - 14871121891082823821, - 15156344465408677175, - 12695157488434086405, - 7840105431702704631, - 4763759818130023465, - 12295696339556388640, - 352741974984397506, - 10581333776569094279, - 204002329498100 -])); - -#[rustfmt::skip] -pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, BigInteger768([ - 11263496889641203707, - 16306762242042931049, - 8275973312257833978, - 12034012818098316014, - 5392903691498465561, - 4572635011530974247, - 696221667645211601, - 11098678912660456319, - 5477755854538915619, - 11442390115310629698, - 10262065045802790037, - 17901561410539 -])); +pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615"); +pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497"); +pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, "21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689"); diff --git a/mnt6_753/src/curves/mod.rs b/mnt6_753/src/curves/mod.rs index bf233ed..1242279 100644 --- a/mnt6_753/src/curves/mod.rs +++ b/mnt6_753/src/curves/mod.rs @@ -1,11 +1,10 @@ -use ark_ff::{biginteger::BigInteger768, field_new, fields::FpParameters, Fp3}; - +use ark_ff::{biginteger::BigInteger768, field_new, Fp3}; use ark_ec::models::{ mnt6::{MNT6Parameters, MNT6}, SWModelParameters, }; -use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, FqParameters, Fr, FrParameters}; +use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, Fr}; pub mod g1; pub mod g2; @@ -71,7 +70,7 @@ impl MNT6Parameters for Parameters { type G2Parameters = self::g2::Parameters; } -pub const FQ_ZERO: Fq = field_new!(Fq, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])); -pub const FQ_ONE: Fq = field_new!(Fq, FqParameters::R); -pub const FR_ZERO: Fr = field_new!(Fr, BigInteger768([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])); -pub const FR_ONE: Fr = field_new!(Fr, FrParameters::R); +pub const FQ_ZERO: Fq = field_new!(Fq, "0"); +pub const FQ_ONE: Fq = field_new!(Fq, "1"); +pub const FR_ZERO: Fr = field_new!(Fr, "0"); +pub const FR_ONE: Fr = field_new!(Fr, "1"); diff --git a/mnt6_753/src/curves/tests.rs b/mnt6_753/src/curves/tests.rs index 5a03d3f..f8d27f3 100644 --- a/mnt6_753/src/curves/tests.rs +++ b/mnt6_753/src/curves/tests.rs @@ -57,8 +57,8 @@ fn test_bilinearity() { let b: G2Projective = rng.gen(); let s: Fr = rng.gen(); - let sa = a.mul(s); - let sb = b.mul(s); + let sa = a.mul(s.into_repr()); + let sb = b.mul(s.into_repr()); let ans1 = MNT6_753::pairing(sa, b); let ans2 = MNT6_753::pairing(a, sb); diff --git a/mnt6_753/src/fields/fq3.rs b/mnt6_753/src/fields/fq3.rs index 91e150a..7235b3b 100644 --- a/mnt6_753/src/fields/fq3.rs +++ b/mnt6_753/src/fields/fq3.rs @@ -1,6 +1,5 @@ -use crate::{fq::Fq, FQ_ONE}; +use crate::{fq::Fq, FQ_ONE, FQ_ZERO}; use ark_ff::{ - biginteger::BigInteger768 as BigInteger, field_new, fields::fp3::{Fp3, Fp3Parameters}, }; @@ -13,20 +12,7 @@ impl Fp3Parameters for Fq3Parameters { type Fp = Fq; #[rustfmt::skip] - const NONRESIDUE: Fq = field_new!(Fq, BigInteger([ - 5145524327033718740, - 14149824967095184544, - 5159730833497260295, - 3902941467692815387, - 15830098551216085679, - 8665641533746801158, - 17502192300007146323, - 14483698255198590748, - 546300946688995976, - 4331975528992054828, - 5311428878520309260, - 495362057711802, - ])); + const NONRESIDUE: Fq = field_new!(Fq, "11"); const TWO_ADICITY: u32 = 30; @@ -67,27 +53,14 @@ impl Fp3Parameters for Fq3Parameters { 1926648890365125214, 13532564555356297305, 3114545746551080, - 0, ]; + /// (11^T, 0, 0) #[rustfmt::skip] const QUADRATIC_NONRESIDUE_TO_T: (Fq, Fq, Fq) = ( - field_new!(Fq, BigInteger([ - 2456656400918202012, - 7503386575313625620, - 1014314685003569848, - 10473903647598823719, - 15893393002146336511, - 8418203974290622500, - 9017296731996077946, - 2923126592994124774, - 9368756030960215800, - 17344552888362241070, - 10938255746876359306, - 107029542386399, - ])), - field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])), - field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])), + field_new!(Fq, "22168644070733283197994897338612733221095941481265408161807376791727499343083607817089033595478370212662133368413166734396127674284827734481031659015434501966360165723728649019457855887066657739809176476252080335185730833468062"), + FQ_ZERO, + FQ_ZERO, ); // Coefficients for the Frobenius automorphism. @@ -97,34 +70,8 @@ impl Fp3Parameters for Fq3Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ FQ_ONE, - field_new!(Fq, BigInteger([ - 7739145380395648640, - 1403348385939055902, - 11220424057264707228, - 4567962295300549271, - 5929583493640677751, - 17618207486530478833, - 16600462137977359741, - 16551719371247820635, - 12057922785354578416, - 13022559182829558162, - 13308285686168533250, - 313705269181021, - ])), - field_new!(Fq, BigInteger([ - 12973180669431253567, - 17038664486452692616, - 11034024317238370177, - 7712681843988565810, - 4725787734130647531, - 2175028350442404679, - 9323639551697167751, - 14465264105466053583, - 8569442212929419360, - 17553812953652473294, - 13991744086792172309, - 48577617831792, - ])), + field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), + field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), ]; // c2 = {c1[0], c1[2], c1[1]} diff --git a/mnt6_753/src/fields/fq6.rs b/mnt6_753/src/fields/fq6.rs index 8c1a011..d5c872b 100644 --- a/mnt6_753/src/fields/fq6.rs +++ b/mnt6_753/src/fields/fq6.rs @@ -1,6 +1,5 @@ use crate::{Fq, Fq3, Fq3Parameters, FQ_ONE, FQ_ZERO}; use ark_ff::{ - biginteger::BigInteger768 as BigInteger, field_new, fields::fp6_2over3::{Fp6, Fp6Parameters}, }; @@ -25,75 +24,10 @@ impl Fp6Parameters for Fq6Parameters { #[rustfmt::skip] const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[ FQ_ONE, - field_new!(Fq, BigInteger([ - 2665418275744511426, - 7073776242814464967, - 4441331072847607829, - 5681016258918493042, - 18254896527151449163, - 10681724016023285331, - 1760041123371930134, - 4557299868084578750, - 16702481779049799698, - 14149724469588165150, - 5617650120443517591, - 449252806040736, - ])), - field_new!(Fq, BigInteger([ - 7739145380395648640, - 1403348385939055902, - 11220424057264707228, - 4567962295300549271, - 5929583493640677751, - 17618207486530478833, - 16600462137977359741, - 16551719371247820635, - 12057922785354578416, - 13022559182829558162, - 13308285686168533250, - 313705269181021, - ])), - field_new!(Fq, BigInteger([ - 2265581976117350591, - 18442012872391748519, - 3807704300793525789, - 12280644139289115082, - 10655371227771325282, - 1346491763263331896, - 7477357615964975877, - 12570239403004322603, - 2180620924574446161, - 12129628062772479841, - 8853285699251153944, - 362282887012814, - ])), - field_new!(Fq, BigInteger([ - 12973180669431253567, - 17038664486452692616, - 11034024317238370177, - 7712681843988565810, - 4725787734130647531, - 2175028350442404679, - 9323639551697167751, - 14465264105466053583, - 8569442212929419360, - 17553812953652473294, - 13991744086792172309, - 48577617831792, - ])), - field_new!(Fq, BigInteger([ - 7899453564780116353, - 4262348269618550065, - 4254931332821270779, - 8825735807606509581, - 17051100767641418943, - 13685288953644762793, - 12929962610801289759, - 2470844602302811697, - 13214001206624640642, - 234234166701528666, - 6301108521067156651, - 184125154691507, - ])), + field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133"), + field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"), + field_new!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000"), + field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"), + field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869"), ]; }