Browse Source

Update `MNT4-753`

fq2_neg_nonresidue
Pratyush Mishra 3 years ago
parent
commit
4b050b1aae
6 changed files with 30 additions and 264 deletions
  1. +7
    -59
      mnt4_753/src/curves/g1.rs
  2. +7
    -85
      mnt4_753/src/curves/g2.rs
  3. +8
    -23
      mnt4_753/src/curves/mod.rs
  4. +2
    -2
      mnt4_753/src/curves/tests.rs
  5. +3
    -52
      mnt4_753/src/fields/fq2.rs
  6. +3
    -43
      mnt4_753/src/fields/fq4.rs

+ 7
- 59
mnt4_753/src/curves/g1.rs

@ -2,7 +2,7 @@ use ark_ec::{
mnt4,
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 = 2
#[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, BigInteger768([
3553860551672651396,
2565472393707818253,
3424927325234966109,
17487811826058095619,
15730291918544907998,
4332070408724822737,
7212646118208244402,
12904649141092619460,
9289117987390442562,
2254330573517213976,
3065472942259520298,
271095073719429,
]));
const COEFF_A: Fq = field_new!(Fq, "2");
/// COEFF_B = 0x01373684A8C9DCAE7A016AC5D7748D3313CD8E39051C596560835DF0C9E50A5B59B882A92C78DC537E51A16703EC9855C77FC3D8BB21C8D68BB8CFB9DB4B8C8FBA773111C36C8B1B4E8F1ECE940EF9EAAD265458E06372009C9A0491678EF4
#[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, BigInteger768([
2672638521926201442,
17587766986973859626,
1309143029066506763,
1756412671449422902,
5395165286423163724,
589638022240022974,
7360845090332416697,
9829497896347590557,
9341553552113883496,
5888515763059971584,
10173739464651404689,
456607542322059,
]));
const COEFF_B: Fq = field_new!(Fq, "28798803903456388891410036793299405764940372360099938340752576406393880372126970068421383312482853541572780087363938442377933706865252053507077543420534380486492786626556269083255657125025963825610840222568694137138741554679540");
/// COFACTOR = 1
const COFACTOR: &'static [u64] = &[1];
@ -69,36 +43,10 @@ impl SWModelParameters for Parameters {
// Generator of G1
// X = 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569,
// Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648,
/// G1_GENERATOR_X =
/// G1_GENERATOR_X = 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569
#[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger768([
9433494781491502420,
373642694095780604,
7974079134466535382,
15325904219470166885,
16825705122208020751,
898733863352481713,
3802318585082797759,
14417069684372068941,
4332882897981414838,
15138727514183191816,
16850594895992448907,
30598511593902
]));
pub const G1_GENERATOR_X: Fq = field_new!(Fq, "7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569");
/// G1_GENERATOR_Y =
/// G1_GENERATOR_Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648
#[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([
15710199097794077134,
3645667958306606136,
8298269426007169475,
5277073422205725562,
10451808582969862130,
14392820246664025579,
4365987620174557815,
14007263953321073101,
1355600847400958219,
3872959105252355444,
18016882244107198324,
424779036457857
]));
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648");

+ 7
- 85
mnt4_753/src/curves/g2.rs

@ -3,7 +3,7 @@ use ark_ec::{
mnt4::MNT4Parameters,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::{biginteger::BigInteger768, field_new};
use ark_ff::field_new;
use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
@ -41,20 +41,7 @@ impl SWModelParameters for Parameters {
#[rustfmt::skip]
const COEFF_B: Fq2 = field_new!(Fq2,
FQ_ZERO,
field_new!(Fq, BigInteger768([
15129916544657421551,
11332543254671606602,
11913830318987286849,
13905314883394440110,
16479690325073358448,
14869098639251228898,
10663986895980443550,
10768989312009479656,
9469728929095040349,
4512954369775881939,
8788997129423430122,
459763387588954,
])),
field_new!(Fq, "39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212")
);
/// COFACTOR =
@ -78,20 +65,7 @@ impl SWModelParameters for Parameters {
/// COFACTOR^(-1) mod r =
/// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200
#[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([
1879390364380281898,
7926794171490610432,
6437239504245874253,
16688141022047191858,
17059416847145768464,
15065047661241262516,
16537575340937777321,
3324411942044534547,
3878293904770657570,
18116939243856833744,
7557533897589069385,
78370361203778,
]));
const COFACTOR_INV: Fr = field_new!(Fr, "102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
@ -113,65 +87,13 @@ const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1
// Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654,
// 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245,
#[rustfmt::skip]
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger768([
7263636080534048301,
7643227961769035653,
15787777614640869937,
17661317895964274771,
4142647779394287783,
15064949873659932676,
4579259080596351332,
2207443675339702626,
5738725620118622838,
4338467638707299712,
6558861849926282439,
341078935870328
]));
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167");
#[rustfmt::skip]
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger768([
13073882729051113867,
195909455108318710,
10527070038778509320,
16605710222187477118,
10442518358308209073,
7776589986153052354,
16034091384000651523,
17429232381273855185,
512853344493546034,
7982076214836075255,
3601416800138513610,
399028695285184
]));
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000");
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger768([
4867672648970469422,
2453112364260322863,
11918672197974895143,
3923647310180624143,
12707123323825700670,
15781895092544451511,
17747112377690960911,
16511994611001933567,
15360620366665804029,
10252080383738480571,
5722654046339742760,
316853130349807
]));
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654");
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger768([
17322957246732430708,
11825815087694023697,
7654216682602683900,
13544637981229618042,
17057060382219081849,
4038731408172002692,
6631723222530012253,
10585926166286435412,
16050667328028620117,
16598483946296156500,
11771818132648686020,
1230430296095
]));
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245");

