use cryptix_ecc::CurvePoint;
use cryptix_field::field::{montgomery::MontgomeryOps, MulIdentity};
use cryptix_bn254::{galoisfield::{FpElement, fp12::Fp12Element}, pairing::{e1::BN254Fp, e2::BN254Fp2, o_ate::OptimalAte, Pairing}};
const SEED: [u8; 32] = [
1, 0, 52, 0, 0, 0, 0, 0,
1, 0, 10, 0, 22, 32, 0, 0,
2, 0, 55, 49, 0, 11, 0, 0,
3, 0, 0, 0, 0, 0, 2, 92,
];
#[test]
fn test_ate_bilinear() {
use rand_chacha::rand_core::SeedableRng;
let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED);
for _ in 0..5 {
let k = FpElement::rand(&mut rng).repr();
let p = BN254Fp::GENERATOR.scalar_mul(k);
let q = BN254Fp2::GENERATOR;
let f = OptimalAte::pairing(p, q);
let g = OptimalAte::pairing(-p, q);
let q = f.mont_mul(g).mont_rdc();
assert_eq!(q, Fp12Element::ONE);
let g = OptimalAte::pairing(BN254Fp::GENERATOR, BN254Fp2::GENERATOR);
let left = g.mont_rdc().mont_exp(k);
let right = OptimalAte::pairing(
BN254Fp::GENERATOR.scalar_mul(k).normalize(),
BN254Fp2::GENERATOR.normalize()
).mont_rdc();
assert_eq!(left, right)
}
}