Browse Source

Catch up with algebra (#106)

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
update-to-latest-arkworks
Marcin 2 years ago
committed by GitHub
parent
commit
93e64df895
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
120 changed files with 934 additions and 1653 deletions
  1. +2
    -2
      bls12_377/src/constraints/curves.rs
  2. +28
    -34
      bls12_377/src/curves/g1.rs
  3. +22
    -21
      bls12_377/src/curves/g2.rs
  4. +4
    -7
      bls12_377/src/curves/tests.rs
  5. +1
    -4
      bls12_377/src/fields/fq.rs
  6. +36
    -36
      bls12_377/src/fields/fq12.rs
  7. +4
    -7
      bls12_377/src/fields/fq2.rs
  8. +31
    -31
      bls12_377/src/fields/fq6.rs
  9. +1
    -1
      bls12_377/src/fields/tests.rs
  10. +14
    -17
      bls12_381/src/curves/g1.rs
  11. +23
    -29
      bls12_381/src/curves/g2.rs
  12. +5
    -3
      bls12_381/src/curves/tests.rs
  13. +1
    -4
      bls12_381/src/fields/fq.rs
  14. +38
    -38
      bls12_381/src/fields/fq12.rs
  15. +4
    -7
      bls12_381/src/fields/fq2.rs
  16. +38
    -38
      bls12_381/src/fields/fq6.rs
  17. +2
    -19
      bls12_381/src/fields/tests.rs
  18. +15
    -11
      bn254/src/curves/g1.rs
  19. +26
    -38
      bn254/src/curves/g2.rs
  20. +7
    -19
      bn254/src/curves/mod.rs
  21. +1
    -1
      bn254/src/curves/tests.rs
  22. +1
    -4
      bn254/src/fields/fq.rs
  23. +25
    -55
      bn254/src/fields/fq12.rs
  24. +4
    -7
      bn254/src/fields/fq2.rs
  25. +27
    -59
      bn254/src/fields/fq6.rs
  26. +1
    -1
      bn254/src/fields/tests.rs
  27. +13
    -14
      bw6_761/src/curves/g1.rs
  28. +13
    -14
      bw6_761/src/curves/g2.rs
  29. +1
    -1
      bw6_761/src/curves/tests.rs
  30. +1
    -4
      bw6_761/src/fields/fq.rs
  31. +13
    -16
      bw6_761/src/fields/fq3.rs
  32. +9
    -9
      bw6_761/src/fields/fq6.rs
  33. +2
    -2
      bw6_761/src/fields/tests.rs
  34. +12
    -13
      cp6_782/src/curves/g1.rs
  35. +23
    -24
      cp6_782/src/curves/g2.rs
  36. +6
    -6
      cp6_782/src/curves/mod.rs
  37. +1
    -1
      cp6_782/src/curves/tests.rs
  38. +1
    -4
      cp6_782/src/fields/fq.rs
  39. +13
    -13
      cp6_782/src/fields/fq3.rs
  40. +9
    -9
      cp6_782/src/fields/fq6.rs
  41. +2
    -2
      cp6_782/src/fields/tests.rs
  42. +1
    -1
      curve-benches/benches/bls12_377.rs
  43. +1
    -1
      curve-benches/benches/bls12_381.rs
  44. +1
    -3
      curve-benches/benches/bn254.rs
  45. +1
    -1
      curve-benches/benches/bw6_761.rs
  46. +1
    -1
      curve-benches/benches/cp6_782.rs
  47. +1
    -3
      curve-benches/benches/ed_on_bls12_381.rs
  48. +1
    -4
      curve-benches/benches/mnt4_298.rs
  49. +1
    -4
      curve-benches/benches/mnt4_753.rs
  50. +1
    -4
      curve-benches/benches/mnt6_298.rs
  51. +1
    -4
      curve-benches/benches/mnt6_753.rs
  52. +1
    -3
      curve-benches/benches/pallas.rs
  53. +1
    -3
      curve-benches/benches/vesta.rs
  54. +2
    -1
      curve-benches/src/macros/ec.rs
  55. +10
    -14
      curve-constraint-tests/src/lib.rs
  56. +1
    -1
      ed_on_bls12_377/src/constraints/mod.rs
  57. +22
    -32
      ed_on_bls12_377/src/curves/mod.rs
  58. +2
    -39
      ed_on_bls12_377/src/curves/tests.rs
  59. +1
    -1
      ed_on_bls12_377/src/fields/tests.rs
  60. +1
    -1
      ed_on_bls12_381/src/constraints/mod.rs
  61. +34
    -54
      ed_on_bls12_381/src/curves/mod.rs
  62. +3
    -57
      ed_on_bls12_381/src/curves/tests.rs
  63. +1
    -34
      ed_on_bls12_381/src/fields/tests.rs
  64. +1
    -1
      ed_on_bls12_381_bandersnatch/src/constraints/mod.rs
  65. +36
    -61
      ed_on_bls12_381_bandersnatch/src/curves/mod.rs
  66. +3
    -66
      ed_on_bls12_381_bandersnatch/src/curves/tests.rs
  67. +1
    -34
      ed_on_bls12_381_bandersnatch/src/fields/tests.rs
  68. +1
    -1
      ed_on_bn254/src/constraints/mod.rs
  69. +22
    -30
      ed_on_bn254/src/curves/mod.rs
  70. +3
    -52
      ed_on_bn254/src/curves/tests.rs
  71. +1
    -33
      ed_on_bn254/src/fields/tests.rs
  72. +1
    -1
      ed_on_bw6_761/src/constraints/mod.rs
  73. +1
    -1
      ed_on_cp6_782/src/constraints/mod.rs
  74. +17
    -17
      ed_on_cp6_782/src/curves/mod.rs
  75. +2
    -39
      ed_on_cp6_782/src/curves/tests.rs
  76. +1
    -1
      ed_on_cp6_782/src/fields/tests.rs
  77. +1
    -1
      ed_on_mnt4_298/src/constraints/mod.rs
  78. +14
    -17
      ed_on_mnt4_298/src/curves/mod.rs
  79. +2
    -47
      ed_on_mnt4_298/src/curves/tests.rs
  80. +1
    -1
      ed_on_mnt4_298/src/fields/tests.rs
  81. +1
    -1
      ed_on_mnt4_753/src/constraints/mod.rs
  82. +17
    -17
      ed_on_mnt4_753/src/curves/mod.rs
  83. +2
    -40
      ed_on_mnt4_753/src/curves/tests.rs
  84. +1
    -1
      ed_on_mnt4_753/src/fields/tests.rs
  85. +9
    -12
      mnt4_298/src/curves/g1.rs
  86. +13
    -18
      mnt4_298/src/curves/g2.rs
  87. +5
    -9
      mnt4_298/src/curves/mod.rs
  88. +1
    -1
      mnt4_298/src/curves/tests.rs
  89. +5
    -5
      mnt4_298/src/fields/fq2.rs
  90. +7
    -7
      mnt4_298/src/fields/fq4.rs
  91. +1
    -1
      mnt4_298/src/fields/tests.rs
  92. +11
    -12
      mnt4_753/src/curves/g1.rs
  93. +17
    -18
      mnt4_753/src/curves/g2.rs
  94. +4
    -9
      mnt4_753/src/curves/mod.rs
  95. +1
    -1
      mnt4_753/src/curves/tests.rs
  96. +5
    -5
      mnt4_753/src/fields/fq2.rs
  97. +7
    -7
      mnt4_753/src/fields/fq4.rs
  98. +1
    -1
      mnt4_753/src/fields/tests.rs
  99. +10
    -11
      mnt6_298/src/curves/g1.rs
  100. +15
    -23
      mnt6_298/src/curves/g2.rs

+ 2
- 2
bls12_377/src/constraints/curves.rs

@ -1,4 +1,4 @@
use ark_ec::{bls12::Bls12Parameters, ModelParameters};
use ark_ec::{bls12::Bls12Parameters, CurveConfig};
use ark_r1cs_std::{ use ark_r1cs_std::{
fields::fp::FpVar, fields::fp::FpVar,
groups::{bls12, curves::twisted_edwards::AffineVar as TEAffineVar}, groups::{bls12, curves::twisted_edwards::AffineVar as TEAffineVar},
@ -14,7 +14,7 @@ pub type G2Var = bls12::G2Var;
/// An element of G1 (in TE Affine form) in the BLS12-377 bilinear group. /// An element of G1 (in TE Affine form) in the BLS12-377 bilinear group.
pub type G1TEAffineVar = TEAffineVar< pub type G1TEAffineVar = TEAffineVar<
<Parameters as Bls12Parameters>::G1Parameters, <Parameters as Bls12Parameters>::G1Parameters,
FpVar<<<Parameters as Bls12Parameters>::G1Parameters as ModelParameters>::BaseField>,
FpVar<<<Parameters as Bls12Parameters>::G1Parameters as CurveConfig>::BaseField>,
>; >;
/// Represents the cached precomputation that can be performed on a G1 element /// Represents the cached precomputation that can be performed on a G1 element

+ 28
- 34
bls12_377/src/curves/g1.rs

@ -1,21 +1,19 @@
use ark_ec::models::{ 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 core::ops::Neg;
use crate::{
fields::{FQ_ONE, FQ_ZERO},
Fq, Fr,
};
use crate::{Fq, Fr};
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -24,22 +22,18 @@ impl ModelParameters for Parameters {
/// COFACTOR_INV = COFACTOR^{-1} mod r /// COFACTOR_INV = COFACTOR^{-1} mod r
/// = 5285428838741532253824584287042945485047145357130994810877 /// = 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 /// COEFF_A = 0
const COEFF_A: Fq = FQ_ZERO;
const COEFF_A: Fq = Fq::ZERO;
/// COEFF_B = 1 /// COEFF_B = 1
const COEFF_B: Fq = FQ_ONE;
const COEFF_B: Fq = Fq::ONE;
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { 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. /// Bls12_377::G1 also has a twisted Edwards form.
/// It can be obtained via the following script, implementing /// It can be obtained via the following script, implementing
@ -97,18 +92,17 @@ pub type G1TEProjective = TEGroupProjective;
/// # b = -TE1d/TE1a /// # b = -TE1d/TE1a
/// TE2d = Fp(122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179) /// TE2d = Fp(122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179)
/// ``` /// ```
impl TEModelParameters for Parameters {
impl TECurveConfig for Parameters {
/// COEFF_A = -1 /// COEFF_A = -1
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = 122268283598675559488486339158635529096981886914877139579534153582033676785385790730042363341236035746924960903179 mod q /// 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) /// 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`. /// Multiplication by `a` is multiply by `-1`.
#[inline(always)] #[inline(always)]
@ -146,23 +140,23 @@ impl TEModelParameters for Parameters {
// # MB = s // # MB = s
// MB=Fp(10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931) // MB=Fp(10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931)
// ``` // ```
impl MontgomeryModelParameters for Parameters {
impl MontCurveConfig for Parameters {
/// COEFF_A = 228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384 /// COEFF_A = 228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384
const COEFF_A: Fq = MontFp!(Fq, "228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384");
const COEFF_A: Fq = MontFp!("228097355113300204138531148905234651262148041026195375645000724271212049151994375092458297304264351187709081232384");
/// COEFF_B = 10189023633222963290707194929886294091415157242906428298294512798502806398782149227503530278436336312243746741931 /// 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 = /// G1_GENERATOR_X =
/// 81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695 /// 81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695");
pub const G1_GENERATOR_X: Fq = MontFp!("81937999373150964239938255573465948239988671502647976594219695644855304257327692006745978603320413799295628339695");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
/// 241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030 /// 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 generator for twisted Edward form is the same SW generator converted into
// the normalized TE form (TE2). // the normalized TE form (TE2).
@ -210,8 +204,8 @@ pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "241266749859715473739788878240585681
// ``` // ```
/// TE_GENERATOR_X = /// TE_GENERATOR_X =
/// 71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393 /// 71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393
pub const TE_GENERATOR_X: Fq = MontFp!(Fq, "71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393");
pub const TE_GENERATOR_X: Fq = MontFp!("71222569531709137229370268896323705690285216175189308202338047559628438110820800641278662592954630774340654489393");
/// TE_GENERATOR_Y = /// TE_GENERATOR_Y =
/// 6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235 /// 6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235
pub const TE_GENERATOR_Y: Fq = MontFp!(Fq, "6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235");
pub const TE_GENERATOR_Y: Fq = MontFp!("6177051365529633638563236407038680211609544222665285371549726196884440490905471891908272386851767077598415378235");

+ 22
- 21
bls12_377/src/curves/g2.rs

@ -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)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq2; type BaseField = Fq2;
type ScalarField = Fr; type ScalarField = Fr;
@ -26,15 +30,13 @@ impl ModelParameters for Parameters {
/// COFACTOR_INV = COFACTOR^{-1} mod r /// COFACTOR_INV = COFACTOR^{-1} mod r
/// = 6764900296503390671038341982857278410319949526107311149686707033187604810669 /// = 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] /// 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, // 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 // 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). // In our case, i = u (App A.3, T_6).
/// COEFF_B = [0, /// COEFF_B = [0,
/// 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906] /// 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) /// 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)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { 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 = /// G2_GENERATOR_X_C0 =
/// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294 /// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294
pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294");
pub const G2_GENERATOR_X_C0: Fq = MontFp!("233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294");
/// G2_GENERATOR_X_C1 = /// G2_GENERATOR_X_C1 =
/// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118 /// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118
pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118");
pub const G2_GENERATOR_X_C1: Fq = MontFp!("140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118");
/// G2_GENERATOR_Y_C0 = /// G2_GENERATOR_Y_C0 =
/// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423 /// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423");
pub const G2_GENERATOR_Y_C0: Fq = MontFp!("63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423");
/// G2_GENERATOR_Y_C1 = /// G2_GENERATOR_Y_C1 =
/// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491 /// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491");
pub const G2_GENERATOR_Y_C1: Fq = MontFp!("149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491");

+ 4
- 7
bls12_377/src/curves/tests.rs

@ -1,22 +1,19 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::{curve_tests, edwards_tests, sw_tests}, curves::{curve_tests, edwards_tests, sw_tests},
generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, generate_g2_test, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, generate_g2_test,
groups::group_test,
msm::test_var_base_msm, msm::test_var_base_msm,
}; };
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine};
use ark_ec::{models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine};
use ark_ff::{ use ark_ff::{
fields::{Field, PrimeField, SquareRootField},
fields::{Field, PrimeField},
One, Zero, One, Zero,
}; };
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign}; 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_g2_test!(bls12_377; curve_tests; sw_tests;);
generate_bilinearity_test!(Bls12_377, Fq12); generate_bilinearity_test!(Bls12_377, Fq12);
generate_g1_generator_raw_test!(bls12_377, 1); generate_g1_generator_raw_test!(bls12_377, 1);

+ 1
- 4
bls12_377/src/fields/fq.rs

@ -1,10 +1,7 @@
use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp};
use ark_ff::fields::{Fp384, MontBackend, MontConfig};
#[derive(MontConfig)] #[derive(MontConfig)]
#[modulus = "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177"] #[modulus = "258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177"]
#[generator = "15"] #[generator = "15"]
pub struct FqConfig; pub struct FqConfig;
pub type Fq = Fp384<MontBackend<FqConfig, 6>>; pub type Fq = Fp384<MontBackend<FqConfig, 6>>;
pub const FQ_ONE: Fq = Fq::new(FqConfig::R);
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");

+ 36
- 36
bls12_377/src/fields/fq12.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,65 +10,65 @@ pub struct Fq12Config;
impl Fp12Config for Fq12Config { impl Fp12Config for Fq12Config {
type Fp6Config = Fq6Config; type Fp6Config = Fq6Config;
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO);
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 6) // Fp2::NONRESIDUE^(((q^0) - 1) / 6)
QuadExt!(FQ_ONE, FQ_ZERO),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^(((q^1) - 1) / 6) // Fp2::NONRESIDUE^(((q^1) - 1) / 6)
QuadExt!(
MontFp!(Fq, "92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"),
FQ_ZERO,
Fq2::new(
MontFp!("92949345220277864758624960506473182677953048909283248980960104381795901929519566951595905490535835115111760994353"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 6) // Fp2::NONRESIDUE^(((q^2) - 1) / 6)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
FQ_ZERO,
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 6) // Fp2::NONRESIDUE^(((q^3) - 1) / 6)
QuadExt!(
MontFp!(Fq, "216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"),
FQ_ZERO,
Fq2::new(
MontFp!("216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^4) - 1) / 6) // Fp2::NONRESIDUE^(((q^4) - 1) / 6)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
FQ_ZERO,
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 6) // Fp2::NONRESIDUE^(((q^5) - 1) / 6)
QuadExt!(
MontFp!(Fq, "123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"),
FQ_ZERO,
Fq2::new(
MontFp!("123516416119946754630746545296132064952198520638002533875843642777304321125866014634106496325844844051843001220146"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^6) - 1) / 6) // Fp2::NONRESIDUE^(((q^6) - 1) / 6)
QuadExt!(
MontFp!(Fq, "-1"),
FQ_ZERO,
Fq2::new(
MontFp!("-1"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^7) - 1) / 6) // Fp2::NONRESIDUE^(((q^7) - 1) / 6)
QuadExt!(
MontFp!(Fq, "165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"),
FQ_ZERO,
Fq2::new(
MontFp!("165715080792691229252027773188420350858440463845631411558924158284924566418821255823372982649037525009328560463824"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^8) - 1) / 6) // Fp2::NONRESIDUE^(((q^8) - 1) / 6)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^9) - 1) / 6) // Fp2::NONRESIDUE^(((q^9) - 1) / 6)
QuadExt!(
MontFp!(Fq, "42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"),
FQ_ZERO,
Fq2::new(
MontFp!("42198664672744474621281227892288285906241943207628877683080515507620245292955241189266486323192680957485559243678"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^10) - 1) / 6) // Fp2::NONRESIDUE^(((q^10) - 1) / 6)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^11) - 1) / 6) // Fp2::NONRESIDUE^(((q^11) - 1) / 6)
QuadExt!(
MontFp!(Fq, "135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"),
FQ_ZERO,
Fq2::new(
MontFp!("135148009893022339379906188398761468584194992116912126664040619889416147222474808140862391813728516072597320238031"),
Fq::ZERO,
), ),
]; ];
} }

+ 4
- 7
bls12_377/src/fields/fq2.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config {
type Fp = Fq; type Fp = Fq;
/// NONRESIDUE = -5 /// NONRESIDUE = -5
const NONRESIDUE: Fq = MontFp!(Fq, "-5");
const NONRESIDUE: Fq = MontFp!("-5");
/// Coefficients for the Frobenius automorphism. /// Coefficients for the Frobenius automorphism.
const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
// NONRESIDUE**(((q^0) - 1) / 2) // NONRESIDUE**(((q^0) - 1) / 2)
FQ_ONE,
Fq::ONE,
// NONRESIDUE**(((q^1) - 1) / 2) // NONRESIDUE**(((q^1) - 1) / 2)
MontFp!(Fq, "-1"),
MontFp!("-1"),
]; ];
#[inline(always)] #[inline(always)]
@ -28,6 +28,3 @@ impl Fp2Config for Fq2Config {
fe - original fe - original
} }
} }
pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO);
pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO);

