mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-11 00:11:37 +01:00
Catch up with algebra (#106)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use ark_ec::{
|
||||
mnt4,
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
models::{short_weierstrass::SWCurveConfig, CurveConfig},
|
||||
};
|
||||
use ark_ff::MontFp;
|
||||
use ark_ff::{Field, MontFp};
|
||||
|
||||
use crate::{Fq, Fr, FR_ONE};
|
||||
use crate::{Fq, Fr};
|
||||
|
||||
pub type G1Affine = mnt4::G1Affine<crate::Parameters>;
|
||||
pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
|
||||
@@ -13,7 +13,7 @@ pub type G1Prepared = mnt4::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,19 +21,18 @@ impl ModelParameters for Parameters {
|
||||
const COFACTOR: &'static [u64] = &[1];
|
||||
|
||||
/// COFACTOR^(-1) mod r = 1
|
||||
const COFACTOR_INV: Fr = FR_ONE;
|
||||
const COFACTOR_INV: Fr = Fr::ONE;
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
impl SWCurveConfig for Parameters {
|
||||
/// COEFF_A = 2
|
||||
const COEFF_A: Fq = MontFp!(Fq, "2");
|
||||
const COEFF_A: Fq = MontFp!("2");
|
||||
|
||||
/// COEFF_B = 0x01373684A8C9DCAE7A016AC5D7748D3313CD8E39051C596560835DF0C9E50A5B59B882A92C78DC537E51A16703EC9855C77FC3D8BB21C8D68BB8CFB9DB4B8C8FBA773111C36C8B1B4E8F1ECE940EF9EAAD265458E06372009C9A0491678EF4
|
||||
const COEFF_B: Fq = MontFp!(Fq, "28798803903456388891410036793299405764940372360099938340752576406393880372126970068421383312482853541572780087363938442377933706865252053507077543420534380486492786626556269083255657125025963825610840222568694137138741554679540");
|
||||
const COEFF_B: Fq = MontFp!("28798803903456388891410036793299405764940372360099938340752576406393880372126970068421383312482853541572780087363938442377933706865252053507077543420534380486492786626556269083255657125025963825610840222568694137138741554679540");
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
// Generator of G1
|
||||
@@ -41,8 +40,8 @@ impl SWModelParameters for Parameters {
|
||||
// Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648,
|
||||
/// G1_GENERATOR_X =
|
||||
/// 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569
|
||||
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569");
|
||||
pub const G1_GENERATOR_X: Fq = MontFp!("7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569");
|
||||
|
||||
/// G1_GENERATOR_Y =
|
||||
/// 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648
|
||||
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648");
|
||||
pub const G1_GENERATOR_Y: Fq = MontFp!("6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648");
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use ark_ec::{
|
||||
mnt4,
|
||||
mnt4::MNT4Parameters,
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
models::{short_weierstrass::SWCurveConfig, CurveConfig},
|
||||
};
|
||||
use ark_ff::{MontFp, QuadExt};
|
||||
use ark_ff::{Field, MontFp};
|
||||
|
||||
use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
|
||||
use crate::{Fq, Fq2, Fr, G1_COEFF_A_NON_RESIDUE};
|
||||
|
||||
pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
|
||||
pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
|
||||
@@ -14,7 +14,7 @@ pub type G2Prepared = mnt4::G2Prepared<crate::Parameters>;
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl ModelParameters for Parameters {
|
||||
impl CurveConfig for Parameters {
|
||||
type BaseField = Fq2;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -38,7 +38,7 @@ impl ModelParameters for Parameters {
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
|
||||
const COFACTOR_INV: Fr = MontFp!("102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
|
||||
}
|
||||
|
||||
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
|
||||
@@ -47,7 +47,7 @@ pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
|
||||
/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
|
||||
pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
impl SWCurveConfig for Parameters {
|
||||
const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
|
||||
// B coefficient of MNT4-753 G2 =
|
||||
// ```
|
||||
@@ -58,23 +58,22 @@ impl SWModelParameters for Parameters {
|
||||
// =
|
||||
// (0, 39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212)
|
||||
// ```
|
||||
const COEFF_B: Fq2 = QuadExt!(
|
||||
FQ_ZERO,
|
||||
MontFp!(Fq, "39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212")
|
||||
const COEFF_B: Fq2 = Fq2::new(
|
||||
Fq::ZERO,
|
||||
MontFp!("39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212")
|
||||
);
|
||||
|
||||
/// 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: &Fq2) -> Fq2 {
|
||||
QuadExt!(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
|
||||
Fq2::new(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1)
|
||||
}
|
||||
}
|
||||
|
||||
const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
const G2_GENERATOR_Y: Fq2 = Fq2::new(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
|
||||
@@ -82,10 +81,10 @@ const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
// 19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000,
|
||||
// Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654,
|
||||
// 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245,
|
||||
pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167");
|
||||
pub const G2_GENERATOR_X_C0: Fq = MontFp!("29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167");
|
||||
|
||||
pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000");
|
||||
pub const G2_GENERATOR_X_C1: Fq = MontFp!("19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000");
|
||||
|
||||
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654");
|
||||
pub const G2_GENERATOR_Y_C0: Fq = MontFp!("39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654");
|
||||
|
||||
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245");
|
||||
pub const G2_GENERATOR_Y_C1: Fq = MontFp!("17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger768},
|
||||
Fp2, MontFp, QuadExt,
|
||||
Field, Fp2, MontFp,
|
||||
};
|
||||
|
||||
use crate::{Fq, Fq2Config, Fq4Config, Fr};
|
||||
@@ -22,14 +22,14 @@ pub type MNT4_753 = MNT4<Parameters>;
|
||||
pub struct Parameters;
|
||||
|
||||
impl MNT4Parameters for Parameters {
|
||||
const TWIST: Fp2<Self::Fp2Config> = QuadExt!(FQ_ZERO, FQ_ONE);
|
||||
const TWIST: Fp2<Self::Fp2Config> = Fp2::new(Fq::ZERO, Fq::ONE);
|
||||
// A coefficient of MNT4-753 G2 =
|
||||
// ```
|
||||
// mnt4753_twist_coeff_a = mnt4753_Fq2(mnt4753_G1::coeff_a * non_residue, mnt6753_Fq::zero());
|
||||
// = (A_COEFF * NONRESIDUE, ZERO)
|
||||
// = (26, ZERO)
|
||||
// ```
|
||||
const TWIST_COEFF_A: Fp2<Self::Fp2Config> = QuadExt!(G1_COEFF_A_NON_RESIDUE, FQ_ZERO,);
|
||||
const TWIST_COEFF_A: Fp2<Self::Fp2Config> = Fp2::new(G1_COEFF_A_NON_RESIDUE, Fq::ZERO);
|
||||
// https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt4753.ml
|
||||
const ATE_LOOP_COUNT: &'static [u64] = &[
|
||||
8824542903220142080,
|
||||
@@ -66,9 +66,4 @@ impl MNT4Parameters for Parameters {
|
||||
}
|
||||
|
||||
// 26
|
||||
pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!(Fq, "26");
|
||||
|
||||
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");
|
||||
pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!("26");
|
||||
|
||||
@@ -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::fp2::{Fp2, Fp2Config},
|
||||
MontFp,
|
||||
Field, MontFp,
|
||||
};
|
||||
|
||||
use crate::{Fq, FQ_ONE};
|
||||
use crate::Fq;
|
||||
|
||||
pub type Fq2 = Fp2<Fq2Config>;
|
||||
|
||||
@@ -13,13 +13,13 @@ impl Fp2Config for Fq2Config {
|
||||
type Fp = Fq;
|
||||
|
||||
// non_residue = 13
|
||||
const NONRESIDUE: Fq = MontFp!(Fq, "13");
|
||||
const NONRESIDUE: Fq = MontFp!("13");
|
||||
|
||||
// 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,
|
||||
MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
|
||||
Fq::ONE,
|
||||
MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use ark_ff::{
|
||||
fields::fp4::{Fp4, Fp4Config},
|
||||
MontFp, QuadExt,
|
||||
Field, MontFp,
|
||||
};
|
||||
|
||||
use crate::{Fq, Fq2, Fq2Config, FQ_ONE, FQ_ZERO};
|
||||
use crate::{Fq, Fq2, Fq2Config};
|
||||
|
||||
pub type Fq4 = Fp4<Fq4Config>;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct Fq4Config;
|
||||
impl Fp4Config for Fq4Config {
|
||||
type Fp2Config = Fq2Config;
|
||||
|
||||
const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE);
|
||||
const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE);
|
||||
|
||||
// Coefficients for the Frobenius automorphism.
|
||||
// c1[0] = 1,
|
||||
@@ -23,9 +23,9 @@ impl Fp4Config for Fq4Config {
|
||||
// These are calculated as `FROBENIUS_COEFF_FP4_C1[i] =
|
||||
// Fp2Config::NONRESIDUE^((q^i - 1) / 4)`.
|
||||
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[
|
||||
FQ_ONE,
|
||||
MontFp!(Fq, "18691656569803771296244054523431852464958959799019013859007259692542121208304602539555350517075508287829753932558576476751900235650227380562700444433662761577027341858128610410779088384480737679672900770810745291515010467307990"),
|
||||
MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
|
||||
MontFp!(Fq, "23206834398115182106100160267808784663211750120934935212776243228483231604266504233503543246714830633588317039329677309362453490879357004638891161288350364891904062489821230132228897943262725174047727280881395973788104254381611"),
|
||||
Fq::ONE,
|
||||
MontFp!("18691656569803771296244054523431852464958959799019013859007259692542121208304602539555350517075508287829753932558576476751900235650227380562700444433662761577027341858128610410779088384480737679672900770810745291515010467307990"),
|
||||
MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
|
||||
MontFp!("23206834398115182106100160267808784663211750120934935212776243228483231604266504233503543246714830633588317039329677309362453490879357004638891161288350364891904062489821230132228897943262725174047727280881395973788104254381611"),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
Reference in New Issue
Block a user