Update MNT4-298

This commit is contained in:
Pratyush Mishra
2020-12-09 00:12:57 -08:00
parent 4b050b1aae
commit 6f7235d939
6 changed files with 29 additions and 151 deletions

View File

@@ -3,7 +3,7 @@ use ark_ec::{
mnt4,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::{biginteger::BigInteger320, field_new};
use ark_ff::{field_new};
pub type G1Affine = mnt4::G1Affine<crate::Parameters>;
pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
@@ -21,24 +21,12 @@ impl SWModelParameters for Parameters {
/// COEFF_A = 2
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116
#[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, BigInteger320([
3568597988870129848,
15257338106490985450,
10069779447956199041,
5922375556522222383,
3858029504390,
]));
const COEFF_A: Fq = field_new!(Fq, "2");
/// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117
#[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, BigInteger320([
7842808090366692145,
288200302308193399,
4162060950790347941,
5488589108190218591,
1553456013645,
]));
const COEFF_B: Fq = field_new!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
/// COFACTOR = 1
const COFACTOR: &'static [u64] = &[1];
@@ -59,21 +47,9 @@ impl SWModelParameters for Parameters {
/// G1_GENERATOR_X
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137
#[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger320([
6046301378120906932,
15105298306031900263,
15757949605695610691,
6113949277267426050,
3063081829217,
]));
pub const G1_GENERATOR_X: Fq = field_new!(Fq, "60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838");
/// G1_GENERATOR_Y
/// Reference: https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138
#[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger320([
8798367863963590781,
9770379341721339603,
17697354471293810920,
15252694996423733496,
3845520398052,
]));
pub const G1_GENERATOR_Y: Fq = field_new!(Fq, "363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306");

View File

@@ -4,7 +4,7 @@ use ark_ec::{
mnt4::MNT4Parameters,
models::{ModelParameters, SWModelParameters},
};
use ark_ff::{biginteger::BigInteger320, field_new};
use ark_ff::field_new;
pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
@@ -40,13 +40,7 @@ impl SWModelParameters for Parameters {
#[rustfmt::skip]
const COEFF_B: Fq2 = field_new!(Fq2,
FQ_ZERO,
field_new!(Fq, BigInteger320([
9511110677122940475,
13403516020116973437,
1464701424831086967,
4646785117660390394,
1747881737068,
])),
field_new!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
);
/// COFACTOR =
@@ -63,13 +57,7 @@ impl SWModelParameters for Parameters {
/// COFACTOR^(-1) mod r =
/// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
#[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, BigInteger320([
8065818351154103109,
7537800592537321232,
747075088561892445,
6335802185495034136,
1874289794052,
]));
const COFACTOR_INV: Fr = field_new!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
@@ -87,41 +75,17 @@ const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, 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
// X = 438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708,
// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
#[rustfmt::skip]
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger320([
5356671649366391794,
2684151262065976452,
4683110650642896126,
10421299515941681582,
1618695480960
]));
pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708");
#[rustfmt::skip]
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger320([
133394645290266480,
15395232932057272770,
18271324022738539173,
9095178119640120034,
2303787573609
]));
pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641");
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger320([
16920448081812496532,
15580160192086626100,
3974467672100342742,
8216505962266760277,
2643162835232
]));
pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482");
#[rustfmt::skip]
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger320([
73816197493558356,
8663991890578965996,
11575903875707445958,
17953546933481201011,
2167465829200
]));
pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489");

View File

@@ -1,7 +1,7 @@
use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
use ark_ff::{biginteger::BigInteger320, field_new, fields::FpParameters, Fp2};
use ark_ff::{biginteger::BigInteger320, 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;
@@ -47,17 +47,8 @@ impl MNT4Parameters for Parameters {
}
// 34
pub const G1_COEFF_A_NON_RESIDUE: Fq = field_new!(
Fq,
BigInteger320([
9379015694948865065,
3933863906897692531,
7183785805598089445,
17382890709766103498,
3934325337380,
])
);
pub const FQ_ZERO: Fq = field_new!(Fq, BigInteger320([0, 0, 0, 0, 0]));
pub const FQ_ONE: Fq = field_new!(Fq, FqParameters::R);
pub const FR_ZERO: Fr = field_new!(Fr, BigInteger320([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, "34");
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");

View File

@@ -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_298::pairing(sa, b);
let ans2 = MNT4_298::pairing(a, sb);