Upgrade to work with latest ark-ff (#95)

Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
Pratyush Mishra
2022-03-07 13:12:03 -08:00
committed by GitHub
parent d0dc200f22
commit 1551d6d76c
231 changed files with 2830 additions and 4343 deletions

View File

@@ -0,0 +1,28 @@
modulus = 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160001
assert(modulus.is_prime())
Fp = GF(modulus)
generator = Fp(0);
for i in range(0, 20):
i = Fp(i);
neg_i = Fp(-i)
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
continue
elif i.is_primitive_root():
assert(i.is_primitive_root());
print("Generator: %d" % i)
generator = i
break
else:
assert(neg_i.is_primitive_root());
print("Generator: %d" % neg_i)
generator = neg_i
break
two_adicity = valuation(modulus - 1, 2);
trace = (modulus - 1) / 2**two_adicity;
two_adic_root_of_unity = generator^trace
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)

View File

@@ -0,0 +1,28 @@
modulus = 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689601
assert(modulus.is_prime())
Fp = GF(modulus)
generator = Fp(0);
for i in range(0, 20):
i = Fp(i);
neg_i = Fp(-i)
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
continue
elif i.is_primitive_root():
assert(i.is_primitive_root());
print("Generator: %d" % i)
generator = i
break
else:
assert(neg_i.is_primitive_root());
print("Generator: %d" % neg_i)
generator = neg_i
break
two_adicity = valuation(modulus - 1, 2);
trace = (modulus - 1) / 2**two_adicity;
two_adic_root_of_unity = generator^trace
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)

View File

@@ -1,6 +1,7 @@
use crate::Parameters;
use ark_r1cs_std::groups::mnt6;
use crate::Parameters;
/// An element of G1 in the MNT6-753 bilinear group.
pub type G1Var = mnt6::G1Var<Parameters>;
/// An element of G2 in the MNT6-753 bilinear group.

View File

