mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 07:21:30 +01:00
Catch up with algebra (#106)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -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<crate::Parameters>;
|
||||
#[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");
|
||||
|
||||
@@ -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<crate::Parameters>;
|
||||
pub type G2Projective = mnt6::G2Projective<crate::Parameters>;
|
||||
@@ -14,7 +14,7 @@ pub type G2Prepared = mnt6::G2Prepared<crate::Parameters>;
|
||||
#[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"
|
||||
);
|
||||
|
||||
@@ -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<Parameters>;
|
||||
pub struct Parameters;
|
||||
|
||||
impl MNT6Parameters for Parameters {
|
||||
const TWIST: Fp3<Self::Fp3Config> = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
|
||||
const TWIST: Fp3<Self::Fp3Config> = Fp3::<Self::Fp3Config>::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
|
||||
const TWIST_COEFF_A: Fp3<Self::Fp3Config> =
|
||||
CubicExt!(FQ_ZERO, FQ_ZERO, g1::Parameters::COEFF_A,);
|
||||
Fp3::<Self::Fp3Config>::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");
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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<Fq3Config>;
|
||||
|
||||
@@ -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] = &[
|
||||
|
||||
@@ -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<Fq6Config>;
|
||||
|
||||
@@ -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"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user