openvm_pairing_guest/halo2curves_shims/bn254/
test_utils.rs1use core::mem::transmute;
2
3use halo2curves_axiom::{
4 bn256::{Fq12, Gt},
5 pairing::MillerLoopResult,
6};
7use hex_literal::hex;
8use lazy_static::lazy_static;
9use num_bigint::BigUint;
10use num_traits::Pow;
11use openvm_algebra_guest::ExpBytes;
12
13lazy_static! {
14 pub static ref BN254_MODULUS: BigUint = BigUint::from_bytes_be(&hex!(
15 "30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"
16 ));
17 pub static ref BN254_ORDER: BigUint = BigUint::from_bytes_be(&hex!(
18 "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"
19 ));
20}
21
22pub fn final_exp(f: Fq12) -> Fq12 {
24 let p = BN254_MODULUS.clone();
25 let r = BN254_ORDER.clone();
26 let exp: BigUint = (p.pow(12u32) - BigUint::from(1u32)) / r;
27 ExpBytes::exp_bytes(&f, true, &exp.to_bytes_be())
28}
29
30pub fn assert_miller_results_eq(a: Gt, b: Fq12) {
32 let a = a.final_exponentiation();
33 let b = final_exp(b);
34 assert_eq!(unsafe { transmute::<Gt, Fq12>(a) }, b);
35}