Skip to main content

airbender_crypto/bn254/curves/
mod.rs

1#[cfg(any(
2    all(target_arch = "riscv32", feature = "bigint_ops"),
3    test,
4    feature = "proving"
5))]
6use crate::ark_ff_delegation::MontFp;
7use ark_ec::{
8    bn,
9    bn::{BnConfig, TwistType},
10};
11#[cfg(not(any(
12    all(target_arch = "riscv32", feature = "bigint_ops"),
13    test,
14    feature = "proving"
15)))]
16use ark_ff::MontFp;
17
18use crate::bn254::fields::{Fq, Fq12Config, Fq2, Fq2Config, Fq6Config};
19
20pub mod g1;
21pub mod g2;
22
23mod pairing_impl;
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub struct Config;
27
28impl BnConfig for Config {
29    const X: &'static [u64] = &[4965661367192848881];
30    /// `x` is positive.
31    const X_IS_NEGATIVE: bool = false;
32    const ATE_LOOP_COUNT: &'static [i8] = &[
33        0, 0, 0, 1, 0, 1, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, -1, 0, 0, 0,
34        0, -1, 0, 0, 1, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, -1, 0,
35        -1, 0, 0, 0, 1, 0, 1, 1,
36    ];
37
38    const TWIST_MUL_BY_Q_X: Fq2 = Fq2::new(
39        MontFp!("21575463638280843010398324269430826099269044274347216827212613867836435027261"),
40        MontFp!("10307601595873709700152284273816112264069230130616436755625194854815875713954"),
41    );
42    const TWIST_MUL_BY_Q_Y: Fq2 = Fq2::new(
43        MontFp!("2821565182194536844548159561693502659359617185244120367078079554186484126554"),
44        MontFp!("3505843767911556378687030309984248845540243509899259641013678093033130930403"),
45    );
46    const TWIST_TYPE: TwistType = TwistType::D;
47    type Fp = Fq;
48    type Fp2Config = Fq2Config;
49    type Fp6Config = Fq6Config;
50    type Fp12Config = Fq12Config;
51    type G1Config = g1::Config;
52    type G2Config = g2::Config;
53}
54
55// pub type Bn254 = Bn<Config>;
56
57#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
58pub struct Bn254;
59
60pub type G1Affine = bn::G1Affine<Config>;
61pub type G1Projective = bn::G1Projective<Config>;
62pub type G2Affine = bn::G2Affine<Config>;
63pub type G2Projective = bn::G2Projective<Config>;