arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_377/src/curves/g1_swu_iso.rs
bls12_377/src/curves/g1_swu_iso.rsRaw
  1use ark_ec::{
  2    hashing::curve_maps::{swu::SWUConfig, wb::IsogenyMap},
  3    models::{
  4        short_weierstrass::{Affine, SWCurveConfig},
  5        CurveConfig,
  6    },
  7};
  8
  9use ark_ff::MontFp;
 10
 11use crate::{g1, Fq, Fr};
 12
 13type G1Affine = Affine<SwuIsoConfig>;
 14
 15#[derive(Clone, Default, PartialEq, Eq)]
 16pub struct SwuIsoConfig;
 17
 18impl CurveConfig for SwuIsoConfig {
 19    type BaseField = Fq;
 20    type ScalarField = Fr;
 21
 22    /// COFACTOR = (x - 1)^2 / 3  = iso_G1.domain().order() /
 23    /// 8444461749428370424248824938781546531375899335154063827935233455917409239041
 24    //  30631250834960419227450344600217059328
 25    const COFACTOR: &'static [u64] = &[0x0, 0x170b5d4430000000];
 26
 27    /// COFACTOR_INV = COFACTOR^{-1} mod r
 28    /// = 5285428838741532253824584287042945485047145357130994810877
 29    const COFACTOR_INV: Fr = MontFp!("5285428838741532253824584287042945485047145357130994810877");
 30}
 31
 32// sage: iso_G1
 33// Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 +
 34// 258664426012969092796408009721202742408018065645352501567204841856062976176281513834280849065051431927238430294002*
 35// x + 22 over Finite Field of size
 36// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
 37// to Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field of size
 38// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
 39
 40impl SWCurveConfig for SwuIsoConfig {
 41    /// COEFF_A
 42    const COEFF_A: Fq = MontFp!("258664426012969092796408009721202742408018065645352501567204841856062976176281513834280849065051431927238430294002");
 43
 44    /// COEFF_B
 45    const COEFF_B: Fq = MontFp!("22");
 46
 47    /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
 48    const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
 49}
 50
 51// sage: G1_gen  = iso_G1.domain().random_point()
 52// sage: G1_gen = 30631250834960419227450344600217059328* G1_gen
 53// sage: G1_gen.order() ==
 54// 8444461749428370424248824938781546531375899335154063827935233455917409239041
 55// True
 56// sage: G1_gen
 57// (183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830 : 69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974 : 1)
 58/// G1_GENERATOR_X =
 59/// 183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830
 60pub const G1_GENERATOR_X: Fq = MontFp!("183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830");
 61
 62/// G1_GENERATOR_Y =
 63/// 69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974
 64pub const G1_GENERATOR_Y: Fq = MontFp!("69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974");
 65
 66impl SWUConfig for SwuIsoConfig {
 67    const ZETA: Fq = MontFp!("-11"); // arbitatry primitive root of unity (element)
 68}
 69
 70pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoConfig, g1::Config, > = IsogenyMap {
 71    x_map_numerator : &[
 72        MontFp!("193998319509726820447277314072485610595876362210707887456279225959507476652652651634192264150953923683470146535424"), 
 73        MontFp!("40474824132456359704279181570318738632422647360355249739068643631356267969150730939906729705473"), 
 74        MontFp!("193998319509726820507989550271170150152295134566185995404913197000040351261255617081226666104680020093330241093633"),
 75    ],
 76
 77    x_map_denominator : &[
 78        MontFp!("161899296529825438817116726281274954529690589441420998956274574525425071876602923759626918821892"), 
 79        MontFp!("1"),
 80    ],
 81
 82    y_map_numerator : &[
 83        MontFp!("193998319509726820507989550271170150152295134566185995404913197000040351261255617081226666104680020093330241093631"), 
 84        MontFp!("32333053251621136903112182208573040583096119983059602439070460434672245065050016464457115901761911040205276577794"), 
 85        MontFp!("129332213006484547066038603046131306324615528732935438218576102373893108782773376834518846023512776472080255287298"), 
 86        MontFp!("226331372761347957259321141983031841844344323660550327972398729833380409804798219928097777122126690108885281275905"),
 87    ],
 88
 89    y_map_denominator : &[
 90        MontFp!("258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458169"), 
 91        MontFp!("971395779178952632902700357687649727178143536648525993737647447152550431259617542557761512931340"), 
 92        MontFp!("485697889589476316451350178843824863589071768324262996868823723576275215629808771278880756465676"), 
 93        MontFp!("1"),
 94    ],
 95};
 96
 97#[cfg(test)]
 98mod test {
 99    use super::*;
100
101    #[test]
102    fn test_gen() {
103        let gen: G1Affine = SwuIsoConfig::GENERATOR;
104        assert!(gen.is_on_curve());
105        assert!(gen.is_in_correct_subgroup_assuming_on_curve());
106    }
107}