+ 31
- 31
bls12_377/src/fields/fq6.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -11,59 +11,59 @@ impl Fp6Config for Fq6Config {
type Fp2Config = Fq2Config; type Fp2Config = Fq2Config;
/// NONRESIDUE = U /// NONRESIDUE = U
const NONRESIDUE: Fq2 = QuadExt!(FQ_ZERO, FQ_ONE);
const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE);
const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 3) // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
QuadExt!(FQ_ONE, FQ_ZERO),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^(((q^1) - 1) / 3) // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
FQ_ZERO,
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 3) // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
FQ_ZERO,
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 3) // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
QuadExt!(MontFp!(Fq, "-1"), FQ_ZERO),
Fq2::new(MontFp!("-1"), Fq::ZERO),
// Fp2::NONRESIDUE^(((q^4) - 1) / 3) // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 3) // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
Fq::ZERO,
), ),
]; ];
const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
// Fp2::NONRESIDUE^((2*(q^0) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
QuadExt!(FQ_ONE, FQ_ZERO),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^((2*(q^1) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
FQ_ZERO
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
Fq::ZERO
), ),
// Fp2::NONRESIDUE^((2*(q^2) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^((2*(q^3) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
QuadExt!(FQ_ONE, FQ_ZERO),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^((2*(q^4) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
QuadExt!(
MontFp!(Fq, "80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
FQ_ZERO,
Fq2::new(
MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^((2*(q^5) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
QuadExt!(
MontFp!(Fq, "258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
FQ_ZERO,
Fq2::new(
MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
Fq::ZERO,
), ),
]; ];
@ -72,6 +72,6 @@ impl Fp6Config for Fq6Config {
// Karatsuba multiplication with constant other = u. // Karatsuba multiplication with constant other = u.
let c0 = Fq2Config::mul_fp_by_nonresidue(&fe.c1); let c0 = Fq2Config::mul_fp_by_nonresidue(&fe.c1);
let c1 = fe.c0; let c1 = fe.c0;
QuadExt!(c0, c1)
Fq2::new(c0, c1)
} }
} }

+ 1
- 1
bls12_377/src/fields/tests.rs

@ -3,7 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::{BigInt, BigInteger, BigInteger384}, biginteger::{BigInt, BigInteger, BigInteger384},
fields::{FftField, Field, Fp6Config, PrimeField, SquareRootField},
fields::{FftField, Field, Fp6Config, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};

+ 14
- 17
bls12_381/src/curves/g1.rs

@ -1,11 +1,11 @@
use ark_ec::{ use ark_ec::{
bls12, bls12,
bls12::Bls12Parameters, bls12::Bls12Parameters,
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::GroupAffine,
models::CurveConfig,
short_weierstrass::{Affine, SWCurveConfig},
AffineCurve, ProjectiveCurve, AffineCurve, ProjectiveCurve,
}; };
use ark_ff::{biginteger::BigInteger256, MontFp, Zero};
use ark_ff::{biginteger::BigInteger256, Field, MontFp, Zero};
use ark_std::ops::Neg; use ark_std::ops::Neg;
use crate::*; use crate::*;
@ -16,7 +16,7 @@ pub type G1Projective = bls12::G1Projective;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -25,22 +25,19 @@ impl ModelParameters for Parameters {
/// COFACTOR_INV = COFACTOR^{-1} mod r /// COFACTOR_INV = COFACTOR^{-1} mod r
/// = 52435875175126190458656871551744051925719901746859129887267498875565241663483 /// = 52435875175126190458656871551744051925719901746859129887267498875565241663483
const COFACTOR_INV: Fr = MontFp!(
Fr,
"52435875175126190458656871551744051925719901746859129887267498875565241663483"
);
const COFACTOR_INV: Fr =
MontFp!("52435875175126190458656871551744051925719901746859129887267498875565241663483");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = 0 /// COEFF_A = 0
const COEFF_A: Fq = MontFp!(Fq, "0");
const COEFF_A: Fq = Fq::ZERO;
/// COEFF_B = 4 /// COEFF_B = 4
const COEFF_B: Fq = MontFp!(Fq, "4");
const COEFF_B: Fq = MontFp!("4");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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);
#[inline(always)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
@ -71,16 +68,16 @@ impl SWModelParameters for Parameters {
/// G1_GENERATOR_X = /// G1_GENERATOR_X =
/// 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 /// 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507");
pub const G1_GENERATOR_X: Fq = MontFp!("3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
/// 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569 /// 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569");
pub const G1_GENERATOR_Y: Fq = MontFp!("1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569");
/// BETA is a non-trivial cubic root of unity in Fq. /// BETA is a non-trivial cubic root of unity in Fq.
pub const BETA: Fq = MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350");
pub const BETA: Fq = MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350");
pub fn endomorphism(p: &GroupAffine<Parameters>) -> GroupAffine<Parameters> {
pub fn endomorphism(p: &Affine<Parameters>) -> Affine<Parameters> {
// Endomorphism of the points on the curve. // Endomorphism of the points on the curve.
// endomorphism_p(x,y) = (BETA * x, y) // endomorphism_p(x,y) = (BETA * x, y)
// where BETA is a non-trivial cubic root of unity in Fq. // where BETA is a non-trivial cubic root of unity in Fq.

+ 23
- 29
bls12_381/src/curves/g2.rs

@ -1,11 +1,11 @@
use ark_ec::{ use ark_ec::{
bls12, bls12,
bls12::Bls12Parameters, bls12::Bls12Parameters,
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::GroupAffine,
models::CurveConfig,
short_weierstrass::{Affine, SWCurveConfig},
AffineCurve, AffineCurve,
}; };
use ark_ff::{BigInt, Field, MontFp, QuadExt, Zero};
use ark_ff::{BigInt, Field, MontFp, Zero};
use crate::*; use crate::*;
@ -15,7 +15,7 @@ pub type G2Projective = bls12::G2Projective;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq2; type BaseField = Fq2;
type ScalarField = Fr; type ScalarField = Fr;
@ -36,22 +36,19 @@ impl ModelParameters for Parameters {
/// COFACTOR_INV = COFACTOR^{-1} mod r /// COFACTOR_INV = COFACTOR^{-1} mod r
/// 26652489039290660355457965112010883481355318854675681319708643586776743290055 /// 26652489039290660355457965112010883481355318854675681319708643586776743290055
const COFACTOR_INV: Fr = MontFp!(
Fr,
"26652489039290660355457965112010883481355318854675681319708643586776743290055"
);
const COFACTOR_INV: Fr =
MontFp!("26652489039290660355457965112010883481355318854675681319708643586776743290055");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = [0, 0] /// 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);
/// COEFF_B = [4, 4] /// COEFF_B = [4, 4]
const COEFF_B: Fq2 = QuadExt!(g1::Parameters::COEFF_B, g1::Parameters::COEFF_B,);
const COEFF_B: Fq2 = Fq2::new(g1::Parameters::COEFF_B, g1::Parameters::COEFF_B);
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// 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)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
@ -74,48 +71,45 @@ 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 = /// G2_GENERATOR_X_C0 =
/// 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160 /// 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160
pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160");
pub const G2_GENERATOR_X_C0: Fq = MontFp!("352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160");
/// G2_GENERATOR_X_C1 = /// G2_GENERATOR_X_C1 =
/// 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758 /// 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758
pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758");
pub const G2_GENERATOR_X_C1: Fq = MontFp!("3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758");
/// G2_GENERATOR_Y_C0 = /// G2_GENERATOR_Y_C0 =
/// 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905 /// 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905");
pub const G2_GENERATOR_Y_C0: Fq = MontFp!("1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905");
/// G2_GENERATOR_Y_C1 = /// G2_GENERATOR_Y_C1 =
/// 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582 /// 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582");
pub const G2_GENERATOR_Y_C1: Fq = MontFp!("927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582");
// psi(x,y) = (x**p * PSI_X, y**p * PSI_Y) is the Frobenius composed // psi(x,y) = (x**p * PSI_X, y**p * PSI_Y) is the Frobenius composed
// with the quadratic twist and its inverse // with the quadratic twist and its inverse
// PSI_X = 1/(u+1)^((p-1)/3) // PSI_X = 1/(u+1)^((p-1)/3)
pub const P_POWER_ENDOMORPHISM_COEFF_0 : Fq2 = QuadExt!(
FQ_ZERO,
pub const P_POWER_ENDOMORPHISM_COEFF_0 : Fq2 = Fq2::new(
Fq::ZERO,
MontFp!( MontFp!(
Fq,
"4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"
"4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"
) )
); );
// PSI_Y = 1/(u+1)^((p-1)/2) // PSI_Y = 1/(u+1)^((p-1)/2)
pub const P_POWER_ENDOMORPHISM_COEFF_1: Fq2 = QuadExt!(
pub const P_POWER_ENDOMORPHISM_COEFF_1: Fq2 = Fq2::new(
MontFp!( MontFp!(
Fq,
"2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
"2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
MontFp!( MontFp!(
Fq,
"1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257")
"1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257")
); );
pub fn p_power_endomorphism(p: &GroupAffine<Parameters>) -> GroupAffine<Parameters> {
pub fn p_power_endomorphism(p: &Affine<Parameters>) -> Affine<Parameters> {
// The p-power endomorphism for G2 is defined as follows: // The p-power endomorphism for G2 is defined as follows:
// 1. Note that G2 is defined on curve E': y^2 = x^3 + 4(u+1). // 1. Note that G2 is defined on curve E': y^2 = x^3 + 4(u+1).
// To map a point (x, y) in E' to (s, t) in E, // To map a point (x, y) in E' to (s, t) in E,

+ 5
- 3
bls12_381/src/curves/tests.rs

@ -1,10 +1,12 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, curves::*, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test,
generate_g2_test, groups::*, msm::*,
generate_g2_test, msm::*,
};
use ark_ec::{
models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine, ProjectiveCurve,
}; };
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{ use ark_ff::{
fields::{Field, PrimeField, SquareRootField},
fields::{Field, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};

+ 1
- 4
bls12_381/src/fields/fq.rs

@ -1,10 +1,7 @@
use ark_ff::fields::{Fp384, MontBackend, MontConfig, MontFp};
use ark_ff::fields::{Fp384, MontBackend, MontConfig};
#[derive(MontConfig)] #[derive(MontConfig)]
#[modulus = "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"] #[modulus = "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"]
#[generator = "2"] #[generator = "2"]
pub struct FqConfig; pub struct FqConfig;
pub type Fq = Fp384<MontBackend<FqConfig, 6>>; pub type Fq = Fp384<MontBackend<FqConfig, 6>>;
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");

+ 38
- 38
bls12_381/src/fields/fq12.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,68 +10,68 @@ pub struct Fq12Config;
impl Fp12Config for Fq12Config { impl Fp12Config for Fq12Config {
type Fp6Config = Fq6Config; type Fp6Config = Fq6Config;
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO);
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 6) // Fp2::NONRESIDUE^(((q^0) - 1) / 6)
QuadExt!(
MontFp!(Fq, "1"),
MontFp!(Fq, "0"),
Fq2::new(
Fq::ONE,
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^1) - 1) / 6) // Fp2::NONRESIDUE^(((q^1) - 1) / 6)
QuadExt!(
MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
Fq2::new(
MontFp!("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
MontFp!("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 6) // Fp2::NONRESIDUE^(((q^2) - 1) / 6)
QuadExt!(
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 6) // Fp2::NONRESIDUE^(((q^3) - 1) / 6)
QuadExt!(
MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
Fq2::new(
MontFp!("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
MontFp!("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
), ),
// Fp2::NONRESIDUE^(((q^4) - 1) / 6) // Fp2::NONRESIDUE^(((q^4) - 1) / 6)
QuadExt!(
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 6) // Fp2::NONRESIDUE^(((q^5) - 1) / 6)
QuadExt!(
MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
Fq2::new(
MontFp!("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
MontFp!("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
), ),
// Fp2::NONRESIDUE^(((q^6) - 1) / 6) // Fp2::NONRESIDUE^(((q^6) - 1) / 6)
QuadExt!(
MontFp!(Fq, "-1"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("-1"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^7) - 1) / 6) // Fp2::NONRESIDUE^(((q^7) - 1) / 6)
QuadExt!(
MontFp!(Fq, "151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
MontFp!(Fq, "3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
Fq2::new(
MontFp!("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),
MontFp!("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),
), ),
// Fp2::NONRESIDUE^(((q^8) - 1) / 6) // Fp2::NONRESIDUE^(((q^8) - 1) / 6)
QuadExt!(
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^9) - 1) / 6) // Fp2::NONRESIDUE^(((q^9) - 1) / 6)
QuadExt!(
MontFp!(Fq, "1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
MontFp!(Fq, "2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
Fq2::new(
MontFp!("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),
MontFp!("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),
), ),
// Fp2::NONRESIDUE^(((q^10) - 1) / 6) // Fp2::NONRESIDUE^(((q^10) - 1) / 6)
QuadExt!(
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^11) - 1) / 6) // Fp2::NONRESIDUE^(((q^11) - 1) / 6)
QuadExt!(
MontFp!(Fq, "877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
MontFp!(Fq, "3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
Fq2::new(
MontFp!("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),
MontFp!("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),
), ),
]; ];
} }

+ 4
- 7
bls12_381/src/fields/fq2.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config {
type Fp = Fq; type Fp = Fq;
/// NONRESIDUE = -1 /// NONRESIDUE = -1
const NONRESIDUE: Fq = MontFp!(Fq, "-1");
const NONRESIDUE: Fq = MontFp!("-1");
/// Coefficients for the Frobenius automorphism. /// Coefficients for the Frobenius automorphism.
const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
// Fq(-1)**(((q^0) - 1) / 2) // Fq(-1)**(((q^0) - 1) / 2)
MontFp!(Fq, "1"),
Fq::ONE,
// Fq(-1)**(((q^1) - 1) / 2) // Fq(-1)**(((q^1) - 1) / 2)
MontFp!(Fq, "-1"),
MontFp!("-1"),
]; ];
#[inline(always)] #[inline(always)]
@ -25,6 +25,3 @@ impl Fp2Config for Fq2Config {
-(*fp) -(*fp)
} }
} }
pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO);
pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO);

+ 38
- 38
bls12_381/src/fields/fq6.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -11,72 +11,72 @@ impl Fp6Config for Fq6Config {
type Fp2Config = Fq2Config; type Fp2Config = Fq2Config;
/// NONRESIDUE = (U + 1) /// NONRESIDUE = (U + 1)
const NONRESIDUE: Fq2 = QuadExt!(FQ_ONE, FQ_ONE);
const NONRESIDUE: Fq2 = Fq2::new(Fq::ONE, Fq::ONE);
const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 3) // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
QuadExt!(
MontFp!(Fq, "1"),
MontFp!(Fq, "0"),
Fq2::new(
Fq::ONE,
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^1) - 1) / 3) // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
QuadExt!(
MontFp!(Fq, "0"),
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
Fq2::new(
Fq::ZERO,
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 3) // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
QuadExt!(
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 3) // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
QuadExt!(
MontFp!(Fq, "0"),
MontFp!(Fq, "1"),
Fq2::new(
Fq::ZERO,
Fq::ONE,
), ),
// Fp2::NONRESIDUE^(((q^4) - 1) / 3) // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
QuadExt!(
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 3) // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
QuadExt!(
MontFp!(Fq, "0"),
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
Fq2::new(
Fq::ZERO,
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
), ),
]; ];
#[rustfmt::skip] #[rustfmt::skip]
const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
// Fq2(u + 1)**(((2q^0) - 2) / 3) // Fq2(u + 1)**(((2q^0) - 2) / 3)
QuadExt!(
MontFp!(Fq, "1"),
MontFp!(Fq, "0"),
Fq2::new(
Fq::ONE,
Fq::ZERO,
), ),
// Fq2(u + 1)**(((2q^1) - 2) / 3) // Fq2(u + 1)**(((2q^1) - 2) / 3)
QuadExt!(
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
Fq::ZERO,
), ),
// Fq2(u + 1)**(((2q^2) - 2) / 3) // Fq2(u + 1)**(((2q^2) - 2) / 3)
QuadExt!(
MontFp!(Fq, "4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
Fq::ZERO,
), ),
// Fq2(u + 1)**(((2q^3) - 2) / 3) // Fq2(u + 1)**(((2q^3) - 2) / 3)
QuadExt!(
MontFp!(Fq, "-1"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("-1"),
Fq::ZERO,
), ),
// Fq2(u + 1)**(((2q^4) - 2) / 3) // Fq2(u + 1)**(((2q^4) - 2) / 3)
QuadExt!(
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
Fq::ZERO,
), ),
// Fq2(u + 1)**(((2q^5) - 2) / 3) // Fq2(u + 1)**(((2q^5) - 2) / 3)
QuadExt!(
MontFp!(Fq, "793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
Fq::ZERO,
), ),
]; ];

+ 2
- 19
bls12_381/src/fields/tests.rs

@ -3,7 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::{BigInt, BigInteger, BigInteger384}, biginteger::{BigInt, BigInteger, BigInteger384},
fields::{FftField, Field, Fp12Config, Fp2Config, Fp6Config, PrimeField, SquareRootField},
fields::{FftField, Field, Fp12Config, Fp2Config, Fp6Config, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
@ -21,7 +21,7 @@ generate_field_serialization_test!(bls12_381; fq2; fq6; fq12;);
#[test] #[test]
fn test_negative_one() { fn test_negative_one() {
let neg_one = Fq::new(BigInt::new([
let neg_one = Fq::new_unchecked(BigInt::new([
0x43f5fffffffcaaae, 0x43f5fffffffcaaae,
0x32b7fff2ed47fffd, 0x32b7fff2ed47fffd,
0x7e83a49a2e99d69, 0x7e83a49a2e99d69,
@ -739,23 +739,6 @@ fn test_frob_coeffs() {
); );
} }
#[test]
fn test_neg_one() {
let o = -Fq::one();
let thing: [u64; 6] = [
0x43f5fffffffcaaae,
0x32b7fff2ed47fffd,
0x7e83a49a2e99d69,
0xeca8f3318332bb7a,
0xef148d1ea0f4c069,
0x40ab3263eff0206,
];
let negative_one = Fq::new(BigInt::new(thing));
assert_eq!(negative_one, o);
}
#[test] #[test]
fn test_fq_repr_from() { fn test_fq_repr_from() {
assert_eq!(BigInt::from(100u64), BigInt::new([100, 0, 0, 0, 0, 0])); assert_eq!(BigInt::from(100u64), BigInt::new([100, 0, 0, 0, 0, 0]));

+ 15
- 11
bn254/src/curves/g1.rs

@ -1,12 +1,17 @@
use ark_ec::models::{ModelParameters, SWModelParameters};
use ark_ff::{MontFp, Zero};
use ark_ec::{
models::{short_weierstrass::SWCurveConfig, CurveConfig},
short_weierstrass::Affine,
};
use ark_ff::{Field, MontFp, Zero};
use crate::{Fq, Fr}; use crate::{Fq, Fr};
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
pub type G1Affine = Affine<Parameters>;
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -14,19 +19,18 @@ impl ModelParameters for Parameters {
const COFACTOR: &'static [u64] = &[0x1]; const COFACTOR: &'static [u64] = &[0x1];
/// COFACTOR_INV = COFACTOR^{-1} mod r = 1 /// COFACTOR_INV = 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 = 0 /// COEFF_A = 0
const COEFF_A: Fq = MontFp!(Fq, "0");
const COEFF_A: Fq = Fq::ZERO;
/// COEFF_B = 3 /// COEFF_B = 3
const COEFF_B: Fq = MontFp!(Fq, "3");
const COEFF_B: Fq = MontFp!("3");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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);
#[inline(always)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
@ -35,7 +39,7 @@ impl SWModelParameters for Parameters {
} }
/// G1_GENERATOR_X = 1 /// G1_GENERATOR_X = 1
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "1");
pub const G1_GENERATOR_X: Fq = Fq::ONE;
/// G1_GENERATOR_Y = 2 /// G1_GENERATOR_Y = 2
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "2");
pub const G1_GENERATOR_Y: Fq = MontFp!("2");

+ 26
- 38
bn254/src/curves/g2.rs

@ -1,12 +1,17 @@
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::{Fq, Fq2, Fr}; use crate::{Fq, Fq2, Fr};
pub type G2Affine = Affine<Parameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq2; type BaseField = Fq2;
type ScalarField = Fr; type ScalarField = Fr;
@ -21,32 +26,23 @@ impl ModelParameters for Parameters {
]; ];
/// COFACTOR_INV = COFACTOR^{-1} mod r /// COFACTOR_INV = COFACTOR^{-1} mod r
const COFACTOR_INV: Fr = MontFp!(
Fr,
"10944121435919637613327163357776759465618812564592884533313067514031822496649"
);
const COFACTOR_INV: Fr =
MontFp!("10944121435919637613327163357776759465618812564592884533313067514031822496649");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = [0, 0] /// COEFF_A = [0, 0]
const COEFF_A: Fq2 = QuadExt!(MontFp!(Fq, "0"), MontFp!(Fq, "0"));
const COEFF_A: Fq2 = Fq2::ZERO;
/// COEFF_B = 3/(u+9) /// COEFF_B = 3/(u+9)
/// (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690) /// (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690)
const COEFF_B: Fq2 = QuadExt!(
MontFp!(
Fq,
"19485874751759354771024239261021720505790618469301721065564631296452457478373"
),
MontFp!(
Fq,
"266929791119991161246907387137283842545076965332900288569378510910307636690"
),
const COEFF_B: Fq2 = Fq2::new(
MontFp!("19485874751759354771024239261021720505790618469301721065564631296452457478373"),
MontFp!("266929791119991161246907387137283842545076965332900288569378510910307636690"),
); );
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// 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)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
@ -54,33 +50,25 @@ 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 = /// G2_GENERATOR_X_C0 =
/// 10857046999023057135944570762232829481370756359578518086990519993285655852781 /// 10857046999023057135944570762232829481370756359578518086990519993285655852781
pub const G2_GENERATOR_X_C0: Fq = MontFp!(
Fq,
"10857046999023057135944570762232829481370756359578518086990519993285655852781"
);
pub const G2_GENERATOR_X_C0: Fq =
MontFp!("10857046999023057135944570762232829481370756359578518086990519993285655852781");
/// G2_GENERATOR_X_C1 = /// G2_GENERATOR_X_C1 =
/// 11559732032986387107991004021392285783925812861821192530917403151452391805634 /// 11559732032986387107991004021392285783925812861821192530917403151452391805634
pub const G2_GENERATOR_X_C1: Fq = MontFp!(
Fq,
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
);
pub const G2_GENERATOR_X_C1: Fq =
MontFp!("11559732032986387107991004021392285783925812861821192530917403151452391805634");
/// G2_GENERATOR_Y_C0 = /// G2_GENERATOR_Y_C0 =
/// 8495653923123431417604973247489272438418190587263600148770280649306958101930 /// 8495653923123431417604973247489272438418190587263600148770280649306958101930
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(
Fq,
"8495653923123431417604973247489272438418190587263600148770280649306958101930"
);
pub const G2_GENERATOR_Y_C0: Fq =
MontFp!("8495653923123431417604973247489272438418190587263600148770280649306958101930");
/// G2_GENERATOR_Y_C1 = /// G2_GENERATOR_Y_C1 =
/// 4082367875863433681332203403145435568316851327593401208105741076214120093531 /// 4082367875863433681332203403145435568316851327593401208105741076214120093531
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(
Fq,
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
);
pub const G2_GENERATOR_Y_C1: Fq =
MontFp!("4082367875863433681332203403145435568316851327593401208105741076214120093531");

+ 7
- 19
bn254/src/curves/mod.rs

@ -2,7 +2,7 @@ use ark_ec::{
bn, bn,
bn::{Bn, BnParameters, TwistType}, bn::{Bn, BnParameters, TwistType},
}; };
use ark_ff::{MontFp, QuadExt};
use ark_ff::MontFp;
use crate::*; use crate::*;
@ -24,25 +24,13 @@ impl BnParameters for Parameters {
-1, 0, 0, 1, 0, 1, 1, -1, 0, 0, 1, 0, 1, 1,
]; ];
const TWIST_MUL_BY_Q_X: Fq2 = QuadExt!(
MontFp!(
Fq,
"21575463638280843010398324269430826099269044274347216827212613867836435027261"
),
MontFp!(
Fq,
"10307601595873709700152284273816112264069230130616436755625194854815875713954"
),
const TWIST_MUL_BY_Q_X: Fq2 = Fq2::new(
MontFp!("21575463638280843010398324269430826099269044274347216827212613867836435027261"),
MontFp!("10307601595873709700152284273816112264069230130616436755625194854815875713954"),
); );
const TWIST_MUL_BY_Q_Y: Fq2 = QuadExt!(
MontFp!(
Fq,
"2821565182194536844548159561693502659359617185244120367078079554186484126554"
),
MontFp!(
Fq,
"3505843767911556378687030309984248845540243509899259641013678093033130930403"
),
const TWIST_MUL_BY_Q_Y: Fq2 = Fq2::new(
MontFp!("2821565182194536844548159561693502659359617185244120367078079554186484126554"),
MontFp!("3505843767911556378687030309984248845540243509899259641013678093033130930403"),
); );
const TWIST_TYPE: TwistType = TwistType::D; const TWIST_TYPE: TwistType = TwistType::D;
type Fp = Fq; type Fp = Fq;

+ 1
- 1
bn254/src/curves/tests.rs

@ -1,5 +1,5 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
}; };
use ark_ec::{AffineCurve, PairingEngine}; use ark_ec::{AffineCurve, PairingEngine};
use ark_ff::{ use ark_ff::{

+ 1
- 4
bn254/src/fields/fq.rs

@ -1,10 +1,7 @@
use ark_ff::fields::{Fp256, MontBackend, MontConfig, MontFp};
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
#[derive(MontConfig)] #[derive(MontConfig)]
#[modulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"] #[modulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"]
#[generator = "3"] #[generator = "3"]
pub struct FqConfig; pub struct FqConfig;
pub type Fq = Fp256<MontBackend<FqConfig, 4>>; pub type Fq = Fp256<MontBackend<FqConfig, 4>>;
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");

+ 25
- 55
bn254/src/fields/fq12.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, CubicExt, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,108 +10,78 @@ pub struct Fq12Config;
impl Fp12Config for Fq12Config { impl Fp12Config for Fq12Config {
type Fp6Config = Fq6Config; type Fp6Config = Fq6Config;
const NONRESIDUE: Fq6 = CubicExt!(FQ2_ZERO, FQ2_ONE, FQ2_ZERO);
const NONRESIDUE: Fq6 = Fq6::new(Fq2::ZERO, Fq2::ONE, Fq2::ZERO);
const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP12_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 6) // Fp2::NONRESIDUE^(((q^0) - 1) / 6)
QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^(((q^1) - 1) / 6) // Fp2::NONRESIDUE^(((q^1) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!("8376118865763821496583973867626364092589906065868298776909617916018768340080"),
MontFp!( MontFp!(
Fq,
"8376118865763821496583973867626364092589906065868298776909617916018768340080"
),
MontFp!(
Fq,
"16469823323077808223889137241176536799009286646108169935659301613961712198316" "16469823323077808223889137241176536799009286646108169935659301613961712198316"
), ),
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 6) // Fp2::NONRESIDUE^(((q^2) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"21888242871839275220042445260109153167277707414472061641714758635765020556617" "21888242871839275220042445260109153167277707414472061641714758635765020556617"
), ),
MontFp!(Fq, "0"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 6) // Fp2::NONRESIDUE^(((q^3) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"11697423496358154304825782922584725312912383441159505038794027105778954184319" "11697423496358154304825782922584725312912383441159505038794027105778954184319"
), ),
MontFp!(
Fq,
"303847389135065887422783454877609941456349188919719272345083954437860409601"
),
MontFp!("303847389135065887422783454877609941456349188919719272345083954437860409601"),
), ),
// Fp2::NONRESIDUE^(((q^4) - 1) / 6) // Fp2::NONRESIDUE^(((q^4) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"21888242871839275220042445260109153167277707414472061641714758635765020556616" "21888242871839275220042445260109153167277707414472061641714758635765020556616"
), ),
MontFp!(Fq, "0"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 6) // Fp2::NONRESIDUE^(((q^5) - 1) / 6)
QuadExt!(
MontFp!(
Fq,
"3321304630594332808241809054958361220322477375291206261884409189760185844239"
),
MontFp!(
Fq,
"5722266937896532885780051958958348231143373700109372999374820235121374419868"
),
Fq2::new(
MontFp!("3321304630594332808241809054958361220322477375291206261884409189760185844239"),
MontFp!("5722266937896532885780051958958348231143373700109372999374820235121374419868"),
), ),
// Fp2::NONRESIDUE^(((q^6) - 1) / 6) // Fp2::NONRESIDUE^(((q^6) - 1) / 6)
QuadExt!(MontFp!(Fq, "-1"), MontFp!(Fq, "0"),),
Fq2::new(MontFp!("-1"), Fq::ZERO),
// Fp2::NONRESIDUE^(((q^7) - 1) / 6) // Fp2::NONRESIDUE^(((q^7) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"13512124006075453725662431877630910996106405091429524885779419978626457868503" "13512124006075453725662431877630910996106405091429524885779419978626457868503"
), ),
MontFp!(
Fq,
"5418419548761466998357268504080738289687024511189653727029736280683514010267"
),
MontFp!("5418419548761466998357268504080738289687024511189653727029736280683514010267"),
), ),
// Fp2::NONRESIDUE^(((q^8) - 1) / 6) // Fp2::NONRESIDUE^(((q^8) - 1) / 6)
QuadExt!(
MontFp!(
Fq,
"2203960485148121921418603742825762020974279258880205651966"
),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("2203960485148121921418603742825762020974279258880205651966"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^9) - 1) / 6) // Fp2::NONRESIDUE^(((q^9) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"10190819375481120917420622822672549775783927716138318623895010788866272024264" "10190819375481120917420622822672549775783927716138318623895010788866272024264"
), ),
MontFp!( MontFp!(
Fq,
"21584395482704209334823622290379665147239961968378104390343953940207365798982" "21584395482704209334823622290379665147239961968378104390343953940207365798982"
), ),
), ),
// Fp2::NONRESIDUE^(((q^10) - 1) / 6) // Fp2::NONRESIDUE^(((q^10) - 1) / 6)
QuadExt!(
MontFp!(
Fq,
"2203960485148121921418603742825762020974279258880205651967"
),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("2203960485148121921418603742825762020974279258880205651967"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^11) - 1) / 6) // Fp2::NONRESIDUE^(((q^11) - 1) / 6)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"18566938241244942414004596690298913868373833782006617400804628704885040364344" "18566938241244942414004596690298913868373833782006617400804628704885040364344"
), ),
MontFp!( MontFp!(
Fq,
"16165975933942742336466353786298926857552937457188450663314217659523851788715" "16165975933942742336466353786298926857552937457188450663314217659523851788715"
), ),
), ),

