openvm_pairing_guest/bls12_381/
mod.rs

1use hex_literal::hex;
2#[cfg(not(target_os = "zkvm"))]
3use lazy_static::lazy_static;
4#[cfg(not(target_os = "zkvm"))]
5use num_bigint::BigUint;
6
7#[cfg(all(test, feature = "halo2curves", not(target_os = "zkvm")))]
8mod tests;
9
10#[cfg(not(target_os = "zkvm"))]
11lazy_static! {
12    pub static ref BLS12_381_MODULUS: BigUint = BigUint::from_bytes_be(&hex!(
13        "1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"
14    ));
15    pub static ref BLS12_381_ORDER: BigUint = BigUint::from_bytes_be(&hex!(
16        "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
17    ));
18}
19
20pub const BLS12_381_XI_ISIZE: [isize; 2] = [1, 1];
21pub const BLS12_381_NUM_LIMBS: usize = 48;
22pub const BLS12_381_LIMB_BITS: usize = 8;
23pub const BLS12_381_BLOCK_SIZE: usize = 16;
24
25pub const BLS12_381_SEED_ABS: u64 = 0xd201000000010000;
26// Encodes the Bls12_381 seed, x.
27// x = sum_i BLS12_381_PSEUDO_BINARY_ENCODING[i] * 2^i
28// where BLS12_381_PSEUDO_BINARY_ENCODING[i] is in {-1, 0, 1}
29// Validated against BLS12_381_SEED_ABS by a test in tests.rs
30pub const BLS12_381_PSEUDO_BINARY_ENCODING: [i8; 64] = [
31    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1,
33];
34
35#[cfg(not(target_os = "zkvm"))]
36// Used in WeierstrassExtension config
37pub const BLS12_381_ECC_STRUCT_NAME: &str = "Bls12_381G1Affine";
38
39#[cfg(not(target_os = "zkvm"))]
40// Used in Fp2Extension config
41pub const BLS12_381_COMPLEX_STRUCT_NAME: &str = "Bls12_381Fp2";