mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-11 08:21:33 +01:00
Catch up with algebra (#106)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -1,21 +1,19 @@
|
||||
use ark_ec::models::{
|
||||
twisted_edwards_extended::{
|
||||
GroupAffine as TEGroupAffine, GroupProjective as TEGroupProjective,
|
||||
short_weierstrass::{Affine as SWAffine, SWCurveConfig},
|
||||
twisted_edwards::{
|
||||
Affine as TEAffine, MontCurveConfig, Projective as TEProjective, TECurveConfig,
|
||||
},
|
||||
ModelParameters, MontgomeryModelParameters, SWModelParameters, TEModelParameters,
|
||||
CurveConfig,
|
||||
};
|
||||
use ark_ff::{MontFp, Zero};
|
||||
use ark_ff::{Field, MontFp, Zero};
|
||||
use core::ops::Neg;
|
||||
|
||||
use crate::{
|
||||
fields::{FQ_ONE, FQ_ZERO},
|
||||
Fq, Fr,
|
||||
};
|
||||
use crate::{Fq, Fr};
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl ModelParameters for Parameters {
|
||||
impl CurveConfig for Parameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -24,22 +22,18 @@ impl ModelParameters for Parameters {
|
||||
|
||||
/// COFACTOR_INV = COFACTOR^{-1} mod r
|
||||
/// = 5285428838741532253824584287042945485047145357130994810877
|
||||
const COFACTOR_INV: Fr = MontFp!(
|
||||
Fr,
|
||||
"5285428838741532253824584287042945485047145357130994810877"
|
||||
);
|
||||
const COFACTOR_INV: Fr = MontFp!("5285428838741532253824584287042945485047145357130994810877");
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
impl SWCurveConfig for Parameters {
|
||||
/// COEFF_A = 0
|
||||
const COEFF_A: Fq = FQ_ZERO;
|
||||
const COEFF_A: Fq = Fq::ZERO;
|
||||
|
||||
/// COEFF_B = 1
|
||||
const COEFF_B: Fq = FQ_ONE;
|
||||
const COEFF_B: Fq = Fq::ONE;
|
||||
|
||||
/// 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: G1SWAffine = G1SWAffine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
|
||||
@@ -47,8 +41,9 @@ impl SWModelParameters for Parameters {
|
||||
}
|
||||
}
|
||||
|
||||
pub type G1TEAffine = TEGroupAffine<Parameters>;
|
||||
pub type G1TEProjective = TEGroupProjective<Parameters>;
|
||||
pub type G1SWAffine = SWAffine<Parameters>;
|
||||
pub type G1TEAffine = TEAffine<Parameters>;
|
||||
pub type G1TEProjective = TEProjective<Parameters>;
|
||||
|
||||
/// Bls12_377::G1 also has a twisted Edwards form.
|
||||
/// It can be obtained via the following script, implementing
|
||||
@@ -97,18 +92,17 @@ pub type G1TEProjective = TEGroupProjective<Parameters>;
|
||||
/// # b = -TE1d/TE1a
|
||||
/// TE2d = Fp(122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179)
|
||||
/// ```
|
||||
impl TEModelParameters for Parameters {
|
||||
impl TECurveConfig for Parameters {
|
||||
/// COEFF_A = -1
|
||||
const COEFF_A: Fq = MontFp!(Fq, "-1");
|
||||
const COEFF_A: Fq = MontFp!("-1");
|
||||
|
||||
/// COEFF_D = 122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179 mod q
|
||||
const COEFF_D: Fq = MontFp!(Fq, "122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179");
|
||||
const COEFF_D: Fq = MontFp!("122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179");
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
(TE_GENERATOR_X, TE_GENERATOR_Y);
|
||||
const GENERATOR: G1TEAffine = G1TEAffine::new_unchecked(TE_GENERATOR_X, TE_GENERATOR_Y);
|
||||
|
||||
type MontgomeryModelParameters = Parameters;
|
||||
type MontCurveConfig = Parameters;
|
||||
|
||||
/// Multiplication by `a` is multiply by `-1`.
|
||||
#[inline(always)]
|
||||
@@ -146,23 +140,23 @@ impl TEModelParameters for Parameters {
|
||||
// # MB = s
|
||||
// MB=Fp(10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931)
|
||||
// ```
|
||||
impl MontgomeryModelParameters for Parameters {
|
||||
impl MontCurveConfig for Parameters {
|
||||
/// COEFF_A = 228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384
|
||||
const COEFF_A: Fq = MontFp!(Fq, "228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384");
|
||||
const COEFF_A: Fq = MontFp!("228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384");
|
||||
|
||||
/// COEFF_B = 10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931
|
||||
const COEFF_B: Fq = MontFp!(Fq, "10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931");
|
||||
const COEFF_B: Fq = MontFp!("10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931");
|
||||
|
||||
type TEModelParameters = Parameters;
|
||||
type TECurveConfig = Parameters;
|
||||
}
|
||||
|
||||
/// G1_GENERATOR_X =
|
||||
/// 81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695
|
||||
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695");
|
||||
pub const G1_GENERATOR_X: Fq = MontFp!("81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695");
|
||||
|
||||
/// G1_GENERATOR_Y =
|
||||
/// 241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030
|
||||
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030");
|
||||
pub const G1_GENERATOR_Y: Fq = MontFp!("241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030");
|
||||
|
||||
// The generator for twisted Edward form is the same SW generator converted into
|
||||
// the normalized TE form (TE2).
|
||||
@@ -210,8 +204,8 @@ pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "241266749859715473739788878240585681
|
||||
// ```
|
||||
/// TE_GENERATOR_X =
|
||||
/// 71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393
|
||||
pub const TE_GENERATOR_X: Fq = MontFp!(Fq, "71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393");
|
||||
pub const TE_GENERATOR_X: Fq = MontFp!("71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393");
|
||||
|
||||
/// TE_GENERATOR_Y =
|
||||
/// 6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235
|
||||
pub const TE_GENERATOR_Y: Fq = MontFp!(Fq, "6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235");
|
||||
pub const TE_GENERATOR_Y: Fq = MontFp!("6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235");
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use ark_ec::models::{ModelParameters, SWModelParameters};
|
||||
use ark_ff::{MontFp, QuadExt, Zero};
|
||||
use ark_ec::{
|
||||
models::{short_weierstrass::SWCurveConfig, CurveConfig},
|
||||
short_weierstrass::Affine,
|
||||
};
|
||||
use ark_ff::{Field, MontFp, Zero};
|
||||
|
||||
use crate::{fields::FQ_ZERO, g1, Fq, Fq2, Fr};
|
||||
use crate::{g1, Fq, Fq2, Fr};
|
||||
|
||||
pub type G2Affine = Affine<Parameters>;
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl ModelParameters for Parameters {
|
||||
impl CurveConfig for Parameters {
|
||||
type BaseField = Fq2;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -26,15 +30,13 @@ impl ModelParameters for Parameters {
|
||||
|
||||
/// COFACTOR_INV = COFACTOR^{-1} mod r
|
||||
/// = 6764900296503390671038341982857278410319949526107311149686707033187604810669
|
||||
const COFACTOR_INV: Fr = MontFp!(
|
||||
Fr,
|
||||
"6764900296503390671038341982857278410319949526107311149686707033187604810669"
|
||||
);
|
||||
const COFACTOR_INV: Fr =
|
||||
MontFp!("6764900296503390671038341982857278410319949526107311149686707033187604810669");
|
||||
}
|
||||
|
||||
impl SWModelParameters for Parameters {
|
||||
impl SWCurveConfig for Parameters {
|
||||
/// COEFF_A = [0, 0]
|
||||
const COEFF_A: Fq2 = QuadExt!(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A,);
|
||||
const COEFF_A: Fq2 = Fq2::new(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A);
|
||||
|
||||
// As per https://eprint.iacr.org/2012/072.pdf,
|
||||
// this curve has b' = b/i, where b is the COEFF_B of G1, and x^6 -i is
|
||||
@@ -42,14 +44,13 @@ impl SWModelParameters for Parameters {
|
||||
// In our case, i = u (App A.3, T_6).
|
||||
/// COEFF_B = [0,
|
||||
/// 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906]
|
||||
const COEFF_B: Fq2 = QuadExt!(
|
||||
FQ_ZERO,
|
||||
MontFp!(Fq, "155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906"),
|
||||
const COEFF_B: Fq2 = Fq2::new(
|
||||
Fq::ZERO,
|
||||
MontFp!("155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906"),
|
||||
);
|
||||
|
||||
/// 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(_: &Self::BaseField) -> Self::BaseField {
|
||||
@@ -57,21 +58,21 @@ impl SWModelParameters for Parameters {
|
||||
}
|
||||
}
|
||||
|
||||
pub const G2_GENERATOR_X: Fq2 = QuadExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
pub const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
|
||||
pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
|
||||
|
||||
/// G2_GENERATOR_X_C0 =
|
||||
/// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294
|
||||
pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294");
|
||||
pub const G2_GENERATOR_X_C0: Fq = MontFp!("233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294");
|
||||
|
||||
/// G2_GENERATOR_X_C1 =
|
||||
/// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118
|
||||
pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118");
|
||||
pub const G2_GENERATOR_X_C1: Fq = MontFp!("140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118");
|
||||
|
||||
/// G2_GENERATOR_Y_C0 =
|
||||
/// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423
|
||||
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423");
|
||||
pub const G2_GENERATOR_Y_C0: Fq = MontFp!("63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423");
|
||||
|
||||
/// G2_GENERATOR_Y_C1 =
|
||||
/// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491
|
||||
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491");
|
||||
pub const G2_GENERATOR_Y_C1: Fq = MontFp!("149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491");
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
use ark_algebra_test_templates::{
|
||||
curves::{curve_tests, edwards_tests, sw_tests},
|
||||
generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, generate_g2_test,
|
||||
groups::group_test,
|
||||
msm::test_var_base_msm,
|
||||
};
|
||||
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine};
|
||||
use ark_ec::{models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine};
|
||||
use ark_ff::{
|
||||
fields::{Field, PrimeField, SquareRootField},
|
||||
fields::{Field, PrimeField},
|
||||
One, Zero,
|
||||
};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign};
|
||||
|
||||
use crate::{
|
||||
g1, g2, Bls12_377, Fq, Fq12, Fr, G1Affine, G1Projective, G1TEProjective, G2Affine, G2Projective,
|
||||
};
|
||||
use crate::{g1, g2, Bls12_377, Fq, Fq12, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
|
||||
|
||||
generate_g1_test!(bls12_377; curve_tests; sw_tests; edwards_tests; te_group_tests;);
|
||||
generate_g1_test!(bls12_377; curve_tests; sw_tests; edwards_tests;);
|
||||
generate_g2_test!(bls12_377; curve_tests; sw_tests;);
|
||||
generate_bilinearity_test!(Bls12_377, Fq12);
|
||||
generate_g1_generator_raw_test!(bls12_377, 1);
|
||||
|
||||
Reference in New Issue
Block a user