+ 4
- 7
bn254/src/fields/fq2.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -10,14 +10,14 @@ impl Fp2Config for Fq2Config {
type Fp = Fq; type Fp = Fq;
/// NONRESIDUE = -1 /// NONRESIDUE = -1
const NONRESIDUE: Fq = MontFp!(Fq, "-1");
const NONRESIDUE: Fq = MontFp!("-1");
/// Coefficients for the Frobenius automorphism. /// Coefficients for the Frobenius automorphism.
const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
// NONRESIDUE**(((q^0) - 1) / 2) // NONRESIDUE**(((q^0) - 1) / 2)
MontFp!(Fq, "1"),
Fq::ONE,
// NONRESIDUE**(((q^1) - 1) / 2) // NONRESIDUE**(((q^1) - 1) / 2)
MontFp!(Fq, "-1"),
MontFp!("-1"),
]; ];
#[inline(always)] #[inline(always)]
@ -25,6 +25,3 @@ impl Fp2Config for Fq2Config {
-(*fe) -(*fe)
} }
} }
pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO);
pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO);

+ 27
- 59
bn254/src/fields/fq6.rs

@ -1,4 +1,4 @@
use ark_ff::{fields::*, MontFp, QuadExt};
use ark_ff::{fields::*, MontFp};
use crate::*; use crate::*;
@ -11,113 +11,81 @@ impl Fp6Config for Fq6Config {
type Fp2Config = Fq2Config; type Fp2Config = Fq2Config;
/// NONRESIDUE = U+9 /// NONRESIDUE = U+9
const NONRESIDUE: Fq2 = QuadExt!(MontFp!(Fq, "9"), MontFp!(Fq, "1"));
const NONRESIDUE: Fq2 = Fq2::new(MontFp!("9"), Fq::ONE);
const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
// Fp2::NONRESIDUE^(((q^0) - 1) / 3) // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^(((q^1) - 1) / 3) // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"21575463638280843010398324269430826099269044274347216827212613867836435027261" "21575463638280843010398324269430826099269044274347216827212613867836435027261"
), ),
MontFp!( MontFp!(
Fq,
"10307601595873709700152284273816112264069230130616436755625194854815875713954" "10307601595873709700152284273816112264069230130616436755625194854815875713954"
), ),
), ),
// Fp2::NONRESIDUE^(((q^2) - 1) / 3) // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"21888242871839275220042445260109153167277707414472061641714758635765020556616" "21888242871839275220042445260109153167277707414472061641714758635765020556616"
), ),
MontFp!(Fq, "0"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^3) - 1) / 3) // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
QuadExt!(
MontFp!(
Fq,
"3772000881919853776433695186713858239009073593817195771773381919316419345261"
),
MontFp!(
Fq,
"2236595495967245188281701248203181795121068902605861227855261137820944008926"
),
Fq2::new(
MontFp!("3772000881919853776433695186713858239009073593817195771773381919316419345261"),
MontFp!("2236595495967245188281701248203181795121068902605861227855261137820944008926"),
), ),
// Fp2::NONRESIDUE^(((q^4) - 1) / 3) // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
QuadExt!(
MontFp!(
Fq,
"2203960485148121921418603742825762020974279258880205651966"
),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("2203960485148121921418603742825762020974279258880205651966"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^(((q^5) - 1) / 3) // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"18429021223477853657660792034369865839114504446431234726392080002137598044644" "18429021223477853657660792034369865839114504446431234726392080002137598044644"
), ),
MontFp!(
Fq,
"9344045779998320333812420223237981029506012124075525679208581902008406485703"
),
MontFp!("9344045779998320333812420223237981029506012124075525679208581902008406485703"),
), ),
]; ];
const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[ const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
// Fp2::NONRESIDUE^((2*(q^0) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
Fq2::new(Fq::ONE, Fq::ZERO),
// Fp2::NONRESIDUE^((2*(q^1) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
QuadExt!(
Fq2::new(
MontFp!("2581911344467009335267311115468803099551665605076196740867805258568234346338"),
MontFp!( MontFp!(
Fq,
"2581911344467009335267311115468803099551665605076196740867805258568234346338"
),
MontFp!(
Fq,
"19937756971775647987995932169929341994314640652964949448313374472400716661030" "19937756971775647987995932169929341994314640652964949448313374472400716661030"
), ),
), ),
// Fp2::NONRESIDUE^((2*(q^2) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
QuadExt!(
MontFp!(
Fq,
"2203960485148121921418603742825762020974279258880205651966"
),
MontFp!(Fq, "0"),
Fq2::new(
MontFp!("2203960485148121921418603742825762020974279258880205651966"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^((2*(q^3) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
QuadExt!(
Fq2::new(
MontFp!("5324479202449903542726783395506214481928257762400643279780343368557297135718"),
MontFp!( MontFp!(
Fq,
"5324479202449903542726783395506214481928257762400643279780343368557297135718"
),
MontFp!(
Fq,
"16208900380737693084919495127334387981393726419856888799917914180988844123039" "16208900380737693084919495127334387981393726419856888799917914180988844123039"
), ),
), ),
// Fp2::NONRESIDUE^((2*(q^4) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"21888242871839275220042445260109153167277707414472061641714758635765020556616" "21888242871839275220042445260109153167277707414472061641714758635765020556616"
), ),
MontFp!(Fq, "0"),
Fq::ZERO,
), ),
// Fp2::NONRESIDUE^((2*(q^5) - 2) / 3) // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
QuadExt!(
Fq2::new(
MontFp!( MontFp!(
Fq,
"13981852324922362344252311234282257507216387789820983642040889267519694726527" "13981852324922362344252311234282257507216387789820983642040889267519694726527"
), ),
MontFp!(
Fq,
"7629828391165209371577384193250820201684255241773809077146787135900891633097"
),
MontFp!("7629828391165209371577384193250820201684255241773809077146787135900891633097"),
), ),
]; ];
@ -128,6 +96,6 @@ impl Fp6Config for Fq6Config {
f.double_in_place().double_in_place().double_in_place(); f.double_in_place().double_in_place().double_in_place();
let c0 = f.c0 + fe.c0 + Fq2Config::mul_fp_by_nonresidue(&fe.c1); let c0 = f.c0 + fe.c0 + Fq2Config::mul_fp_by_nonresidue(&fe.c1);
let c1 = f.c1 + fe.c1 + fe.c0; let c1 = f.c1 + fe.c1 + fe.c0;
QuadExt!(c0, c1)
Fq2::new(c0, c1)
} }
} }

+ 1
- 1
bn254/src/fields/tests.rs

@ -3,7 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::{BigInt, BigInteger, BigInteger256}, biginteger::{BigInt, BigInteger, BigInteger256},
fields::{FftField, Field, Fp6Config, PrimeField, SquareRootField},
fields::{FftField, Field, Fp6Config, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};

+ 13
- 14
bw6_761/src/curves/g1.rs

