|
| 1 | +use ark_ec::models::short_weierstrass::{ |
| 2 | + Affine, Projective, SWCurveConfig, |
| 3 | +}; |
| 4 | +use ark_ec::CurveConfig; |
| 5 | +use ark_ff::{Field, MontFp, Zero, AdditiveGroup}; |
| 6 | + |
| 7 | +use crate::bn254::{Fq, Fr}; // Assuming Fq is defined in fq.rs |
| 8 | + |
| 9 | +#[derive(Clone, Default, PartialEq, Eq)] |
| 10 | +pub struct G1Config; |
| 11 | + |
| 12 | +impl CurveConfig for G1Config { |
| 13 | + type BaseField = Fq; |
| 14 | + type ScalarField = Fr; |
| 15 | + |
| 16 | + /// COFACTOR = 1 |
| 17 | + const COFACTOR: &'static [u64] = &[1]; |
| 18 | + |
| 19 | + /// COFACTOR_INV = COFACTOR^{-1} mod r = 1 |
| 20 | + const COFACTOR_INV: Self::ScalarField = Fr::ONE; |
| 21 | +} |
| 22 | + |
| 23 | +impl SWCurveConfig for G1Config { |
| 24 | + /// COEFF_A = 0 |
| 25 | + const COEFF_A: Self::BaseField = Fq::ZERO; |
| 26 | + |
| 27 | + /// COEFF_B = 3 |
| 28 | + const COEFF_B: Self::BaseField = MontFp!("3"); |
| 29 | + |
| 30 | + /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) |
| 31 | + const GENERATOR: Affine<Self> = Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); |
| 32 | + |
| 33 | + #[inline(always)] |
| 34 | + fn mul_by_a(_base: Self::BaseField) -> Self::BaseField { |
| 35 | + // A is zero, avoids a multiply |
| 36 | + Self::BaseField::zero() |
| 37 | + } |
| 38 | + |
| 39 | + #[inline(always)] |
| 40 | + fn is_in_correct_subgroup_assuming_on_curve(_p: &Affine<Self>) -> bool { |
| 41 | + // The cofactor is 1, so any point on the curve is in the correct subgroup. |
| 42 | + true |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +/// G1_GENERATOR_X = 1 |
| 47 | +pub const G1_GENERATOR_X: Fq = MontFp!("1"); |
| 48 | + |
| 49 | +/// G1_GENERATOR_Y = 2 |
| 50 | +pub const G1_GENERATOR_Y: Fq = MontFp!("2"); |
| 51 | + |
| 52 | +pub type G1Affine = Affine<G1Config>; |
| 53 | +pub type G1Projective = Projective<G1Config>; |
0 commit comments