@@ -1,13 +1,13 @@
use crate::{Fq, Fq3Parameters, Fq6Parameters};
use ark_r1cs_std::fields::{fp::FpVar, fp3::Fp3Var, fp6_2over3::Fp6Var};
use crate::{Fq, Fq3Config, Fq6Config};
/// A variable that is the R1CS equivalent of `crate::Fq`.
pub type FqVar = FpVar<Fq>;
/// A variable that is the R1CS equivalent of `crate::Fq3`.
pub type Fq3Var = Fp3Var<Fq3Parameters>;
pub type Fq3Var = Fp3Var<Fq3Config>;
/// A variable that is the R1CS equivalent of `crate::Fq6`.
pub type Fq6Var = Fp6Var<Fq6Parameters>;
pub type Fq6Var = Fp6Var<Fq6Config>;
#[test]
fn mnt6_753_field_gadgets_test() {

View File

@@ -1,6 +1,7 @@
use crate::Parameters;
/// Specifies the constraints for computing a pairing in the MNT6-753 bilinear group.
/// Specifies the constraints for computing a pairing in the MNT6-753 bilinear
/// group.
pub type PairingVar = ark_r1cs_std::pairing::mnt6::PairingVar<Parameters>;
#[test]

View File

@@ -2,7 +2,7 @@ use ark_ec::{
mnt6,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::field_new;
use ark_ff::MontFp;
use crate::{Fq, Fr, FR_ONE};
@@ -21,18 +21,15 @@ impl ModelParameters for Parameters {
const COFACTOR: &'static [u64] = &[1];
/// COFACTOR^(-1) mod r = 1
#[rustfmt::skip]
const COFACTOR_INV: Fr = FR_ONE;
}
impl SWModelParameters for Parameters {
/// COEFF_A = 11
#[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, "11");
const COEFF_A: Fq = MontFp!(Fq, "11");
/// COEFF_B = 0x7DA285E70863C79D56446237CE2E1468D14AE9BB64B2BB01B10E60A5D5DFE0A25714B7985993F62F03B22A9A3C737A1A1E0FCF2C43D7BF847957C34CCA1E3585F9A80A95F401867C4E80F4747FDE5ABA7505BA6FCF2485540B13DFC8468A
#[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, "11625908999541321152027340224010374716841167701783584648338908235410859267060079819722747939267925389062611062156601938166010098747920378738927832658133625454260115409075816187555055859490253375704728027944315501122723426879114");
const COEFF_B: Fq = MontFp!(Fq, "11625908999541321152027340224010374716841167701783584648338908235410859267060079819722747939267925389062611062156601938166010098747920378738927832658133625454260115409075816187555055859490253375704728027944315501122723426879114");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
@@ -44,10 +41,8 @@ impl SWModelParameters for Parameters {
// Y = 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569,
/// G1_GENERATOR_X =
/// 3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728,
#[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = field_new!(Fq, "3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728");
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "3458420969484235708806261200128850544017070333833944116801482064540723268149235477762870414664917360605949659630933184751526227993647030875167687492714052872195770088225183259051403087906158701786758441889742618916006546636728");
/// G1_GENERATOR_Y =
/// 27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569,
#[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569");
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "27460508402331965149626600224382137254502975979168371111640924721589127725376473514838234361114855175488242007431439074223827742813911899817930728112297763448010814764117701403540298764970469500339646563344680868495474127850569");

View File

@@ -3,7 +3,7 @@ use ark_ec::{
mnt6::MNT6Parameters,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::field_new;
use ark_ff::{CubicExt, MontFp};
use crate::{g1, Fq, Fq3, Fr, FQ_ZERO};
@@ -50,21 +50,18 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r =
/// 6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200
#[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, "6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200");
const COFACTOR_INV: Fr = MontFp!(Fr, "6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200");
}
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
/// = 11 * 11
/// = 121
#[rustfmt::skip]
pub const MUL_BY_A_C0: Fq = field_new!(Fq, "121");
pub const MUL_BY_A_C0: Fq = MontFp!(Fq, "121");
/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
/// = 11 * 11
/// = 121
#[rustfmt::skip]
pub const MUL_BY_A_C1: Fq = field_new!(Fq, "121");
pub const MUL_BY_A_C1: Fq = MontFp!(Fq, "121");
/// MUL_BY_A_C2 = COEFF_A
pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A;
@@ -81,10 +78,8 @@ impl SWModelParameters for Parameters {
// (2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251,
// 0, 0)
// ```
#[rustfmt::skip]
const COEFF_B: Fq3 = field_new!(
Fq3,
field_new!(Fq, "2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251"),
const COEFF_B: Fq3 = CubicExt!(
MontFp!(Fq, "2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251"),
FQ_ZERO,
FQ_ZERO,
);
@@ -95,8 +90,7 @@ impl SWModelParameters for Parameters {
#[inline(always)]
fn mul_by_a(elt: &Fq3) -> Fq3 {
field_new!(
Fq3,
CubicExt!(
MUL_BY_A_C0 * &elt.c1,
MUL_BY_A_C1 * &elt.c2,
MUL_BY_A_C2 * &elt.c0,
@@ -104,10 +98,8 @@ impl SWModelParameters for Parameters {
}
}
const G2_GENERATOR_X: Fq3 =
field_new!(Fq3, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2);
const G2_GENERATOR_Y: Fq3 =
field_new!(Fq3, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2);
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);
// Generator of G2
// These are three Fq elements each because X and Y (and Z) are elements of Fq^3
@@ -117,10 +109,10 @@ const G2_GENERATOR_Y: Fq3 =
// Y = 2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615,
// 7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497,
// 21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689,
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");
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_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");
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");

View File

@@ -2,9 +2,9 @@ use ark_ec::models::{
mnt6::{MNT6Parameters, MNT6},
SWModelParameters,
};
use ark_ff::{biginteger::BigInteger768, field_new, BigInt, Fp3};
use ark_ff::{biginteger::BigInteger768, BigInt, CubicExt, Fp3, MontFp};
use crate::{Fq, Fq3, Fq3Parameters, Fq6Parameters, Fr};
use crate::{Fq, Fq3Config, Fq6Config, Fr};
pub mod g1;
pub mod g2;
@@ -22,19 +22,16 @@ pub type MNT6_753 = MNT6<Parameters>;
pub struct Parameters;
impl MNT6Parameters for Parameters {
const TWIST: Fp3<Self::Fp3Params> = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
const TWIST: Fp3<Self::Fp3Config> = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
// A coefficient of MNT6-753 G2 =
// ```
// mnt6753_twist_coeff_a = mnt6753_Fq3(mnt6753_Fq::zero(), mnt6753_Fq::zero(),
// mnt6753_G1::coeff_a);
// = (ZERO, ZERO, A_COEFF);
// ```
#[rustfmt::skip]
const TWIST_COEFF_A: Fp3<Self::Fp3Params> = field_new!(Fq3,
FQ_ZERO,
FQ_ZERO,
g1::Parameters::COEFF_A,
);
const TWIST_COEFF_A: Fp3<Self::Fp3Config> =
CubicExt!(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] = &[
8824542903220142080,
@@ -64,13 +61,13 @@ impl MNT6Parameters for Parameters {
]);
type Fp = Fq;
type Fr = Fr;
type Fp3Params = Fq3Parameters;
type Fp6Params = Fq6Parameters;
type Fp3Config = Fq3Config;
type Fp6Config = Fq6Config;
type G1Parameters = self::g1::Parameters;
type G2Parameters = self::g2::Parameters;
}
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");
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");

View File

@@ -1,16 +1,14 @@
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{Field, One, PrimeField, UniformRand};
use ark_std::{rand::Rng, test_rng};
use crate::*;
use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
generate_product_of_pairings_test, groups::*, msm::*,
};
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{Field, One, PrimeField, UniformRand};
use ark_std::{rand::Rng, test_rng};
use core::ops::MulAssign;
use crate::*;
generate_g1_test!(mnt6_753; curve_tests; sw_tests;);
generate_g2_test!(mnt6_753; curve_tests; sw_tests;);
generate_bilinearity_test!(MNT6_753, Fq6);

View File

@@ -1 +1 @@
pub use ark_mnt4_753::{Fr as Fq, FrParameters as FqParameters};
pub use ark_mnt4_753::{Fr as Fq, FrConfig as FqConfig};

View File

@@ -1,23 +1,23 @@
use crate::{fq::Fq, FQ_ONE, FQ_ZERO};
use ark_ff::{
field_new,
fields::fp3::{Fp3, Fp3Parameters},
fields::fp3::{Fp3, Fp3Config},
CubicExt, MontFp,
};
pub type Fq3 = Fp3<Fq3Parameters>;
use crate::{fq::Fq, FQ_ONE, FQ_ZERO};
pub struct Fq3Parameters;
pub type Fq3 = Fp3<Fq3Config>;
impl Fp3Parameters for Fq3Parameters {
pub struct Fq3Config;
impl Fp3Config for Fq3Config {
type Fp = Fq;
#[rustfmt::skip]
const NONRESIDUE: Fq = field_new!(Fq, "11");
const NONRESIDUE: Fq = MontFp!(Fq, "11");
const TWO_ADICITY: u32 = 30;
#[rustfmt::skip]
const T_MINUS_ONE_DIV_TWO: &'static [u64] = &[
const TRACE_MINUS_ONE_DIV_TWO: &'static [u64] = &[
15439605736802142541,
18190868848461853149,
6220121510046940818,
@@ -56,9 +56,8 @@ impl Fp3Parameters for Fq3Parameters {
];
/// (11^T, 0, 0)
#[rustfmt::skip]
const QUADRATIC_NONRESIDUE_TO_T: (Fq, Fq, Fq) = (
field_new!(Fq, "22168644070733283197994897338612733221095941481265408161807376791727499343083607817089033595478370212662133368413166734396127674284827734481031659015434501966360165723728649019457855887066657739809176476252080335185730833468062"),
const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!(
MontFp!(Fq, "22168644070733283197994897338612733221095941481265408161807376791727499343083607817089033595478370212662133368413166734396127674284827734481031659015434501966360165723728649019457855887066657739809176476252080335185730833468062"),
FQ_ZERO,
FQ_ZERO,
);
@@ -67,15 +66,13 @@ impl Fp3Parameters for Fq3Parameters {
// c1[0] = 1,
// c1[1] = 24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132
// c1[2] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868,
#[rustfmt::skip]
const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
FQ_ONE,
field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"),
field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"),
MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"),
MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"),
];
// c2 = {c1[0], c1[2], c1[1]}
#[rustfmt::skip]
const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
FQ_ONE,
Self::FROBENIUS_COEFF_FP3_C1[2],

View File

@@ -1,18 +1,18 @@
use crate::{Fq, Fq3, Fq3Parameters, FQ_ONE, FQ_ZERO};
use ark_ff::{
field_new,
fields::fp6_2over3::{Fp6, Fp6Parameters},
fields::fp6_2over3::{Fp6, Fp6Config},
CubicExt, MontFp,
};
pub type Fq6 = Fp6<Fq6Parameters>;
use crate::{Fq, Fq3, Fq3Config, FQ_ONE, FQ_ZERO};
pub struct Fq6Parameters;
pub type Fq6 = Fp6<Fq6Config>;
impl Fp6Parameters for Fq6Parameters {
type Fp3Params = Fq3Parameters;
pub struct Fq6Config;
#[rustfmt::skip]
const NONRESIDUE: Fq3 = field_new!(Fq3, FQ_ZERO, FQ_ONE, FQ_ZERO);
impl Fp6Config for Fq6Config {
type Fp3Config = Fq3Config;
const NONRESIDUE: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
// Coefficients for the Frobenius automorphism.
// c1[0] = 1,
@@ -21,13 +21,12 @@ impl Fp6Parameters for Fq6Parameters {
// c1[3] = 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000
// c1[4] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868
// c1[5] = 17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869
#[rustfmt::skip]
const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
FQ_ONE,
field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133"),
field_new!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"),
field_new!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000"),
field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"),
field_new!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869"),
MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052133"),
MontFp!(Fq, "24129022407817241407134263419936114379815707076943508280977368156625538709102831814843582780138963119807143081677569721953561801075623741378629346409604471234573396989178424163772589090105392407118197799904755622897541183052132"),
MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160000"),
MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107868"),
MontFp!(Fq, "17769468560101711995209951371304522748355002843010440790806134764399814103468274958215310983651375801610927890210888755369611256415970113691066895445191924931148019336171640277697829047741006062493737919155152541323243293107869"),
];
}

View File

@@ -1 +1 @@
pub use ark_mnt4_753::{Fq as Fr, FqParameters as FrParameters};
pub use ark_mnt4_753::{Fq as Fr, FqConfig as FrConfig};

View File

@@ -10,5 +10,5 @@ pub use self::fq3::*;
pub mod fq6;
pub use self::fq6::*;
#[cfg(all(feature = "mnt6_753", test))]
#[cfg(test)]
mod tests;

View File

@@ -1,19 +1,21 @@
use ark_ff::{
fields::{models::fp6_2over3::*, quadratic_extension::QuadExtParameters},
Field,
use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test,
};
use ark_std::{rand::Rng, test_rng};
use ark_ff::{
fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig, SquareRootField},
Field, PrimeField,
};
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng, One, UniformRand, Zero};
use core::ops::{AddAssign, MulAssign, SubAssign};
use crate::*;
use ark_algebra_test_templates::{fields::*, generate_field_test};
use core::ops::{AddAssign, MulAssign, SubAssign};
generate_field_test!(mnt6_753;);
generate_field_test!(mnt6_753; fq3; fq6; mont(12, 12); );
generate_field_serialization_test!(mnt6_753;);
#[test]
fn test_fq3() {
fn test_fq3_more() {
let mut rng = test_rng();
let a: Fq3 = rng.gen();
let b: Fq3 = rng.gen();
@@ -21,16 +23,7 @@ fn test_fq3() {
sqrt_field_test(a);
frobenius_test::<Fq3, _>(Fq::characteristic(), 13);
assert_eq!(
a * Fq6Parameters::NONRESIDUE,
<Fp6ParamsWrapper<Fq6Parameters>>::mul_base_field_by_nonresidue(&a)
a * Fq6Config::NONRESIDUE,
<Fp6ConfigWrapper<Fq6Config>>::mul_base_field_by_nonresidue(&a)
);
}
#[test]
fn test_fq6() {
let mut rng = test_rng();
let a: Fq6 = rng.gen();
let b: Fq6 = rng.gen();
field_test(a, b);
frobenius_test::<Fq6, _>(Fq::characteristic(), 13);
}

View File

@@ -10,9 +10,10 @@
//! This library implements the MNT6_753 curve generated in
//! [\[BCTV14\]](https://eprint.iacr.org/2014/595). The name denotes that it is a
//! Miyaji--Nakabayashi--Takano curve of embedding degree 6, defined over a 753-bit (prime) field.
//! The main feature of this curve is that its scalar field and base field respectively equal the
//! base field and scalar field of MNT4_753.
//! Miyaji--Nakabayashi--Takano curve of embedding degree 6, defined over a
//! 753-bit (prime) field. The main feature of this curve is that its scalar
//! field and base field respectively equal the base field and scalar field of
//! MNT4_753.
//!
//! Curve information:
//! * Base field: q = 0x01C4C62D92C41110229022EEE2CDADB7F997505B8FAFED5EB7E8F96C97D87307FDB925E8A0ED8D99D124D9A15AF79DB26C5C28C859A99B3EEBCA9429212636B9DFF97634993AA4D6C381BC3F0057974EA099170FA13A4FD90776E240000001
@@ -25,7 +26,8 @@
//! * G2 curve equation: y^2 = x^3 + Ax + B, where
//! * A = Fq3(0, 0, a)
//! * B = Fq3(b * NON_RESIDUE, 0, 0)
//! * NON_RESIDUE = 11 is the cubic non-residue used to construct the extension field Fq3
//! * NON_RESIDUE = 11 is the cubic non-residue used to construct the
//! extension field Fq3
#[cfg(feature = "r1cs")]
pub mod constraints;