@ -1,18 +1,18 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
models::{short_weierstrass::SWCurveConfig, CurveConfig},
short_weierstrass::{Affine, Projective},
}; };
use ark_ff::MontFp;
use ark_ff::{Field, MontFp};
use crate::{Fq, Fr}; use crate::{Fq, Fr};
pub type G1Affine = GroupAffine<Parameters>;
pub type G1Projective = GroupProjective<Parameters>;
pub type G1Affine = Affine<Parameters>;
pub type G1Projective = Projective<Parameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -30,19 +30,18 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804 /// 91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804
const COFACTOR_INV: Fr = MontFp!(Fr, "91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804");
const COFACTOR_INV: Fr = MontFp!("91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = 0 /// COEFF_A = 0
const COEFF_A: Fq = MontFp!(Fq, "0");
const COEFF_A: Fq = Fq::ZERO;
/// COEFF_B = -1 /// COEFF_B = -1
const COEFF_B: Fq = MontFp!(Fq, "-1");
const COEFF_B: Fq = MontFp!("-1");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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);
#[inline(always)] #[inline(always)]
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
use ark_ff::Zero; use ark_ff::Zero;
@ -52,8 +51,8 @@ impl SWModelParameters for Parameters {
/// G1_GENERATOR_X = /// G1_GENERATOR_X =
/// 6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237 /// 6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237");
pub const G1_GENERATOR_X: Fq = MontFp!("6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
/// 2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099 /// 2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099");
pub const G1_GENERATOR_Y: Fq = MontFp!("2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099");

+ 13
- 14
bw6_761/src/curves/g2.rs

@ -1,18 +1,18 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
models::{short_weierstrass::SWCurveConfig, CurveConfig},
short_weierstrass::{Affine, Projective},
}; };
use ark_ff::MontFp;
use ark_ff::{Field, MontFp};
use crate::{Fq, Fr}; use crate::{Fq, Fr};
pub type G2Affine = GroupAffine<Parameters>;
pub type G2Projective = GroupProjective<Parameters>;
pub type G2Affine = Affine<Parameters>;
pub type G2Projective = Projective<Parameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -30,19 +30,18 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124 /// 214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124
const COFACTOR_INV: Fr = MontFp!(Fr, "214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124");
const COFACTOR_INV: Fr = MontFp!("214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = 0 /// COEFF_A = 0
const COEFF_A: Fq = MontFp!(Fq, "0");
const COEFF_A: Fq = Fq::ZERO;
/// COEFF_B = 4 /// COEFF_B = 4
const COEFF_B: Fq = MontFp!(Fq, "4");
const COEFF_B: Fq = MontFp!("4");
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// 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)] #[inline(always)]
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
@ -53,8 +52,8 @@ impl SWModelParameters for Parameters {
/// G2_GENERATOR_X = /// G2_GENERATOR_X =
/// 6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428 /// 6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428
pub const G2_GENERATOR_X: Fq = MontFp!(Fq, "6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428");
pub const G2_GENERATOR_X: Fq = MontFp!("6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428");
/// G2_GENERATOR_Y = /// G2_GENERATOR_Y =
/// 562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041 /// 562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041
pub const G2_GENERATOR_Y: Fq = MontFp!(Fq, "562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041");
pub const G2_GENERATOR_Y: Fq = MontFp!("562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041");

+ 1
- 1
bw6_761/src/curves/tests.rs

@ -1,5 +1,5 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
}; };
use ark_ec::{AffineCurve, PairingEngine}; use ark_ec::{AffineCurve, PairingEngine};
use ark_ff::{Field, One, PrimeField}; use ark_ff::{Field, One, PrimeField};

+ 1
- 4
bw6_761/src/fields/fq.rs

@ -1,10 +1,7 @@
use ark_ff::fields::{Fp768, MontBackend, MontConfig, MontFp};
use ark_ff::fields::{Fp768, MontBackend, MontConfig};
#[derive(MontConfig)] #[derive(MontConfig)]
#[modulus = "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299"] #[modulus = "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299"]
#[generator = "2"] #[generator = "2"]
pub struct FqConfig; pub struct FqConfig;
pub type Fq = Fp768<MontBackend<FqConfig, 12>>; pub type Fq = Fp768<MontBackend<FqConfig, 12>>;
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");

+ 13
- 16
bw6_761/src/fields/fq3.rs

@ -1,12 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp3::{Fp3, Fp3Config}, fields::fp3::{Fp3, Fp3Config},
CubicExt, MontFp,
Field, MontFp,
}; };
use crate::{
fields::{FQ_ONE, FQ_ZERO},
Fq,
};
use crate::Fq;
pub type Fq3 = Fp3<Fq3Config>; pub type Fq3 = Fp3<Fq3Config>;
@ -17,7 +14,7 @@ impl Fp3Config for Fq3Config {
/// NONRESIDUE = -4 /// NONRESIDUE = -4
// Fq3 = Fq\[u\]/u^3+4 // Fq3 = Fq\[u\]/u^3+4
const NONRESIDUE: Fq = MontFp!(Fq, "-4");
const NONRESIDUE: Fq = MontFp!("-4");
// (MODULUS^3 - 1) % 2^TWO_ADICITY == 0 // (MODULUS^3 - 1) % 2^TWO_ADICITY == 0
const TWO_ADICITY: u32 = 1; const TWO_ADICITY: u32 = 1;
@ -64,24 +61,24 @@ impl Fp3Config for Fq3Config {
]; ];
// NONRESIDUE^T % q // NONRESIDUE^T % q
const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!(
MontFp!(Fq, "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068298"),
FQ_ZERO,
FQ_ZERO,
const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new(
MontFp!("6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068298"),
Fq::ZERO,
Fq::ZERO,
); );
// NQR ^ (MODULUS^i - 1)/3, i=0,1,2 with NQR = u = (0,1,0) // NQR ^ (MODULUS^i - 1)/3, i=0,1,2 with NQR = u = (0,1,0)
const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
FQ_ONE,
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
Fq::ONE,
MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
]; ];
// NQR ^ (2*MODULUS^i - 2)/3, i=0,1,2 with NQR = u = (0,1,0) // NQR ^ (2*MODULUS^i - 2)/3, i=0,1,2 with NQR = u = (0,1,0)
const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
FQ_ONE,
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
Fq::ONE,
MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
]; ];
#[inline(always)] #[inline(always)]

+ 9
- 9
bw6_761/src/fields/fq6.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp6_2over3::{Fp6, Fp6Config}, 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>; pub type Fq6 = Fp6<Fq6Config>;
@ -13,14 +13,14 @@ impl Fp6Config for Fq6Config {
type Fp3Config = Fq3Config; type Fp3Config = Fq3Config;
/// NONRESIDUE = (0, 1, 0) /// NONRESIDUE = (0, 1, 0)
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] = &[ const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
MontFp!(Fq, "1"),
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"),
MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
MontFp!(Fq, "-1"),
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"),
Fq::ONE,
MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775649"),
MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
MontFp!("-1"),
MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
MontFp!("1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292651"),
]; ];
} }

+ 2
- 2
bw6_761/src/fields/tests.rs

@ -1,12 +1,12 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};
use crate::*; use crate::*;
generate_field_test!(bw6_761; fq3; fq6; mont(12, 6); );
generate_field_test!(bw6_761; fq3; fq6_2_on_3; false; mont(12, 6); );
generate_field_serialization_test!(bw6_761;); generate_field_serialization_test!(bw6_761;);

+ 12
- 13
cp6_782/src/curves/g1.rs

@ -1,18 +1,18 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
models::{short_weierstrass::SWCurveConfig, CurveConfig},
short_weierstrass::{Affine, Projective},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
use crate::{Fq, Fr}; use crate::{Fq, Fr};
pub type G1Affine = GroupAffine<Parameters>;
pub type G1Projective = GroupProjective<Parameters>;
pub type G1Affine = Affine<Parameters>;
pub type G1Projective = Projective<Parameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -31,25 +31,24 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788 /// 163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788
const COFACTOR_INV: Fr = MontFp!(Fr, "163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788");
const COFACTOR_INV: Fr = MontFp!("163276846538158998893990986356139314746223949404500031940624325017036397274793417940375498603127780919653358641788");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = 5 /// COEFF_A = 5
const COEFF_A: Fq = MontFp!(Fq, "5");
const COEFF_A: Fq = MontFp!("5");
/// COEFF_B = 17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414 /// COEFF_B = 17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414
const COEFF_B: Fq = MontFp!(Fq, "17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414");
const COEFF_B: Fq = MontFp!("17764315118651679038286329069295091506801468118146712649886336045535808055361274148466772191243305528312843236347777260247138934336850548243151534538734724191505953341403463040067571652261229308333392040104884438208594329793895206056414");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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 = /// G1_GENERATOR_X =
/// 5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646 /// 5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646");
pub const G1_GENERATOR_X: Fq = MontFp!("5511163824921585887915590525772884263960974614921003940645351443740084257508990841338974915037175497689287870585840954231884082785026301437744745393958283053278991955159266640440849940136976927372133743626748847559939620888818486853646");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
/// 7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443 /// 7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443");
pub const G1_GENERATOR_Y: Fq = MontFp!("7913123550914612057135582061699117755797758113868200992327595317370485234417808273674357776714522052694559358668442301647906991623400754234679697332299689255516547752391831738454121261248793568285885897998257357202903170202349380518443");

+ 23
- 24
cp6_782/src/curves/g2.rs

@ -1,18 +1,18 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, SWModelParameters},
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
models::CurveConfig,
short_weierstrass::{Affine, Projective, SWCurveConfig},
}; };
use ark_ff::{CubicExt, MontFp};
use ark_ff::{Field, MontFp};
use crate::{Fq, Fq3, Fr, FQ_ZERO};
use crate::{Fq, Fq3, Fr};
pub type G2Affine = GroupAffine<Parameters>;
pub type G2Projective = GroupProjective<Parameters>;
pub type G2Affine = Affine<Parameters>;
pub type G2Projective = Projective<Parameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq3; type BaseField = Fq3;
type ScalarField = Fr; type ScalarField = Fr;
@ -55,50 +55,49 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598 /// 45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598
const COFACTOR_INV: Fr = MontFp!(Fr, "45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598");
const COFACTOR_INV: Fr = MontFp!("45586359457219724873147353901735745013467692594291916855200979604570630929674383405372210802279573887880950375598");
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = (0, 0, COEFF_A * TWIST^2) = (0, 0, 5) /// COEFF_A = (0, 0, COEFF_A * TWIST^2) = (0, 0, 5)
const COEFF_A: Fq3 = CubicExt!(FQ_ZERO, FQ_ZERO, MontFp!(Fq, "5"),);
const COEFF_A: Fq3 = Fq3::new(Fq::ZERO, Fq::ZERO, MontFp!("5"));
/// COEFF_B = (G1::COEFF_B * TWIST^3, 0, 0) = /// COEFF_B = (G1::COEFF_B * TWIST^3, 0, 0) =
/// (7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612, /// (7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612,
/// 0, 0) /// 0, 0)
const COEFF_B: Fq3 = CubicExt!(
MontFp!(Fq, "7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612"),
FQ_ZERO,
FQ_ZERO,
const COEFF_B: Fq3 = Fq3::new(
MontFp!("7237353553714858194254855835825640240663090882935418626687402315497764195116318527743248304684159666286416318482685337633828994152723793439622384740540789612754127688659139509552568164770448654259255628317166934203899992395064470477612"),
Fq::ZERO,
Fq::ZERO,
); );
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// 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);
} }
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);
/// G2_GENERATOR_X_C0 = /// G2_GENERATOR_X_C0 =
/// 13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338 /// 13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338
pub const G2_GENERATOR_X_C0: Fq = MontFp!(Fq, "13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338");
pub const G2_GENERATOR_X_C0: Fq = MontFp!("13426761183630949215425595811885033211332897733228446437546263564078445562454176776915160094418980045665397361295624472103734543457352048745726512354895954850428989867542989474136256025045975283415690491751906307188562464175510373683338");
/// G2_GENERATOR_X_C1 = /// G2_GENERATOR_X_C1 =
/// 20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610 /// 20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610
pub const G2_GENERATOR_X_C1: Fq = MontFp!(Fq, "20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610");
pub const G2_GENERATOR_X_C1: Fq = MontFp!("20471601555918880743198170952645906008198510944268658573129351735028343217532386920456705632337352161031960990613816401042894531220068552819818037605513359562118363589199569321421558696125646867661360498323171027455638052943806292028610");
/// G2_GENERATOR_X_C2 = /// G2_GENERATOR_X_C2 =
/// 3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980 /// 3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980
pub const G2_GENERATOR_X_C2: Fq = MontFp!(Fq, "3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980");
pub const G2_GENERATOR_X_C2: Fq = MontFp!("3905053196875761830053608605277158152930144841844497593936739534395003062685449846381431331169369910535935138116320442345524758217411779027270883193856999691582831339845600938304719916501940381093815781408183227875600753651697934495980");
/// G2_GENERATOR_Y_C0 = /// G2_GENERATOR_Y_C0 =
/// 8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243 /// 8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243
pub const G2_GENERATOR_Y_C0: Fq = MontFp!(Fq, "8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243");
pub const G2_GENERATOR_Y_C0: Fq = MontFp!("8567517639523571619872938228644013584947463594196306323477160496987712111576624702939472765993995586889532559039169098780892505598589581147768095093536988446010255611523736706017580686335404469207486594272103717837888228343074699140243");
/// G2_GENERATOR_Y_C1 = /// G2_GENERATOR_Y_C1 =
/// 3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752 /// 3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752
pub const G2_GENERATOR_Y_C1: Fq = MontFp!(Fq, "3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752");
pub const G2_GENERATOR_Y_C1: Fq = MontFp!("3890537069205870914984502594450293167889863914413852788876350245583932846980126025043974070704295857226211547108005650399870458089721518559480870503159804530091559886149680718531004778697982910253701559194337987238111062202037698927752");
/// G2_GENERATOR_Y_C2 = /// G2_GENERATOR_Y_C2 =
/// 10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721 /// 10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721
pub const G2_GENERATOR_Y_C2: Fq = MontFp!(Fq, "10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721");
pub const G2_GENERATOR_Y_C2: Fq = MontFp!("10936269922612615564271188303104593362724754284143779051599749016735041389483971486958818324356025479751246744831831158558101688599198721653921723013062333636402617118847009085485166284126970598561393411916461254016145116183331671450721");

+ 6
- 6
cp6_782/src/curves/mod.rs

@ -1,11 +1,11 @@
use ark_ec::{models::SWModelParameters, PairingEngine};
use ark_ec::{models::short_weierstrass::SWCurveConfig, PairingEngine};
use ark_ff::{ use ark_ff::{
biginteger::BigInteger832, biginteger::BigInteger832,
fields::{BitIteratorBE, Field}, fields::{BitIteratorBE, Field},
BigInt, CubicExt, One,
BigInt, One,
}; };
use crate::{Fq, Fq3, Fq6, Fr, FQ_ONE, FQ_ZERO};
use crate::{Fq, Fq3, Fq6, Fr};
pub mod g1; pub mod g1;
pub use self::g1::{G1Affine, G1Projective}; pub use self::g1::{G1Affine, G1Projective};
@ -87,7 +87,7 @@ impl CP6_782 {
let x = py_twist_squared; let x = py_twist_squared;
let y = gamma_old_rx - &old_ry - &gamma_twist_px; let y = gamma_old_rx - &old_ry - &gamma_twist_px;
let ell_rr_at_p = Fq6::new(x, y);
let ell_rr_at_p: Fq6 = Fq6::new(x, y);
rx = gamma.square() - &old_rx.double(); rx = gamma.square() - &old_rx.double();
ry = gamma * &(old_rx - &rx) - &old_ry; ry = gamma * &(old_rx - &rx) - &old_ry;
@ -105,7 +105,7 @@ impl CP6_782 {
let x = py_twist_squared; let x = py_twist_squared;
let y = gamma_qx - &qy - &gamma_twist_px; let y = gamma_qx - &qy - &gamma_twist_px;
let ell_rq_at_p = Fq6::new(x, y);
let ell_rq_at_p: Fq6 = Fq6::new(x, y);
rx = gamma.square() - &old_rx - &qx; rx = gamma.square() - &old_rx - &qx;
ry = gamma * &(old_rx - &rx) - &old_ry; ry = gamma * &(old_rx - &rx) - &old_ry;
@ -153,7 +153,7 @@ impl CP6_782 {
} }
/// TWIST = (0, 1, 0) /// TWIST = (0, 1, 0)
pub const TWIST: Fq3 = CubicExt!(FQ_ZERO, FQ_ONE, FQ_ZERO);
pub const TWIST: Fq3 = Fq3::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
/// ATE_IS_LOOP_COUNT_NEG = false /// ATE_IS_LOOP_COUNT_NEG = false
pub const ATE_IS_LOOP_COUNT_NEG: bool = false; pub const ATE_IS_LOOP_COUNT_NEG: bool = false;

+ 1
- 1
cp6_782/src/curves/tests.rs

@ -1,5 +1,5 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
}; };
use ark_ec::{AffineCurve, PairingEngine}; use ark_ec::{AffineCurve, PairingEngine};
use ark_ff::{Field, One, PrimeField}; use ark_ff::{Field, One, PrimeField};

+ 1
- 4
cp6_782/src/fields/fq.rs

@ -1,10 +1,7 @@
use ark_ff::fields::{Fp832, MontBackend, MontConfig, MontFp};
use ark_ff::fields::{Fp832, MontBackend, MontConfig};
#[derive(MontConfig)] #[derive(MontConfig)]
#[modulus = "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577"] #[modulus = "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577"]
#[generator = "13"] #[generator = "13"]
pub struct FqConfig; pub struct FqConfig;
pub type Fq = Fp832<MontBackend<FqConfig, 13>>; pub type Fq = Fp832<MontBackend<FqConfig, 13>>;
pub const FQ_ONE: Fq = MontFp!(Fq, "1");
pub const FQ_ZERO: Fq = MontFp!(Fq, "0");

+ 13
- 13
cp6_782/src/fields/fq3.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp3::{Fp3, Fp3Config}, fields::fp3::{Fp3, Fp3Config},
CubicExt, Field, MontFp,
Field, MontFp,
}; };
use crate::{fields::FQ_ZERO, Fq};
use crate::Fq;
pub type Fq3 = Fp3<Fq3Config>; pub type Fq3 = Fp3<Fq3Config>;
@ -13,7 +13,7 @@ impl Fp3Config for Fq3Config {
type Fp = Fq; type Fp = Fq;
/// NONRESIDUE = 13 /// NONRESIDUE = 13
const NONRESIDUE: Fq = MontFp!(Fq, "13");
const NONRESIDUE: Fq = MontFp!("13");
const TWO_ADICITY: u32 = 3; const TWO_ADICITY: u32 = 3;
@ -58,22 +58,22 @@ impl Fp3Config for Fq3Config {
0x2b87fda171, 0x2b87fda171,
]; ];
const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!(
MontFp!(Fq, "5759691735434357221228070840130186543101559976323700017469395641639510585333061695996665166662748527158637897523704071820491869715512532675375604262649010727161924084052120196921150869218319839231115277876207074651754402338718419191428"),
FQ_ZERO,
FQ_ZERO,
const QUADRATIC_NONRESIDUE_TO_T: Fq3 = Fq3::new(
MontFp!("5759691735434357221228070840130186543101559976323700017469395641639510585333061695996665166662748527158637897523704071820491869715512532675375604262649010727161924084052120196921150869218319839231115277876207074651754402338718419191428"),
Fq::ZERO,
Fq::ZERO,
); );
const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
MontFp!(Fq, "1"),
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
Fq::ONE,
MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
]; ];
const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[ const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
MontFp!(Fq, "1"),
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
Fq::ONE,
MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
]; ];
#[inline(always)] #[inline(always)]