+ 8
- 23
mnt4_753/src/curves/mod.rs

@ -1,7 +1,7 @@
use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
use ark_ff::{biginteger::BigInteger768, field_new, fields::FpParameters, Fp2};
use ark_ff::{biginteger::BigInteger768, field_new, Fp2};
use crate::{Fq, Fq2, Fq2Parameters, Fq4Parameters, FqParameters, Fr, FrParameters};
use crate::{Fq, Fq2, Fq2Parameters, Fq4Parameters, Fr};
pub mod g1;
pub mod g2;
@ -67,24 +67,9 @@ impl MNT4Parameters for Parameters {
}
// 26
pub const G1_COEFF_A_NON_RESIDUE: Fq = field_new!(
Fq,
BigInteger768([
16948538951764659373,
10775354577659735631,
12766795894854242596,
8684022258823474090,
973489465296612807,
3883945490221946200,
16178634811223492029,
16155746945640075033,
17642042187059426365,
10295720303844380352,
13265853240981244259,
39422991244875,
])
);
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 G1_COEFF_A_NON_RESIDUE: Fq = field_new!(Fq, "26");
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");

+ 2
- 2
mnt4_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 = MNT4_753::pairing(sa, b);
let ans2 = MNT4_753::pairing(a, sb);

+ 3
- 52
mnt4_753/src/fields/fq2.rs

@ -1,6 +1,5 @@
use crate::{Fq, FQ_ONE};
use ark_ff::{
biginteger::BigInteger768 as BigInteger,
field_new,
fields::fp2::{Fp2, Fp2Parameters},
};
@ -14,64 +13,16 @@ impl Fp2Parameters for Fq2Parameters {
// non_residue = 13
#[rustfmt::skip]
const NONRESIDUE: Fq = field_new!(Fq, BigInteger([
11881297496860141143,
13588356353764843511,
9969398190777826186,
17325157081734070311,
16341533986183788031,
8322434028726676858,
13631157743146294957,
8365783422740577875,
3010239015809771096,
11776256826687733591,
7214251687253691272,
268626707558702
]));
const NONRESIDUE: Fq = field_new!(Fq, "13");
// qnr = (8, 1)
const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = (
field_new!(
Fq,
BigInteger([
587330122779359758,
14352661462510473462,
17802452401246596498,
18018663494943049411,
17948754733747257098,
10253180574146027531,
6683223122694781837,
13573468617269213174,
5059368039312883748,
950479668716233863,
9936591501985804621,
88719447132658
])
),
FQ_ONE,
);
const QUADRATIC_NONRESIDUE: (Self::Fp, Self::Fp) = (field_new!(Fq, "8"), FQ_ONE);
// 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,
field_new!(
Fq,
BigInteger([
14260497802974073023,
5895249896161266456,
14682908860938702530,
17222385991615618722,
14621060510943733448,
10594887362868996148,
7477357615964975684,
12570239403004322603,
2180620924574446161,
12129628062772479841,
8853285699251153944,
362282887012814
])
),
field_new!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
];
}

+ 3
- 43
mnt4_753/src/fields/fq4.rs

@ -1,6 +1,5 @@
use crate::{Fq, Fq2, Fq2Parameters, FQ_ONE, FQ_ZERO};
use ark_ff::{
biginteger::BigInteger768 as BigInteger,
field_new,
fields::fp4::{Fp4, Fp4Parameters},
};
@ -22,47 +21,8 @@ impl Fp4Parameters for Fq4Parameters {
#[rustfmt::skip]
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[
FQ_ONE,
field_new!(Fq, BigInteger([
2732208433323581659,
2172983777736624684,
14351170316343013496,
6345300643186282385,
3197292113538174065,
1887663496013421009,
16627860175048929982,
1842296636815120666,
13463717484107308085,
721000253033730237,
1214767992212094798,
163570781165682,
])),
field_new!(Fq, BigInteger([
14260497802974073023,
5895249896161266456,
14682908860938702530,
17222385991615618722,
14621060510943733448,
10594887362868996148,
7477357615964975684,
12570239403004322603,
2180620924574446161,
12129628062772479841,
8853285699251153944,
362282887012814,
])),
field_new!(Fq, BigInteger([
4081847608632041254,
14228374352133326707,
11267574244067947896,
1174247187748832530,
10065542319823237575,
10873259071217986508,
12902564573729719519,
17180267336735511666,
11808206507871910973,
12535793096497356591,
18394626215023595103,
334259642706846,
])),
field_new!(Fq, "18691656569803771296244054523431852464958959799019013859007259692542121208304602539555350517075508287829753932558576476751900235650227380562700444433662761577027341858128610410779088384480737679672900770810745291515010467307990"),
field_new!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
field_new!(Fq, "23206834398115182106100160267808784663211750120934935212776243228483231604266504233503543246714830633588317039329677309362453490879357004638891167538350364891904062489821230132228897943262725174047727280881395973788104254381611"),
];
}

Loading…
Cancel
Save