use generic_array::GenericArray;
use num::{BigUint, Num, Zero};
use serde::{Deserialize, Serialize};
use typenum::{U32, U62};
use super::{SwCurve, WeierstrassParameters};
use crate::operations::field::params::FieldParameters;
use crate::operations::field::params::NumLimbs;
use crate::utils::ec::CurveType;
use crate::utils::ec::EllipticCurveParameters;
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Bn254Parameters;
pub type Bn254 = SwCurve<Bn254Parameters>;
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Bn254BaseField;
impl FieldParameters for Bn254BaseField {
const MODULUS: &'static [u8] = &[
71, 253, 124, 216, 22, 140, 32, 60, 141, 202, 113, 104, 145, 106, 129, 151, 93, 88, 129,
129, 182, 69, 80, 184, 41, 160, 49, 225, 114, 78, 100, 48,
];
const WITNESS_OFFSET: usize = 1usize << 14;
fn modulus() -> BigUint {
BigUint::from_str_radix(
"21888242871839275222246405745257275088696311157297823662689037894645226208583",
10,
)
.unwrap()
}
}
impl NumLimbs for Bn254BaseField {
type Limbs = U32;
type Witness = U62;
}
impl EllipticCurveParameters for Bn254Parameters {
type BaseField = Bn254BaseField;
const CURVE_TYPE: CurveType = CurveType::Bn254;
}
impl WeierstrassParameters for Bn254Parameters {
const A: GenericArray<u8, U32> = GenericArray::from_array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
]);
const B: GenericArray<u8, U32> = GenericArray::from_array([
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
]);
fn generator() -> (BigUint, BigUint) {
let x = BigUint::from(1u32);
let y = BigUint::from(2u32);
(x, y)
}
fn prime_group_order() -> num::BigUint {
BigUint::from_str_radix(
"21888242871839275222246405745257275088548364400416034343698204186575808495617",
10,
)
.unwrap()
}
fn a_int() -> BigUint {
BigUint::zero()
}
fn b_int() -> BigUint {
BigUint::from(3u32)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::utils::ec::utils::biguint_from_limbs;
#[test]
fn test_weierstrass_biguint_scalar_mul() {
assert_eq!(
biguint_from_limbs(Bn254BaseField::MODULUS),
Bn254BaseField::modulus()
);
}
}