+ 9
- 9
cp6_782/src/fields/fq6.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp6_2over3::{Fp6, Fp6Config}, 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>; pub type Fq6 = Fp6<Fq6Config>;
@ -13,14 +13,14 @@ impl Fp6Config for Fq6Config {
type Fp3Config = Fq3Config; type Fp3Config = Fq3Config;
/// NONRESIDUE = (0, 1, 0). /// NONRESIDUE = (0, 1, 0).
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] = &[ const FROBENIUS_COEFF_FP6_C1: &'static [Fq] = &[
MontFp!(Fq, "1"),
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"),
MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
MontFp!(Fq, "22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"),
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"),
Fq::ONE,
MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756862"),
MontFp!("2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
MontFp!("22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825576"),
MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
MontFp!("19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068716"),
]; ];
} }

+ 2
- 2
cp6_782/src/fields/tests.rs

@ -1,12 +1,12 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};
use crate::*; use crate::*;
generate_field_test!(cp6_782; fq3; fq6; mont(13, 6); );
generate_field_test!(cp6_782; fq3; fq6_2_on_3; mont(13, 6); );
generate_field_serialization_test!(cp6_782;); generate_field_serialization_test!(cp6_782;);

+ 1
- 1
curve-benches/benches/bls12_377.rs

@ -8,7 +8,7 @@ use ark_bls12_377::{
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{ use ark_ff::{
biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand,
BigInteger, Field, PrimeField, UniformRand,
}; };
mod g1 { mod g1 {

+ 1
- 1
curve-benches/benches/bls12_381.rs

@ -8,7 +8,7 @@ use ark_bls12_381::{
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{ use ark_ff::{
biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand,
BigInteger, Field, PrimeField, UniformRand,
}; };
mod g1 { mod g1 {

+ 1
- 3
curve-benches/benches/bn254.rs

@ -6,9 +6,7 @@ use ark_bn254::{
G2Projective as G2, G2Projective as G2,
}; };
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{
biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
};
use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand};
mod g1 { mod g1 {
use super::*; use super::*;

+ 1
- 1
curve-benches/benches/bw6_761.rs

@ -8,7 +8,7 @@ use ark_bw6_761::{
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{ use ark_ff::{
biginteger::{BigInteger384 as FrRepr, BigInteger768 as FqRepr}, biginteger::{BigInteger384 as FrRepr, BigInteger768 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand,
BigInteger, Field, PrimeField, UniformRand,
}; };
mod g1 { mod g1 {

+ 1
- 1
curve-benches/benches/cp6_782.rs

@ -8,7 +8,7 @@ use ark_cp6_782::{
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{ use ark_ff::{
biginteger::{BigInteger384 as FrRepr, BigInteger832 as FqRepr}, biginteger::{BigInteger384 as FrRepr, BigInteger832 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand,
BigInteger, Field, PrimeField, UniformRand,
}; };
mod g1 { mod g1 {

+ 1
- 3
curve-benches/benches/ed_on_bls12_381.rs

@ -3,9 +3,7 @@ use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_ed_on_bls12_381::{fq::Fq, fr::Fr, EdwardsAffine as GAffine, EdwardsProjective as G}; use ark_ed_on_bls12_381::{fq::Fq, fr::Fr, EdwardsAffine as GAffine, EdwardsProjective as G};
use ark_ff::{
biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
};
use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand};
mod g { mod g {
use super::*; use super::*;

+ 1
- 4
curve-benches/benches/mnt4_298.rs

@ -2,10 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{
biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand,
};
use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand};
use ark_mnt4_298::{ use ark_mnt4_298::{
fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
MNT4_298, MNT4_298,

+ 1
- 4
curve-benches/benches/mnt4_753.rs

@ -2,10 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{
biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand,
};
use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand};
use ark_mnt4_753::{ use ark_mnt4_753::{
fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
MNT4_753, MNT4_753,

+ 1
- 4
curve-benches/benches/mnt6_298.rs

@ -2,10 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{
biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand,
};
use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand};
use ark_mnt6_298::{ use ark_mnt6_298::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
MNT6_298, MNT6_298,

+ 1
- 4
curve-benches/benches/mnt6_753.rs

@ -2,10 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ec::{PairingEngine, ProjectiveCurve};
use ark_ff::{
biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand,
};
use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand};
use ark_mnt6_753::{ use ark_mnt6_753::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
MNT6_753, MNT6_753,

+ 1
- 3
curve-benches/benches/pallas.rs

@ -2,9 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_ff::{
biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
};
use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand};
use ark_pallas::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; use ark_pallas::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G};
mod g { mod g {

+ 1
- 3
curve-benches/benches/vesta.rs

@ -2,9 +2,7 @@ use ark_curve_benches::*;
use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_ff::{
biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
};
use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand};
use ark_vesta::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; use ark_vesta::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G};
mod g { mod g {

+ 2
- 1
curve-benches/src/macros/ec.rs

@ -223,6 +223,7 @@ macro_rules! ec_bench {
} }
fn msm_131072(b: &mut $crate::bencher::Bencher) { fn msm_131072(b: &mut $crate::bencher::Bencher) {
use ark_ec::msm::VariableBaseMSM;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 131072; const SAMPLES: usize = 131072;
@ -234,7 +235,7 @@ macro_rules! ec_bench {
.map(|_| Fr::rand(&mut rng).into_bigint()) .map(|_| Fr::rand(&mut rng).into_bigint())
.collect(); .collect();
b.bench_n(1, |b| { b.bench_n(1, |b| {
b.iter(|| ark_ec::msm::VariableBase::msm(&v, &scalars));
b.iter(|| <$projective as VariableBaseMSM>::msm_bigint(&v, &scalars));
}) })
} }

+ 10
- 14
curve-constraint-tests/src/lib.rs

@ -2,14 +2,14 @@
extern crate ark_relations; extern crate ark_relations;
pub mod fields { pub mod fields {
use ark_ff::{BitIteratorLE, Field, UniformRand};
use ark_ff::{BigInteger, BitIteratorLE, Field, PrimeField, UniformRand};
use ark_r1cs_std::prelude::*; use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
use ark_std::{test_rng, vec::Vec}; use ark_std::{test_rng, vec::Vec};
pub fn field_test<F, ConstraintF, AF>() -> Result<(), SynthesisError> pub fn field_test<F, ConstraintF, AF>() -> Result<(), SynthesisError>
where where
F: Field,
F: PrimeField,
ConstraintF: Field, ConstraintF: Field,
AF: FieldVar<F, ConstraintF>, AF: FieldVar<F, ConstraintF>,
AF: TwoBitLookupGadget<ConstraintF, TableConstant = F>, AF: TwoBitLookupGadget<ConstraintF, TableConstant = F>,
@ -176,10 +176,10 @@ pub mod fields {
assert!(cs.is_satisfied().unwrap()); assert!(cs.is_satisfied().unwrap());
let bytes = r.to_non_unique_bytes()?; let bytes = r.to_non_unique_bytes()?;
assert_eq!(ark_ff::to_bytes!(r_native).unwrap(), bytes.value().unwrap());
assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap());
assert!(cs.is_satisfied().unwrap()); assert!(cs.is_satisfied().unwrap());
let bytes = r.to_bytes()?; let bytes = r.to_bytes()?;
assert_eq!(ark_ff::to_bytes!(r_native).unwrap(), bytes.value().unwrap());
assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap());
assert!(cs.is_satisfied().unwrap()); assert!(cs.is_satisfied().unwrap());
let ab_false = &a + (AF::from(Boolean::Constant(false)) * b_native); let ab_false = &a + (AF::from(Boolean::Constant(false)) * b_native);
@ -231,8 +231,8 @@ pub mod fields {
pub mod curves { pub mod curves {
use ark_ec::{ use ark_ec::{
short_weierstrass_jacobian::GroupProjective as SWProjective,
twisted_edwards_extended::GroupProjective as TEProjective, ProjectiveCurve,
short_weierstrass::Projective as SWProjective, twisted_edwards::Projective as TEProjective,
ProjectiveCurve,
}; };
use ark_ff::{BitIteratorLE, Field, One, PrimeField}; use ark_ff::{BitIteratorLE, Field, One, PrimeField};
use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
@ -380,7 +380,7 @@ pub mod curves {
pub fn sw_test<P, GG>() -> Result<(), SynthesisError> pub fn sw_test<P, GG>() -> Result<(), SynthesisError>
where where
P: ark_ec::SWModelParameters,
P: ark_ec::models::short_weierstrass::SWCurveConfig,
GG: CurveVar<SWProjective<P>, <P::BaseField as Field>::BasePrimeField>, GG: CurveVar<SWProjective<P>, <P::BaseField as Field>::BasePrimeField>,
for<'a> &'a GG: GroupOpsBounds<'a, SWProjective<P>, GG>, for<'a> &'a GG: GroupOpsBounds<'a, SWProjective<P>, GG>,
{ {
@ -391,8 +391,6 @@ pub mod curves {
AllocationMode::Constant, AllocationMode::Constant,
]; ];
for &mode in &modes { for &mode in &modes {
use ark_ec::group::Group;
let mut rng = test_rng(); let mut rng = test_rng();
let cs = ConstraintSystem::<<P::BaseField as Field>::BasePrimeField>::new_ref(); let cs = ConstraintSystem::<<P::BaseField as Field>::BasePrimeField>::new_ref();
@ -428,7 +426,7 @@ pub mod curves {
gadget_a_zero.enforce_equal(&gadget_a)?; gadget_a_zero.enforce_equal(&gadget_a)?;
// Check doubling // Check doubling
let aa = Group::double(&a);
let aa = &a.double();
let aa_affine = aa.into_affine(); let aa_affine = aa.into_affine();
gadget_a.double_in_place()?; gadget_a.double_in_place()?;
let aa_val = gadget_a.value()?.into_affine(); let aa_val = gadget_a.value()?.into_affine();
@ -453,7 +451,7 @@ pub mod curves {
pub fn te_test<P, GG>() -> Result<(), SynthesisError> pub fn te_test<P, GG>() -> Result<(), SynthesisError>
where where
P: ark_ec::TEModelParameters,
P: ark_ec::twisted_edwards::TECurveConfig,
GG: CurveVar<TEProjective<P>, <P::BaseField as Field>::BasePrimeField>, GG: CurveVar<TEProjective<P>, <P::BaseField as Field>::BasePrimeField>,
for<'a> &'a GG: GroupOpsBounds<'a, TEProjective<P>, GG>, for<'a> &'a GG: GroupOpsBounds<'a, TEProjective<P>, GG>,
{ {
@ -464,8 +462,6 @@ pub mod curves {
AllocationMode::Constant, AllocationMode::Constant,
]; ];
for &mode in &modes { for &mode in &modes {
use ark_ec::group::Group;
let mut rng = test_rng(); let mut rng = test_rng();
let cs = ConstraintSystem::<<P::BaseField as Field>::BasePrimeField>::new_ref(); let cs = ConstraintSystem::<<P::BaseField as Field>::BasePrimeField>::new_ref();
@ -498,7 +494,7 @@ pub mod curves {
assert!(cs.is_satisfied().unwrap()); assert!(cs.is_satisfied().unwrap());
// Check doubling // Check doubling
let aa = Group::double(&a);
let aa = &a.double();
let aa_affine = aa.into_affine(); let aa_affine = aa.into_affine();
gadget_a.double_in_place()?; gadget_a.double_in_place()?;
let aa_val = gadget_a.value()?.into_affine(); let aa_val = gadget_a.value()?.into_affine();

+ 1
- 1
ed_on_bls12_377/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_bls12_377`. //! This module implements the R1CS equivalent of `ark_ed_on_bls12_377`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 22
- 32
ed_on_bls12_377/src/curves/mod.rs

@ -1,6 +1,6 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine, GroupProjective},
models::CurveConfig,
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
pub type EdwardsAffine = Affine<EdwardsParameters>;
pub type EdwardsProjective = Projective<EdwardsParameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct EdwardsParameters; pub struct EdwardsParameters;
impl ModelParameters for EdwardsParameters {
impl CurveConfig for EdwardsParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -24,23 +24,21 @@ impl ModelParameters for EdwardsParameters {
/// COFACTOR_INV = /// COFACTOR_INV =
/// 527778859339273151515551558673846658209717731602102048798421311598680340096 /// 527778859339273151515551558673846658209717731602102048798421311598680340096
const COFACTOR_INV: Fr = MontFp!(
Fr,
"527778859339273151515551558673846658209717731602102048798421311598680340096"
);
const COFACTOR_INV: Fr =
MontFp!("527778859339273151515551558673846658209717731602102048798421311598680340096");
} }
impl TEModelParameters for EdwardsParameters {
impl TECurveConfig for EdwardsParameters {
/// COEFF_A = -1 /// COEFF_A = -1
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = 3021 /// COEFF_D = 3021
const COEFF_D: Fq = MontFp!(Fq, "3021");
const COEFF_D: Fq = MontFp!("3021");
/// Generated randomly /// Generated randomly
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = EdwardsParameters;
type MontCurveConfig = EdwardsParameters;
/// Multiplication by `a` is just negation. /// Multiplication by `a` is just negation.
/// Is `a` 1 or -1? /// Is `a` 1 or -1?
@ -50,34 +48,26 @@ impl TEModelParameters for EdwardsParameters {
} }
} }
impl MontgomeryModelParameters for EdwardsParameters {
impl MontCurveConfig for EdwardsParameters {
/// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552 /// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
/// = 3990301581132929505568273333084066329187552697088022219156688740916631500114 /// = 3990301581132929505568273333084066329187552697088022219156688740916631500114
const COEFF_A: Fq = MontFp!(
Fq,
"3990301581132929505568273333084066329187552697088022219156688740916631500114"
);
const COEFF_A: Fq =
MontFp!("3990301581132929505568273333084066329187552697088022219156688740916631500114");
/// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD /// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
/// = 4454160168295440918680551605697480202188346638066041608778544715000777738925 /// = 4454160168295440918680551605697480202188346638066041608778544715000777738925
const COEFF_B: Fq = MontFp!(
Fq,
"4454160168295440918680551605697480202188346638066041608778544715000777738925"
);
const COEFF_B: Fq =
MontFp!("4454160168295440918680551605697480202188346638066041608778544715000777738925");
type TEModelParameters = EdwardsParameters;
type TECurveConfig = EdwardsParameters;
} }
/// GENERATOR_X = /// GENERATOR_X =
/// 4497879464030519973909970603271755437257548612157028181994697785683032656389, /// 4497879464030519973909970603271755437257548612157028181994697785683032656389,
const GENERATOR_X: Fq = MontFp!(
Fq,
"4497879464030519973909970603271755437257548612157028181994697785683032656389"
);
const GENERATOR_X: Fq =
MontFp!("4497879464030519973909970603271755437257548612157028181994697785683032656389");
/// GENERATOR_Y = /// GENERATOR_Y =
/// 4357141146396347889246900916607623952598927460421559113092863576544024487809 /// 4357141146396347889246900916607623952598927460421559113092863576544024487809
const GENERATOR_Y: Fq = MontFp!(
Fq,
"4357141146396347889246900916607623952598927460421559113092863576544024487809"
);
const GENERATOR_Y: Fq =
MontFp!("4357141146396347889246900916607623952598927460421559113092863576544024487809");

+ 2
- 39
ed_on_bls12_377/src/curves/tests.rs

@ -1,6 +1,5 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_std::{rand::Rng, test_rng};
use ark_algebra_test_templates::curves::*;
use ark_ec::AffineCurve;
use crate::*; use crate::*;
@ -11,26 +10,6 @@ fn test_projective_curve() {
edwards_tests::<EdwardsParameters>(); edwards_tests::<EdwardsParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = EdwardsAffine::prime_subgroup_generator(); let generator = EdwardsAffine::prime_subgroup_generator();
@ -38,22 +17,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<EdwardsParameters>(); montgomery_conversion_test::<EdwardsParameters>();

+ 1
- 1
ed_on_bls12_377/src/fields/tests.rs

@ -2,7 +2,7 @@ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, fields::*, generate_field_serialization_test, generate_field_test,
}; };
use ark_ff::{ use ark_ff::{
fields::{Field, PrimeField, SquareRootField},
fields::{Field, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};

+ 1
- 1
ed_on_bls12_381/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_bls12_381`. //! This module implements the R1CS equivalent of `ark_ed_on_bls12_381`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 34
- 54
ed_on_bls12_381/src/curves/mod.rs

@ -1,10 +1,7 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
short_weierstrass_jacobian::{
GroupAffine as SWGroupAffine, GroupProjective as SWGroupProjective,
},
twisted_edwards_extended::{GroupAffine, GroupProjective},
SWModelParameters,
models::CurveConfig,
short_weierstrass::{self, SWCurveConfig},
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
@ -13,10 +10,10 @@ use crate::{Fq, Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<JubjubParameters>;
pub type EdwardsProjective = GroupProjective<JubjubParameters>;
pub type SWAffine = SWGroupAffine<JubjubParameters>;
pub type SWProjective = SWGroupProjective<JubjubParameters>;
pub type EdwardsAffine = Affine<JubjubParameters>;
pub type EdwardsProjective = Projective<JubjubParameters>;
pub type SWAffine = short_weierstrass::Affine<JubjubParameters>;
pub type SWProjective = short_weierstrass::Projective<JubjubParameters>;
/// `JubJub` is a twisted Edwards curve. These curves have equations of the /// `JubJub` is a twisted Edwards curve. These curves have equations of the
/// form: ax² + y² = 1 - dx²y². /// form: ax² + y² = 1 - dx²y².
@ -56,7 +53,7 @@ pub struct JubjubParameters;
pub type EdwardsParameters = JubjubParameters; pub type EdwardsParameters = JubjubParameters;
pub type SWParameters = JubjubParameters; pub type SWParameters = JubjubParameters;
impl ModelParameters for JubjubParameters {
impl CurveConfig for JubjubParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -65,26 +62,22 @@ impl ModelParameters for JubjubParameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 819310549611346726241370945440405716213240158234039660170669895299022906775 /// 819310549611346726241370945440405716213240158234039660170669895299022906775
const COFACTOR_INV: Fr = MontFp!(
Fr,
"819310549611346726241370945440405716213240158234039660170669895299022906775"
);
const COFACTOR_INV: Fr =
MontFp!("819310549611346726241370945440405716213240158234039660170669895299022906775");
} }
impl TEModelParameters for JubjubParameters {
impl TECurveConfig for JubjubParameters {
/// COEFF_A = -1 /// COEFF_A = -1
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = (10240/10241) mod q /// COEFF_D = (10240/10241) mod q
const COEFF_D: Fq = MontFp!(
Fq,
"19257038036680949359750312669786877991949435402254120286184196891950884077233"
);
const COEFF_D: Fq =
MontFp!("19257038036680949359750312669786877991949435402254120286184196891950884077233");
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = JubjubParameters;
type MontCurveConfig = JubjubParameters;
/// Multiplication by `a` is simply negation here. /// Multiplication by `a` is simply negation here.
#[inline(always)] #[inline(always)]
@ -93,52 +86,39 @@ impl TEModelParameters for JubjubParameters {
} }
} }
impl MontgomeryModelParameters for JubjubParameters {
impl MontCurveConfig for JubjubParameters {
/// COEFF_A = 40962 /// COEFF_A = 40962
const COEFF_A: Fq = MontFp!(Fq, "40962");
const COEFF_A: Fq = MontFp!("40962");
/// COEFF_B = -40964 /// COEFF_B = -40964
const COEFF_B: Fq = MontFp!(Fq, "-40964");
const COEFF_B: Fq = MontFp!("-40964");
type TEModelParameters = JubjubParameters;
type TECurveConfig = JubjubParameters;
} }
const GENERATOR_X: Fq = MontFp!(
Fq,
"8076246640662884909881801758704306714034609987455869804520522091855516602923"
);
const GENERATOR_X: Fq =
MontFp!("8076246640662884909881801758704306714034609987455869804520522091855516602923");
const GENERATOR_Y: Fq = MontFp!(
Fq,
"13262374693698910701929044844600465831413122818447359594527400194675274060458"
);
const GENERATOR_Y: Fq =
MontFp!("13262374693698910701929044844600465831413122818447359594527400194675274060458");
impl SWModelParameters for JubjubParameters {
impl SWCurveConfig for JubjubParameters {
/// COEFF_A = 52296097456646850916096512823759002727550416093741407922227928430486925478210 /// COEFF_A = 52296097456646850916096512823759002727550416093741407922227928430486925478210
const COEFF_A: Self::BaseField = MontFp!(
Fq,
"52296097456646850916096512823759002727550416093741407922227928430486925478210"
);
const COEFF_A: Self::BaseField =
MontFp!("52296097456646850916096512823759002727550416093741407922227928430486925478210");
/// COEFF_B = 48351165704696163914533707656614864561753505123260775585269522553028192119009 /// COEFF_B = 48351165704696163914533707656614864561753505123260775585269522553028192119009
const COEFF_B: Self::BaseField = MontFp!(
Fq,
"48351165704696163914533707656614864561753505123260775585269522553028192119009"
);
const COEFF_B: Self::BaseField =
MontFp!("48351165704696163914533707656614864561753505123260775585269522553028192119009");
/// generators /// generators
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
(SW_GENERATOR_X, SW_GENERATOR_Y);
const GENERATOR: SWAffine = SWAffine::new_unchecked(SW_GENERATOR_X, SW_GENERATOR_Y);
} }
/// x coordinate for SW curve generator /// x coordinate for SW curve generator
const SW_GENERATOR_X: Fq = MontFp!(
Fq,
"33835869156188682335217394949746694649676633840125476177319971163079011318731"
);
const SW_GENERATOR_X: Fq =
MontFp!("33835869156188682335217394949746694649676633840125476177319971163079011318731");
/// y coordinate for SW curve generator /// y coordinate for SW curve generator
const SW_GENERATOR_Y: Fq = MontFp!(
Fq,
"43777270878440091394432848052353307184915192688165709016756678962558652055320"
);
const SW_GENERATOR_Y: Fq =
MontFp!("43777270878440091394432848052353307184915192688165709016756678962558652055320");

+ 3
- 57
ed_on_bls12_381/src/curves/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_algebra_test_templates::curves::*;
use ark_ec::{AffineCurve, ProjectiveCurve}; use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_ff::{bytes::FromBytes, Zero};
use ark_std::{rand::Rng, str::FromStr, test_rng};
use ark_ff::Zero;
use ark_std::str::FromStr;
use crate::*; use crate::*;
@ -14,31 +14,6 @@ fn test_projective_curve() {
sw_tests::<JubjubParameters>(); sw_tests::<JubjubParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
let c = rng.gen();
let d = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
group_test::<SWProjective>(c, d);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
// edward curve // edward curve
@ -52,22 +27,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_scalar_multiplication() { fn test_scalar_multiplication() {
let f1 = Fr::from_str( let f1 = Fr::from_str(
@ -98,19 +57,6 @@ fn test_scalar_multiplication() {
assert_eq!(f1g.mul(f2).into_affine(), f1f2g); assert_eq!(f1g.mul(f2).into_affine(), f1f2g);
} }
#[test]
fn test_bytes() {
let g_from_repr = EdwardsAffine::from_str(
"(1158870117176967269192899343636553522971009777237254192973081388797299308391, \
36933624999642413792569726058244472742169727126562409632889593958355839948294)",
)
.unwrap();
let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap();
let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap();
assert_eq!(g_from_repr, g);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<JubjubParameters>(); montgomery_conversion_test::<JubjubParameters>();

+ 1
- 34
ed_on_bls12_381/src/fields/tests.rs

@ -3,8 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::BigInteger256 as BigInteger, biginteger::BigInteger256 as BigInteger,
bytes::{FromBytes, ToBytes},
fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField},
fields::{Field, LegendreSymbol::*, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
@ -298,22 +297,6 @@ fn test_fq_legendre() {
assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); assert_eq!(QuadraticNonResidue, Fq::from(e).legendre());
} }
#[test]
fn test_fq_bytes() {
let f1_from_repr = Fq::from(BigInteger::new([
0xab8a2535947d1a77,
0x9ba74cbfda0bbcda,
0xe928b59724d60baf,
0x1cccaaeb9bb1680a,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fq::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_add() { fn test_fr_add() {
let f1 = Fr::from(BigInteger::new([ let f1 = Fr::from(BigInteger::new([
@ -360,22 +343,6 @@ fn test_fr_mul() {
assert_eq!(f1 * &f2, f3); assert_eq!(f1 * &f2, f3);
} }
#[test]
fn test_fr_bytes() {
let f1_from_repr = Fr::from(BigInteger::new([
0xc81265fb4130fe0c,
0xb308836c14e22279,
0x699e887f96bff372,
0x84ecc7e76c11ad,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fr::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_from_str() { fn test_fr_from_str() {
let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0])); let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0]));

+ 1
- 1
ed_on_bls12_381_bandersnatch/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_bandersnatch`. //! This module implements the R1CS equivalent of `ark_bandersnatch`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 36
- 61
ed_on_bls12_381_bandersnatch/src/curves/mod.rs

@ -1,10 +1,7 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
short_weierstrass_jacobian::{
GroupAffine as SWGroupAffine, GroupProjective as SWGroupProjective,
},
twisted_edwards_extended::{GroupAffine, GroupProjective},
SWModelParameters,
models::CurveConfig,
short_weierstrass::{self, SWCurveConfig},
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::{Field, MontFp}; use ark_ff::{Field, MontFp};
@ -13,11 +10,11 @@ use crate::{Fq, Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<BandersnatchParameters>;
pub type EdwardsProjective = GroupProjective<BandersnatchParameters>;
pub type EdwardsAffine = Affine<BandersnatchParameters>;
pub type EdwardsProjective = Projective<BandersnatchParameters>;
pub type SWAffine = SWGroupAffine<BandersnatchParameters>;
pub type SWProjective = SWGroupProjective<BandersnatchParameters>;
pub type SWAffine = short_weierstrass::Affine<BandersnatchParameters>;
pub type SWProjective = short_weierstrass::Projective<BandersnatchParameters>;
/// `bandersnatch` is a twisted Edwards curve. These curves have equations of /// `bandersnatch` is a twisted Edwards curve. These curves have equations of
/// the form: ax² + y² = 1 - dx²y². /// the form: ax² + y² = 1 - dx²y².
@ -57,7 +54,7 @@ pub struct BandersnatchParameters;
pub type EdwardsParameters = BandersnatchParameters; pub type EdwardsParameters = BandersnatchParameters;
pub type SWParameters = BandersnatchParameters; pub type SWParameters = BandersnatchParameters;
impl ModelParameters for BandersnatchParameters {
impl CurveConfig for BandersnatchParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -66,28 +63,23 @@ impl ModelParameters for BandersnatchParameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 9831726595336160714896451345284868594481866920080427688839802480047265754601 /// 9831726595336160714896451345284868594481866920080427688839802480047265754601
const COFACTOR_INV: Fr = MontFp!(
Fr,
"9831726595336160714896451345284868594481866920080427688839802480047265754601"
);
const COFACTOR_INV: Fr =
MontFp!("9831726595336160714896451345284868594481866920080427688839802480047265754601");
} }
impl TEModelParameters for BandersnatchParameters {
impl TECurveConfig for BandersnatchParameters {
/// COEFF_A = -5 /// COEFF_A = -5
const COEFF_A: Fq = MontFp!(Fq, "-5");
const COEFF_A: Fq = MontFp!("-5");
/// COEFF_D = (138827208126141220649022263972958607803/ /// COEFF_D = (138827208126141220649022263972958607803/
/// 171449701953573178309673572579671231137) mod q /// 171449701953573178309673572579671231137) mod q
const COEFF_D: Fq = MontFp!(
Fq,
"45022363124591815672509500913686876175488063829319466900776701791074614335719"
);
const COEFF_D: Fq =
MontFp!("45022363124591815672509500913686876175488063829319466900776701791074614335719");
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
(TE_GENERATOR_X, TE_GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(TE_GENERATOR_X, TE_GENERATOR_Y);
type MontgomeryModelParameters = BandersnatchParameters;
type MontCurveConfig = BandersnatchParameters;
/// Multiplication by `a` is multiply by `-5`. /// Multiplication by `a` is multiply by `-5`.
#[inline(always)] #[inline(always)]
@ -97,20 +89,16 @@ impl TEModelParameters for BandersnatchParameters {
} }
} }
impl MontgomeryModelParameters for BandersnatchParameters {
impl MontCurveConfig for BandersnatchParameters {
/// COEFF_A = 29978822694968839326280996386011761570173833766074948509196803838190355340952 /// COEFF_A = 29978822694968839326280996386011761570173833766074948509196803838190355340952
const COEFF_A: Fq = MontFp!(
Fq,
"29978822694968839326280996386011761570173833766074948509196803838190355340952"
);
const COEFF_A: Fq =
MontFp!("29978822694968839326280996386011761570173833766074948509196803838190355340952");
/// COEFF_B = 25465760566081946422412445027709227188579564747101592991722834452325077642517 /// COEFF_B = 25465760566081946422412445027709227188579564747101592991722834452325077642517
const COEFF_B: Fq = MontFp!(
Fq,
"25465760566081946422412445027709227188579564747101592991722834452325077642517"
);
const COEFF_B: Fq =
MontFp!("25465760566081946422412445027709227188579564747101592991722834452325077642517");
type TEModelParameters = BandersnatchParameters;
type TECurveConfig = BandersnatchParameters;
} }
// The TE form generator is generated following Zcash's fashion: // The TE form generator is generated following Zcash's fashion:
@ -123,43 +111,30 @@ impl MontgomeryModelParameters for BandersnatchParameters {
// <https://github.com/zhenfeizhang/bandersnatch/blob/main/bandersnatch/script/bandersnatch.sage> // <https://github.com/zhenfeizhang/bandersnatch/blob/main/bandersnatch/script/bandersnatch.sage>
/// x coordinate for TE curve generator /// x coordinate for TE curve generator
const TE_GENERATOR_X: Fq = MontFp!(
Fq,
"18886178867200960497001835917649091219057080094937609519140440539760939937304"
);
const TE_GENERATOR_X: Fq =
MontFp!("18886178867200960497001835917649091219057080094937609519140440539760939937304");
/// y coordinate for TE curve generator /// y coordinate for TE curve generator
const TE_GENERATOR_Y: Fq = MontFp!(
Fq,
"19188667384257783945677642223292697773471335439753913231509108946878080696678"
);
const TE_GENERATOR_Y: Fq =
MontFp!("19188667384257783945677642223292697773471335439753913231509108946878080696678");
/// x coordinate for SW curve generator /// x coordinate for SW curve generator
const SW_GENERATOR_X: Fq = MontFp!(
Fq,
"30900340493481298850216505686589334086208278925799850409469406976849338430199"
);
const SW_GENERATOR_X: Fq =
MontFp!("30900340493481298850216505686589334086208278925799850409469406976849338430199");
/// y coordinate for SW curve generator /// y coordinate for SW curve generator
const SW_GENERATOR_Y: Fq = MontFp!(
Fq,
"12663882780877899054958035777720958383845500985908634476792678820121468453298"
);
const SW_GENERATOR_Y: Fq =
MontFp!("12663882780877899054958035777720958383845500985908634476792678820121468453298");
impl SWModelParameters for BandersnatchParameters {
impl SWCurveConfig for BandersnatchParameters {
/// COEFF_A = 10773120815616481058602537765553212789256758185246796157495669123169359657269 /// COEFF_A = 10773120815616481058602537765553212789256758185246796157495669123169359657269
const COEFF_A: Self::BaseField = MontFp!(
Fq,
"10773120815616481058602537765553212789256758185246796157495669123169359657269"
);
const COEFF_A: Self::BaseField =
MontFp!("10773120815616481058602537765553212789256758185246796157495669123169359657269");
/// COEFF_B = 29569587568322301171008055308580903175558631321415017492731745847794083609535 /// COEFF_B = 29569587568322301171008055308580903175558631321415017492731745847794083609535
const COEFF_B: Self::BaseField = MontFp!(
Fq,
"29569587568322301171008055308580903175558631321415017492731745847794083609535"
);
const COEFF_B: Self::BaseField =
MontFp!("29569587568322301171008055308580903175558631321415017492731745847794083609535");
/// generators /// generators
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
(SW_GENERATOR_X, SW_GENERATOR_Y);
const GENERATOR: SWAffine = SWAffine::new_unchecked(SW_GENERATOR_X, SW_GENERATOR_Y);
} }

+ 3
- 66
ed_on_bls12_381_bandersnatch/src/curves/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_algebra_test_templates::curves::*;
use ark_ec::{AffineCurve, ProjectiveCurve}; use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_ff::{bytes::FromBytes, Zero};
use ark_std::{rand::Rng, str::FromStr, test_rng};
use ark_ff::Zero;
use ark_std::str::FromStr;
use crate::*; use crate::*;
@ -14,31 +14,6 @@ fn test_projective_curve() {
sw_tests::<BandersnatchParameters>(); sw_tests::<BandersnatchParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
let c = rng.gen();
let d = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
group_test::<SWProjective>(c, d);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
// edward curve // edward curve
@ -52,31 +27,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
// edward curve
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
// weierstrass curve
let mut rng = test_rng();
let a: SWProjective = rng.gen();
let b: SWProjective = rng.gen();
let a_b = { (a + &b).double().double() };
let a_b2 = (a + &b).double().double();
assert_eq!(a_b.into_affine(), a_b2.into_affine());
}
#[test] #[test]
fn test_scalar_multiplication() { fn test_scalar_multiplication() {
let f1 = Fr::from_str( let f1 = Fr::from_str(
@ -107,19 +57,6 @@ fn test_scalar_multiplication() {
assert_eq!(f1g.mul(f2).into_affine(), f1f2g); assert_eq!(f1g.mul(f2).into_affine(), f1f2g);
} }
#[test]
fn test_bytes() {
let g_from_repr = EdwardsAffine::from_str(
"(29627151942733444043031429156003786749302466371339015363120350521834195802525, \
27488387519748396681411951718153463804682561779047093991696427532072116857978)",
)
.unwrap();
let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap();
let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap();
assert_eq!(g_from_repr, g);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<BandersnatchParameters>(); montgomery_conversion_test::<BandersnatchParameters>();

+ 1
- 34
ed_on_bls12_381_bandersnatch/src/fields/tests.rs

@ -3,8 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::BigInteger256 as BigInteger, biginteger::BigInteger256 as BigInteger,
bytes::{FromBytes, ToBytes},
fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField},
fields::{Field, LegendreSymbol::*, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
@ -298,22 +297,6 @@ fn test_fq_legendre() {
assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); assert_eq!(QuadraticNonResidue, Fq::from(e).legendre());
} }
#[test]
fn test_fq_bytes() {
let f1_from_repr = Fq::from(BigInteger::new([
0xab8a2535947d1a77,
0x9ba74cbfda0bbcda,
0xe928b59724d60baf,
0x1cccaaeb9bb1680a,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fq::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_add() { fn test_fr_add() {
let f1 = Fr::from(BigInteger::new([ let f1 = Fr::from(BigInteger::new([
@ -360,22 +343,6 @@ fn test_fr_mul() {
assert_eq!(f1 * &f2, f3); assert_eq!(f1 * &f2, f3);
} }
#[test]
fn test_fr_bytes() {
let f1_from_repr = Fr::from(BigInteger::new([
0xc81265fb4130fe0c,
0xb308836c14e22279,
0x699e887f96bff372,
0x84ecc7e76c11ad,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fr::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_from_str() { fn test_fr_from_str() {
let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0])); let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0]));

+ 1
- 1
ed_on_bn254/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_bn254`. //! This module implements the R1CS equivalent of `ark_ed_on_bn254`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 22
- 30
ed_on_bn254/src/curves/mod.rs

@ -1,16 +1,16 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine, GroupProjective},
models::CurveConfig,
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp;
use ark_ff::{Field, MontFp};
use crate::{Fq, Fr}; use crate::{Fq, Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
pub type EdwardsAffine = Affine<EdwardsParameters>;
pub type EdwardsProjective = Projective<EdwardsParameters>;
/// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the /// `Baby-JubJub` is a twisted Edwards curve. These curves have equations of the
/// form: ax² + y² = 1 + dx²y². /// form: ax² + y² = 1 + dx²y².
@ -22,7 +22,7 @@ pub type EdwardsProjective = GroupProjective;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct EdwardsParameters; pub struct EdwardsParameters;
impl ModelParameters for EdwardsParameters {
impl CurveConfig for EdwardsParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -31,15 +31,13 @@ impl ModelParameters for EdwardsParameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 2394026564107420727433200628387514462817212225638746351800188703329891451411 /// 2394026564107420727433200628387514462817212225638746351800188703329891451411
const COFACTOR_INV: Fr = MontFp!(
Fr,
"2394026564107420727433200628387514462817212225638746351800188703329891451411"
);
const COFACTOR_INV: Fr =
MontFp!("2394026564107420727433200628387514462817212225638746351800188703329891451411");
} }
impl TEModelParameters for EdwardsParameters {
impl TECurveConfig for EdwardsParameters {
/// COEFF_A = 1 /// COEFF_A = 1
const COEFF_A: Fq = MontFp!(Fq, "1");
const COEFF_A: Fq = Fq::ONE;
#[inline(always)] #[inline(always)]
fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
@ -48,32 +46,26 @@ impl TEModelParameters for EdwardsParameters {
/// COEFF_D = 168696/168700 mod q /// COEFF_D = 168696/168700 mod q
/// = 9706598848417545097372247223557719406784115219466060233080913168975159366771 /// = 9706598848417545097372247223557719406784115219466060233080913168975159366771
const COEFF_D: Fq = MontFp!(
Fq,
"9706598848417545097372247223557719406784115219466060233080913168975159366771"
);
const COEFF_D: Fq =
MontFp!("9706598848417545097372247223557719406784115219466060233080913168975159366771");
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = EdwardsParameters;
type MontCurveConfig = EdwardsParameters;
} }
impl MontgomeryModelParameters for EdwardsParameters {
impl MontCurveConfig for EdwardsParameters {
/// COEFF_A = 168698 /// COEFF_A = 168698
const COEFF_A: Fq = MontFp!(Fq, "168698");
const COEFF_A: Fq = MontFp!("168698");
/// COEFF_B = 168700 /// COEFF_B = 168700
const COEFF_B: Fq = MontFp!(Fq, "168700");
const COEFF_B: Fq = MontFp!("168700");
type TEModelParameters = EdwardsParameters;
type TECurveConfig = EdwardsParameters;
} }
const GENERATOR_X: Fq = MontFp!(
Fq,
"19698561148652590122159747500897617769866003486955115824547446575314762165298"
);
const GENERATOR_X: Fq =
MontFp!("19698561148652590122159747500897617769866003486955115824547446575314762165298");
const GENERATOR_Y: Fq = MontFp!(
Fq,
"19298250018296453272277890825869354524455968081175474282777126169995084727839"
);
const GENERATOR_Y: Fq =
MontFp!("19298250018296453272277890825869354524455968081175474282777126169995084727839");

+ 3
- 52
ed_on_bn254/src/curves/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_algebra_test_templates::curves::*;
use ark_ec::{AffineCurve, ProjectiveCurve}; use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_ff::{bytes::FromBytes, Zero};
use ark_std::{rand::Rng, str::FromStr, test_rng};
use ark_ff::Zero;
use ark_std::str::FromStr;
use crate::*; use crate::*;
@ -12,26 +12,6 @@ fn test_projective_curve() {
edwards_tests::<EdwardsParameters>(); edwards_tests::<EdwardsParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = EdwardsAffine::prime_subgroup_generator(); let generator = EdwardsAffine::prime_subgroup_generator();
@ -39,22 +19,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_scalar_multiplication() { fn test_scalar_multiplication() {
let f1 = Fr::from_str( let f1 = Fr::from_str(
@ -85,19 +49,6 @@ fn test_scalar_multiplication() {
assert_eq!(f1g.mul(f2).into_affine(), f1f2g); assert_eq!(f1g.mul(f2).into_affine(), f1f2g);
} }
#[test]
fn test_bytes() {
let g_from_repr = EdwardsAffine::from_str(
"(15863623088992515880085393097393553694825975317405843389771115419751650972659, \
16950150798460657717958625567821834550301663161624707787222815936182638968203)",
)
.unwrap();
let g_bytes = ark_ff::to_bytes![g_from_repr].unwrap();
let g = EdwardsAffine::read(g_bytes.as_slice()).unwrap();
assert_eq!(g_from_repr, g);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<EdwardsParameters>(); montgomery_conversion_test::<EdwardsParameters>();

+ 1
- 33
ed_on_bn254/src/fields/tests.rs

@ -3,8 +3,7 @@ use ark_algebra_test_templates::{
}; };
use ark_ff::{ use ark_ff::{
biginteger::BigInteger256 as BigInteger, biginteger::BigInteger256 as BigInteger,
bytes::{FromBytes, ToBytes},
fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField},
fields::{Field, LegendreSymbol::*, PrimeField},
One, UniformRand, Zero, One, UniformRand, Zero,
}; };
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize}; use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
@ -293,22 +292,6 @@ fn test_fq_legendre() {
assert_eq!(QuadraticNonResidue, Fq::from(e).legendre()); assert_eq!(QuadraticNonResidue, Fq::from(e).legendre());
} }
#[test]
fn test_fq_bytes() {
let f1_from_repr = Fq::from(BigInteger::new([
0xab8a2535947d1a77,
0x9ba74cbfda0bbcda,
0xe928b59724d60baf,
0x1cccaaeb9bb1680a,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fq::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_add() { fn test_fr_add() {
let f1 = Fr::from(BigInteger::new([ let f1 = Fr::from(BigInteger::new([
@ -354,21 +337,6 @@ fn test_fr_mul() {
])); ]));
assert_eq!(f1 * &f2, f3); assert_eq!(f1 * &f2, f3);
} }
#[test]
fn test_fr_bytes() {
let f1_from_repr = Fr::from(BigInteger::new([
0xc81265fb4130fe0c,
0xb308836c14e22279,
0x699e887f96bff372,
0x84ecc7e76c11ad,
]));
let mut f1_bytes = [0u8; 32];
f1_from_repr.write(f1_bytes.as_mut()).unwrap();
let f1 = Fr::read(f1_bytes.as_ref()).unwrap();
assert_eq!(f1_from_repr, f1);
}
#[test] #[test]
fn test_fr_from_str() { fn test_fr_from_str() {

+ 1
- 1
ed_on_bw6_761/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_bw6_761`. //! This module implements the R1CS equivalent of `ark_ed_on_bw6_761`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 1
- 1
ed_on_cp6_782/src/constraints/mod.rs

@ -2,7 +2,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_cp6_782`. //! This module implements the R1CS equivalent of `ark_ed_on_cp6_782`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 17
- 17
ed_on_cp6_782/src/curves/mod.rs

@ -1,6 +1,6 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine, GroupProjective},
models::CurveConfig,
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
@ -9,13 +9,13 @@ use crate::{Fq, Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
pub type EdwardsAffine = Affine<EdwardsParameters>;
pub type EdwardsProjective = Projective<EdwardsParameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct EdwardsParameters; pub struct EdwardsParameters;
impl ModelParameters for EdwardsParameters {
impl CurveConfig for EdwardsParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -24,20 +24,20 @@ impl ModelParameters for EdwardsParameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560 /// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560
const COFACTOR_INV: Fr = MontFp!(Fr, "12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560");
const COFACTOR_INV: Fr = MontFp!("12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560");
} }
impl TEModelParameters for EdwardsParameters {
impl TECurveConfig for EdwardsParameters {
/// COEFF_A = -1 = /// COEFF_A = -1 =
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = 79743 /// COEFF_D = 79743
const COEFF_D: Fq = MontFp!(Fq, "79743");
const COEFF_D: Fq = MontFp!("79743");
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = EdwardsParameters;
type MontCurveConfig = EdwardsParameters;
/// Multiplication by `a` is just negation. /// Multiplication by `a` is just negation.
#[inline(always)] #[inline(always)]
@ -46,20 +46,20 @@ impl TEModelParameters for EdwardsParameters {
} }
} }
impl MontgomeryModelParameters for EdwardsParameters {
impl MontCurveConfig for EdwardsParameters {
/// COEFF_A = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535 /// COEFF_A = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535
const COEFF_A: Fq = MontFp!(Fq, "90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765");
const COEFF_A: Fq = MontFp!("90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765");
/// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA /// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA
const COEFF_B: Fq = MontFp!(Fq, "168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410");
const COEFF_B: Fq = MontFp!("168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410");
type TEModelParameters = EdwardsParameters;
type TECurveConfig = EdwardsParameters;
} }
/// GENERATOR_X = /// GENERATOR_X =
/// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127 /// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127
const GENERATOR_X: Fq = MontFp!(Fq, "174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127");
const GENERATOR_X: Fq = MontFp!("174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127");
/// GENERATOR_Y = /// GENERATOR_Y =
/// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833 /// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833
const GENERATOR_Y: Fq = MontFp!(Fq, "208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833");
const GENERATOR_Y: Fq = MontFp!("208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833");

+ 2
- 39
ed_on_cp6_782/src/curves/tests.rs

@ -1,6 +1,5 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_std::{rand::Rng, test_rng};
use ark_algebra_test_templates::curves::*;
use ark_ec::AffineCurve;
use crate::*; use crate::*;
@ -11,26 +10,6 @@ fn test_projective_curve() {
edwards_tests::<EdwardsParameters>(); edwards_tests::<EdwardsParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = EdwardsAffine::prime_subgroup_generator(); let generator = EdwardsAffine::prime_subgroup_generator();
@ -38,22 +17,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<EdwardsParameters>(); montgomery_conversion_test::<EdwardsParameters>();

+ 1
- 1
ed_on_cp6_782/src/fields/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};

+ 1
- 1
ed_on_mnt4_298/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_mnt4_298`. //! This module implements the R1CS equivalent of `ark_ed_on_mnt4_298`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 14
- 17
ed_on_mnt4_298/src/curves/mod.rs

@ -1,6 +1,6 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine, GroupProjective},
models::CurveConfig,
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
pub type EdwardsAffine = Affine<EdwardsParameters>;
pub type EdwardsProjective = Projective<EdwardsParameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct EdwardsParameters; pub struct EdwardsParameters;
impl ModelParameters for EdwardsParameters {
impl CurveConfig for EdwardsParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -25,7 +25,6 @@ impl ModelParameters for EdwardsParameters {
/// COFACTOR_INV (mod r) = /// COFACTOR_INV (mod r) =
/// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158 /// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158
const COFACTOR_INV: Fr = MontFp!( const COFACTOR_INV: Fr = MontFp!(
Fr,
"29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158" "29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158"
); );
} }
@ -35,23 +34,23 @@ impl ModelParameters for EdwardsParameters {
// R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876 // R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876
// R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545 // R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
impl TEModelParameters for EdwardsParameters {
impl TECurveConfig for EdwardsParameters {
/// COEFF_A = -1 /// COEFF_A = -1
/// Needs to be in the Montgomery residue form in Fq /// Needs to be in the Montgomery residue form in Fq
/// I.e., -1 * R for Fq /// I.e., -1 * R for Fq
/// = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261 /// = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = 4212 /// COEFF_D = 4212
/// Needs to be in the Montgomery residue form in Fq /// Needs to be in the Montgomery residue form in Fq
/// I.e., 4212 * R for Fq /// I.e., 4212 * R for Fq
/// = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000 /// = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
const COEFF_D: Fq = MontFp!(Fq, "4212");
const COEFF_D: Fq = MontFp!("4212");
/// Generated randomly /// Generated randomly
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = EdwardsParameters;
type MontCurveConfig = EdwardsParameters;
/// Multiplication by `a` is just negation. /// Multiplication by `a` is just negation.
#[inline(always)] #[inline(always)]
@ -60,26 +59,24 @@ impl TEModelParameters for EdwardsParameters {
} }
} }
impl MontgomeryModelParameters for EdwardsParameters {
impl MontCurveConfig for EdwardsParameters {
/// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204 /// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204
const COEFF_A: Fq = MontFp!(Fq, "203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
const COEFF_A: Fq = MontFp!("203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
/// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931 /// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
const COEFF_B: Fq = MontFp!(Fq, "272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
const COEFF_B: Fq = MontFp!("272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
type TEModelParameters = EdwardsParameters;
type TECurveConfig = EdwardsParameters;
} }
/// GENERATOR_X = /// GENERATOR_X =
/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227 /// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
const GENERATOR_X: Fq = MontFp!( const GENERATOR_X: Fq = MontFp!(
Fq,
"282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227" "282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227"
); );
/// GENERATOR_Y = /// GENERATOR_Y =
/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703 /// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
const GENERATOR_Y: Fq = MontFp!( const GENERATOR_Y: Fq = MontFp!(
Fq,
"452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703" "452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703"
); );

+ 2
- 47
ed_on_mnt4_298/src/curves/tests.rs

@ -1,37 +1,8 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_std::{rand::Rng, test_rng};
use ark_algebra_test_templates::curves::*;
use ark_ec::AffineCurve;
use crate::*; use crate::*;
#[test]
fn test_projective_curve() {
curve_tests::<EdwardsProjective>();
edwards_tests::<EdwardsParameters>();
}
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = EdwardsAffine::prime_subgroup_generator(); let generator = EdwardsAffine::prime_subgroup_generator();
@ -39,22 +10,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<EdwardsParameters>(); montgomery_conversion_test::<EdwardsParameters>();

+ 1
- 1
ed_on_mnt4_298/src/fields/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};

+ 1
- 1
ed_on_mnt4_753/src/constraints/mod.rs

@ -1,7 +1,7 @@
//! This module implements the R1CS equivalent of `ark_ed_on_mnt4_753`. //! This module implements the R1CS equivalent of `ark_ed_on_mnt4_753`.
//! //!
//! It implements field variables for `crate::Fq`, //! It implements field variables for `crate::Fq`,
//! and group variables for `crate::GroupProjective`.
//! and group variables for `crate::Projective`.
//! //!
//! The field underlying these constraints is `crate::Fq`. //! The field underlying these constraints is `crate::Fq`.
//! //!

+ 17
- 17
ed_on_mnt4_753/src/curves/mod.rs

@ -1,6 +1,6 @@
use ark_ec::{ use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
twisted_edwards_extended::{GroupAffine, GroupProjective},
models::CurveConfig,
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
}; };
use ark_ff::MontFp; use ark_ff::MontFp;
@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
pub type EdwardsAffine = Affine<EdwardsParameters>;
pub type EdwardsProjective = Projective<EdwardsParameters>;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct EdwardsParameters; pub struct EdwardsParameters;
impl ModelParameters for EdwardsParameters {
impl CurveConfig for EdwardsParameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -24,20 +24,20 @@ impl ModelParameters for EdwardsParameters {
/// COFACTOR_INV (mod r) = /// COFACTOR_INV (mod r) =
/// 4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505 /// 4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505
const COFACTOR_INV: Fr = MontFp!(Fr, "4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505");
const COFACTOR_INV: Fr = MontFp!("4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505");
} }
impl TEModelParameters for EdwardsParameters {
impl TECurveConfig for EdwardsParameters {
/// COEFF_A = -1 /// COEFF_A = -1
const COEFF_A: Fq = MontFp!(Fq, "-1");
const COEFF_A: Fq = MontFp!("-1");
/// COEFF_D = 317690 /// COEFF_D = 317690
const COEFF_D: Fq = MontFp!(Fq, "317690");
const COEFF_D: Fq = MontFp!("317690");
/// Generated randomly /// Generated randomly
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
type MontgomeryModelParameters = EdwardsParameters;
type MontCurveConfig = EdwardsParameters;
/// Multiplication by `a` is just negation. /// Multiplication by `a` is just negation.
#[inline(always)] #[inline(always)]
@ -46,20 +46,20 @@ impl TEModelParameters for EdwardsParameters {
} }
} }
impl MontgomeryModelParameters for EdwardsParameters {
impl MontCurveConfig for EdwardsParameters {
/// COEFF_A = 40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419 /// COEFF_A = 40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419
const COEFF_A: Fq = MontFp!(Fq, "40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419");
const COEFF_A: Fq = MontFp!("40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419");
/// COEFF_B = 1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580 /// COEFF_B = 1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580
const COEFF_B: Fq = MontFp!(Fq, "1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580");
const COEFF_B: Fq = MontFp!("1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580");
type TEModelParameters = EdwardsParameters;
type TECurveConfig = EdwardsParameters;
} }
/// GENERATOR_X = /// GENERATOR_X =
/// 41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826 /// 41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826
const GENERATOR_X: Fq = MontFp!(Fq, "41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826");
const GENERATOR_X: Fq = MontFp!("41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826");
/// GENERATOR_Y = /// GENERATOR_Y =
/// 18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681 /// 18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681
const GENERATOR_Y: Fq = MontFp!(Fq, "18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681");
const GENERATOR_Y: Fq = MontFp!("18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681");

+ 2
- 40
ed_on_mnt4_753/src/curves/tests.rs

@ -1,6 +1,5 @@
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_std::{rand::Rng, test_rng};
use ark_algebra_test_templates::curves::*;
use ark_ec::AffineCurve;
use crate::*; use crate::*;
@ -11,27 +10,6 @@ fn test_projective_curve() {
edwards_tests::<EdwardsParameters>(); edwards_tests::<EdwardsParameters>();
} }
#[test]
fn test_projective_group() {
let mut rng = test_rng();
let a = rng.gen();
let b = rng.gen();
for _i in 0..100 {
group_test::<EdwardsProjective>(a, b);
}
}
#[test]
fn test_affine_group() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
for _i in 0..100 {
group_test::<EdwardsAffine>(a, b);
}
}
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = EdwardsAffine::prime_subgroup_generator(); let generator = EdwardsAffine::prime_subgroup_generator();
@ -39,22 +17,6 @@ fn test_generator() {
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }
#[test]
fn test_conversion() {
let mut rng = test_rng();
let a: EdwardsAffine = rng.gen();
let b: EdwardsAffine = rng.gen();
let a_b = {
use ark_ec::group::Group;
(a + &b).double().double()
};
let a_b2 = (a.into_projective() + &b.into_projective())
.double()
.double();
assert_eq!(a_b, a_b2.into_affine());
assert_eq!(a_b.into_projective(), a_b2);
}
#[test] #[test]
fn test_montgomery_conversion() { fn test_montgomery_conversion() {
montgomery_conversion_test::<EdwardsParameters>(); montgomery_conversion_test::<EdwardsParameters>();

+ 1
- 1
ed_on_mnt4_753/src/fields/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};

+ 9
- 12
mnt4_298/src/curves/g1.rs

@ -1,10 +1,10 @@
use ark_ec::{ use ark_ec::{
mnt4, 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 G1Affine = mnt4::G1Affine<crate::Parameters>;
pub type G1Projective = mnt4::G1Projective<crate::Parameters>; pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
@ -13,7 +13,7 @@ pub type G1Prepared = mnt4::G1Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -22,21 +22,20 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 1 /// 1
const COFACTOR_INV: Fr = FR_ONE;
const COFACTOR_INV: Fr = Fr::ONE;
} }
impl SWModelParameters for Parameters {
impl SWCurveConfig for Parameters {
/// COEFF_A = 2 /// COEFF_A = 2
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116> /// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L116>
const COEFF_A: Fq = MontFp!(Fq, "2");
const COEFF_A: Fq = MontFp!("2");
/// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685 /// COEFF_B = 423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117> /// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L117>
const COEFF_B: Fq = MontFp!(Fq, "423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
const COEFF_B: Fq = MontFp!("423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// 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 // Generator of G1
@ -45,13 +44,11 @@ impl SWModelParameters for Parameters {
/// G1_GENERATOR_X /// G1_GENERATOR_X
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137> /// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L137>
pub const G1_GENERATOR_X: Fq = MontFp!( pub const G1_GENERATOR_X: Fq = MontFp!(
Fq,
"60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838" "60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838"
); );
/// G1_GENERATOR_Y /// G1_GENERATOR_Y
/// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138> /// Reference: <https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L138>
pub const G1_GENERATOR_Y: Fq = MontFp!( pub const G1_GENERATOR_Y: Fq = MontFp!(
Fq,
"363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306" "363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306"
); );

+ 13
- 18
mnt4_298/src/curves/g2.rs

@ -1,11 +1,11 @@
use ark_ec::{ use ark_ec::{
mnt4, mnt4,
mnt4::MNT4Parameters, 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 G2Affine = mnt4::G2Affine<crate::Parameters>;
pub type G2Projective = mnt4::G2Projective<crate::Parameters>; pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
@ -14,7 +14,7 @@ pub type G2Prepared = mnt4::G2Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq2; type BaseField = Fq2;
type ScalarField = Fr; type ScalarField = Fr;
@ -31,7 +31,7 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665 /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
const COFACTOR_INV: Fr = MontFp!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
const COFACTOR_INV: Fr = MontFp!("475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
} }
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A /// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
@ -40,7 +40,7 @@ pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE; 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; const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
// B coefficient of MNT4-298 G2 = // B coefficient of MNT4-298 G2 =
// ``` // ```
@ -51,23 +51,22 @@ impl SWModelParameters for Parameters {
// = // =
// (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430) // (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430)
// ``` // ```
const COEFF_B: Fq2 = QuadExt!(
FQ_ZERO,
MontFp!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
const COEFF_B: Fq2 = Fq2::new(
Fq::ZERO,
MontFp!("67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
); );
/// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y) /// 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)] #[inline(always)]
fn mul_by_a(elt: &Fq2) -> Fq2 { 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 // Generator of G2
// These are two Fq elements each because X and Y (and Z) are elements of Fq^2 // These are two Fq elements each because X and Y (and Z) are elements of Fq^2
@ -76,21 +75,17 @@ const G2_GENERATOR_Y: Fq2 = QuadExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482, // Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489, // 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
pub const G2_GENERATOR_X_C0: Fq = MontFp!( pub const G2_GENERATOR_X_C0: Fq = MontFp!(
Fq,
"438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708" "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708"
); );
pub const G2_GENERATOR_X_C1: Fq = MontFp!( pub const G2_GENERATOR_X_C1: Fq = MontFp!(
Fq,
"37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641" "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641"
); );
pub const G2_GENERATOR_Y_C0: Fq = MontFp!( pub const G2_GENERATOR_Y_C0: Fq = MontFp!(
Fq,
"37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482" "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482"
); );
pub const G2_GENERATOR_Y_C1: Fq = MontFp!( pub const G2_GENERATOR_Y_C1: Fq = MontFp!(
Fq,
"424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489" "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489"
); );

+ 5
- 9
mnt4_298/src/curves/mod.rs

@ -1,7 +1,7 @@
use ark_ec::models::mnt4::{MNT4Parameters, MNT4}; use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
use ark_ff::{biginteger::BigInteger320, BigInt, Fp2, MontFp, QuadExt};
use ark_ff::{biginteger::BigInteger320, BigInt, Field, MontFp};
use crate::{Fq, Fq2Config, Fq4Config, Fr};
use crate::{Fq, Fq2, Fq2Config, Fq4Config, Fr};
pub mod g1; pub mod g1;
pub mod g2; pub mod g2;
@ -19,14 +19,14 @@ pub type MNT4_298 = MNT4;
pub struct Parameters; pub struct Parameters;
impl MNT4Parameters for Parameters { impl MNT4Parameters for Parameters {
const TWIST: Fp2<Self::Fp2Config> = QuadExt!(FQ_ZERO, FQ_ONE);
const TWIST: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE);
// A coefficient of MNT4-298 G2 = // A coefficient of MNT4-298 G2 =
// ``` // ```
// mnt4298_twist_coeff_a = mnt4298_Fq2(mnt4298_G1::coeff_a * non_residue, mnt6298_Fq::zero()); // mnt4298_twist_coeff_a = mnt4298_Fq2(mnt4298_G1::coeff_a * non_residue, mnt6298_Fq::zero());
// = (A_COEFF * NONRESIDUE, ZERO) // = (A_COEFF * NONRESIDUE, ZERO)
// = (34, ZERO) // = (34, ZERO)
// ``` // ```
const TWIST_COEFF_A: Fp2<Self::Fp2Config> = QuadExt!(G1_COEFF_A_NON_RESIDUE, FQ_ZERO);
const TWIST_COEFF_A: Fq2 = Fq2::new(G1_COEFF_A_NON_RESIDUE, Fq::ZERO);
const ATE_LOOP_COUNT: &'static [u64] = &[993502997770534912, 5071219579242586943, 2027349]; const ATE_LOOP_COUNT: &'static [u64] = &[993502997770534912, 5071219579242586943, 2027349];
const ATE_IS_LOOP_COUNT_NEG: bool = false; const ATE_IS_LOOP_COUNT_NEG: bool = false;
@ -43,8 +43,4 @@ impl MNT4Parameters for Parameters {
} }
// 34 // 34
pub const G1_COEFF_A_NON_RESIDUE: Fq = MontFp!(Fq, "34");
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!("34");

+ 1
- 1
mnt4_298/src/curves/tests.rs

@ -1,6 +1,6 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, 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_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_ff::{Field, One, PrimeField, UniformRand};

+ 5
- 5
mnt4_298/src/fields/fq2.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp2::{Fp2, Fp2Config}, fields::fp2::{Fp2, Fp2Config},
MontFp,
Field, MontFp,
}; };
use crate::{Fq, FQ_ONE};
use crate::Fq;
pub type Fq2 = Fp2<Fq2Config>; pub type Fq2 = Fp2<Fq2Config>;
@ -14,12 +14,12 @@ impl Fp2Config for Fq2Config {
/// The quadratic non-residue (17) used to construct the extension is /// The quadratic non-residue (17) used to construct the extension is
/// the same as that used in [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L102). /// the same as that used in [`libff`](https://github.com/scipr-lab/libff/blob/c927821ebe02e0a24b5e0f9170cec5e211a35f08/libff/algebra/curves/mnt/mnt4/mnt4_init.cpp#L102).
const NONRESIDUE: Fq = MontFp!(Fq, "17");
const NONRESIDUE: Fq = MontFp!("17");
/// Precomputed coefficients: /// Precomputed coefficients:
/// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]` /// `[1, 475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080]`
const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[
FQ_ONE,
MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
Fq::ONE,
MontFp!("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
]; ];
} }

+ 7
- 7
mnt4_298/src/fields/fq4.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp4::{Fp4, Fp4Config}, 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>; pub type Fq4 = Fp4<Fq4Config>;
@ -12,7 +12,7 @@ pub struct Fq4Config;
impl Fp4Config for Fq4Config { impl Fp4Config for Fq4Config {
type Fp2Config = Fq2Config; 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. // Coefficients for the Frobenius automorphism.
// c1[0] = 1, // c1[0] = 1,
@ -23,9 +23,9 @@ impl Fp4Config for Fq4Config {
// These are calculated as // These are calculated as
// `FROBENIUS_COEFF_FP4_C1[i] = Fp2Config::NONRESIDUE^((q^i - 1) / 4)`. // `FROBENIUS_COEFF_FP4_C1[i] = Fp2Config::NONRESIDUE^((q^i - 1) / 4)`.
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[ const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[
FQ_ONE,
MontFp!(Fq, "7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"),
MontFp!(Fq, "475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
MontFp!(Fq, "468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"),
Fq::ONE,
MontFp!("7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308"),
MontFp!("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080"),
MontFp!("468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773"),
]; ];
} }

+ 1
- 1
mnt4_298/src/fields/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};

+ 11
- 12
mnt4_753/src/curves/g1.rs

@ -1,10 +1,10 @@
use ark_ec::{ use ark_ec::{
mnt4, 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 G1Affine = mnt4::G1Affine<crate::Parameters>;
pub type G1Projective = mnt4::G1Projective<crate::Parameters>; pub type G1Projective = mnt4::G1Projective<crate::Parameters>;
@ -13,7 +13,7 @@ pub type G1Prepared = mnt4::G1Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -21,19 +21,18 @@ impl ModelParameters for Parameters {
const COFACTOR: &'static [u64] = &[1]; const COFACTOR: &'static [u64] = &[1];
/// COFACTOR^(-1) mod r = 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 /// COEFF_A = 2
const COEFF_A: Fq = MontFp!(Fq, "2");
const COEFF_A: Fq = MontFp!("2");
/// COEFF_B = 0x01373684A8C9DCAE7A016AC5D7748D3313CD8E39051C596560835DF0C9E50A5B59B882A92C78DC537E51A16703EC9855C77FC3D8BB21C8D68BB8CFB9DB4B8C8FBA773111C36C8B1B4E8F1ECE940EF9EAAD265458E06372009C9A0491678EF4 /// 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) /// 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 // Generator of G1
@ -41,8 +40,8 @@ impl SWModelParameters for Parameters {
// Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648, // Y = 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648,
/// G1_GENERATOR_X = /// G1_GENERATOR_X =
/// 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569 /// 7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569");
pub const G1_GENERATOR_X: Fq = MontFp!("7790163481385331313124631546957228376128961350185262705123068027727518350362064426002432450801002268747950550964579198552865939244360469674540925037890082678099826733417900510086646711680891516503232107232083181010099241949569");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
/// 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648 /// 6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648");
pub const G1_GENERATOR_Y: Fq = MontFp!("6913648190367314284606685101150155872986263667483624713540251048208073654617802840433842931301128643140890502238233930290161632176167186761333725658542781350626799660920481723757654531036893265359076440986158843531053720994648");

+ 17
- 18
mnt4_753/src/curves/g2.rs

@ -1,11 +1,11 @@
use ark_ec::{ use ark_ec::{
mnt4, mnt4,
mnt4::MNT4Parameters, 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 G2Affine = mnt4::G2Affine<crate::Parameters>;
pub type G2Projective = mnt4::G2Projective<crate::Parameters>; pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
@ -14,7 +14,7 @@ pub type G2Prepared = mnt4::G2Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq2; type BaseField = Fq2;
type ScalarField = Fr; type ScalarField = Fr;
@ -38,7 +38,7 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200 /// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200
const COFACTOR_INV: Fr = MontFp!(Fr, "102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
const COFACTOR_INV: Fr = MontFp!("102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
} }
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A /// 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 /// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE; 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; const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
// B coefficient of MNT4-753 G2 = // B coefficient of MNT4-753 G2 =
// ``` // ```
@ -58,23 +58,22 @@ impl SWModelParameters for Parameters {
// = // =
// (0, 39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212) // (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) /// 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)] #[inline(always)]
fn mul_by_a(elt: &Fq2) -> Fq2 { 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 // Generator of G2
// These are two Fq elements each because X and Y (and Z) are elements of Fq^2 // 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, // 19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000,
// Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654, // Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654,
// 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245, // 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");

+ 4
- 9
mnt4_753/src/curves/mod.rs

@ -1,7 +1,7 @@
use ark_ec::models::mnt4::{MNT4Parameters, MNT4}; use ark_ec::models::mnt4::{MNT4Parameters, MNT4};
use ark_ff::{ use ark_ff::{
biginteger::{BigInt, BigInteger768}, biginteger::{BigInt, BigInteger768},
Fp2, MontFp, QuadExt,
Field, Fp2, MontFp,
}; };
use crate::{Fq, Fq2Config, Fq4Config, Fr}; use crate::{Fq, Fq2Config, Fq4Config, Fr};
@ -22,14 +22,14 @@ pub type MNT4_753 = MNT4;
pub struct Parameters; pub struct Parameters;
impl MNT4Parameters for 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 = // A coefficient of MNT4-753 G2 =
// ``` // ```
// mnt4753_twist_coeff_a = mnt4753_Fq2(mnt4753_G1::coeff_a * non_residue, mnt6753_Fq::zero()); // mnt4753_twist_coeff_a = mnt4753_Fq2(mnt4753_G1::coeff_a * non_residue, mnt6753_Fq::zero());
// = (A_COEFF * NONRESIDUE, ZERO) // = (A_COEFF * NONRESIDUE, ZERO)
// = (26, 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 // https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt4753.ml
const ATE_LOOP_COUNT: &'static [u64] = &[ const ATE_LOOP_COUNT: &'static [u64] = &[
8824542903220142080, 8824542903220142080,
@ -66,9 +66,4 @@ impl MNT4Parameters for Parameters {
} }
// 26 // 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
- 1
mnt4_753/src/curves/tests.rs

@ -1,6 +1,6 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, 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_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_ff::{Field, One, PrimeField, UniformRand};

+ 5
- 5
mnt4_753/src/fields/fq2.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp2::{Fp2, Fp2Config}, fields::fp2::{Fp2, Fp2Config},
MontFp,
Field, MontFp,
}; };
use crate::{Fq, FQ_ONE};
use crate::Fq;
pub type Fq2 = Fp2<Fq2Config>; pub type Fq2 = Fp2<Fq2Config>;
@ -13,13 +13,13 @@ impl Fp2Config for Fq2Config {
type Fp = Fq; type Fp = Fq;
// non_residue = 13 // non_residue = 13
const NONRESIDUE: Fq = MontFp!(Fq, "13");
const NONRESIDUE: Fq = MontFp!("13");
// Coefficients: // Coefficients:
// [1, 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600] // [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 // 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] = &[ const FROBENIUS_COEFF_FP2_C1: &'static [Self::Fp] = &[
FQ_ONE,
MontFp!(Fq, "41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
Fq::ONE,
MontFp!("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689600"),
]; ];
} }

+ 7
- 7
mnt4_753/src/fields/fq4.rs

@ -1,9 +1,9 @@
use ark_ff::{ use ark_ff::{
fields::fp4::{Fp4, Fp4Config}, 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>; pub type Fq4 = Fp4<Fq4Config>;
@ -12,7 +12,7 @@ pub struct Fq4Config;
impl Fp4Config for Fq4Config { impl Fp4Config for Fq4Config {
type Fp2Config = Fq2Config; 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. // Coefficients for the Frobenius automorphism.
// c1[0] = 1, // c1[0] = 1,
@ -23,9 +23,9 @@ impl Fp4Config for Fq4Config {
// These are calculated as `FROBENIUS_COEFF_FP4_C1[i] = // These are calculated as `FROBENIUS_COEFF_FP4_C1[i] =
// Fp2Config::NONRESIDUE^((q^i - 1) / 4)`. // Fp2Config::NONRESIDUE^((q^i - 1) / 4)`.
const FROBENIUS_COEFF_FP4_C1: &'static [Fq] = &[ 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
- 1
mnt4_753/src/fields/tests.rs

@ -1,7 +1,7 @@
use ark_algebra_test_templates::{ use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test, 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_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng}; use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign}; use core::ops::{AddAssign, MulAssign, SubAssign};

+ 10
- 11
mnt6_298/src/curves/g1.rs

@ -1,8 +1,8 @@
use ark_ec::{ use ark_ec::{
mnt6, mnt6,
models::{ModelParameters, SWModelParameters},
models::{short_weierstrass::SWCurveConfig, CurveConfig},
}; };
use ark_ff::MontFp;
use ark_ff::{Field, MontFp};
use crate::{Fq, Fr}; use crate::{Fq, Fr};
@ -13,7 +13,7 @@ pub type G1Prepared = mnt6::G1Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq; type BaseField = Fq;
type ScalarField = Fr; type ScalarField = Fr;
@ -21,25 +21,24 @@ impl ModelParameters for Parameters {
const COFACTOR: &'static [u64] = &[1]; const COFACTOR: &'static [u64] = &[1];
/// COFACTOR^(-1) mod r = 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 /// COEFF_A = 11
const COEFF_A: Fq = MontFp!(Fq, "11");
const COEFF_A: Fq = MontFp!("11");
/// COEFF_B = 106700080510851735677967319632585352256454251201367587890185989362936000262606668469523074 /// 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) /// 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 = /// G1_GENERATOR_X =
#[rustfmt::skip] #[rustfmt::skip]
pub const G1_GENERATOR_X: Fq = MontFp!(Fq, "336685752883082228109289846353937104185698209371404178342968838739115829740084426881123453");
pub const G1_GENERATOR_X: Fq = MontFp!("336685752883082228109289846353937104185698209371404178342968838739115829740084426881123453");
/// G1_GENERATOR_Y = /// G1_GENERATOR_Y =
#[rustfmt::skip] #[rustfmt::skip]
pub const G1_GENERATOR_Y: Fq = MontFp!(Fq, "402596290139780989709332707716568920777622032073762749862342374583908837063963736098549800");
pub const G1_GENERATOR_Y: Fq = MontFp!("402596290139780989709332707716568920777622032073762749862342374583908837063963736098549800");

+ 15
- 23
mnt6_298/src/curves/g2.rs

@ -1,11 +1,11 @@
use ark_ec::{ use ark_ec::{
mnt6, mnt6,
mnt6::MNT6Parameters, 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 G2Affine = mnt6::G2Affine<crate::Parameters>;
pub type G2Projective = mnt6::G2Projective<crate::Parameters>; pub type G2Projective = mnt6::G2Projective<crate::Parameters>;
@ -14,7 +14,7 @@ pub type G2Prepared = mnt6::G2Prepared;
#[derive(Clone, Default, PartialEq, Eq)] #[derive(Clone, Default, PartialEq, Eq)]
pub struct Parameters; pub struct Parameters;
impl ModelParameters for Parameters {
impl CurveConfig for Parameters {
type BaseField = Fq3; type BaseField = Fq3;
type ScalarField = Fr; type ScalarField = Fr;
@ -37,36 +37,34 @@ impl ModelParameters for Parameters {
/// COFACTOR^(-1) mod r = /// COFACTOR^(-1) mod r =
/// 79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504 /// 79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504
const COFACTOR_INV: Fr = MontFp!( const COFACTOR_INV: Fr = MontFp!(
Fr,
"79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504" "79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504"
); );
} }
/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A = 5 * 11 /// 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 /// 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 /// MUL_BY_A_C2 = COEFF_A
pub const MUL_BY_A_C2: Fq = g1::Parameters::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_A: Fq3 = crate::Parameters::TWIST_COEFF_A;
const COEFF_B: Fq3 = CubicExt!(
const COEFF_B: Fq3 = Fq3::new(
// 5 * G1::COEFF_B // 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) /// 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)] #[inline(always)]
fn mul_by_a(elt: &Fq3) -> Fq3 { fn mul_by_a(elt: &Fq3) -> Fq3 {
CubicExt!(
Fq3::new(
MUL_BY_A_C0 * &elt.c1, MUL_BY_A_C0 * &elt.c1,
MUL_BY_A_C1 * &elt.c2, MUL_BY_A_C1 * &elt.c2,
MUL_BY_A_C2 * &elt.c0, 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!( pub const G2_GENERATOR_X_C0: Fq = MontFp!(
Fq,
"421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427" "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427"
); );
pub const G2_GENERATOR_X_C1: Fq = MontFp!( pub const G2_GENERATOR_X_C1: Fq = MontFp!(
Fq,
"103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114" "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114"
); );
pub const G2_GENERATOR_X_C2: Fq = MontFp!( pub const G2_GENERATOR_X_C2: Fq = MontFp!(
Fq,
"143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558" "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558"
); );
pub const G2_GENERATOR_Y_C0: Fq = MontFp!( pub const G2_GENERATOR_Y_C0: Fq = MontFp!(
Fq,
"464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377" "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377"
); );
pub const G2_GENERATOR_Y_C1: Fq = MontFp!( pub const G2_GENERATOR_Y_C1: Fq = MontFp!(
Fq,
"100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678" "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678"
); );
pub const G2_GENERATOR_Y_C2: Fq = MontFp!( pub const G2_GENERATOR_Y_C2: Fq = MontFp!(
Fq,
"123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903" "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903"
); );

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save