revm_precompile/
bls12_381.rs

1//! BLS12-381 precompiles added in [`EIP-2537`](https://eips.ethereum.org/EIPS/eip-2537)
2//! For more details check modules for each precompile.
3use crate::Precompile;
4
5#[allow(dead_code)]
6pub(crate) mod arkworks;
7
8cfg_if::cfg_if! {
9    if #[cfg(feature = "blst")]{
10        pub(crate) mod blst;
11        pub(crate) use blst as crypto_backend;
12    } else {
13        pub(crate) use arkworks as crypto_backend;
14    }
15}
16
17// Re-export type aliases for use in submodules
18use crate::bls12_381_const::{FP_LENGTH, SCALAR_LENGTH};
19/// G1 point represented as two field elements (x, y coordinates)
20pub type G1Point = ([u8; FP_LENGTH], [u8; FP_LENGTH]);
21/// G2 point represented as four field elements (x0, x1, y0, y1 coordinates)
22pub type G2Point = (
23    [u8; FP_LENGTH],
24    [u8; FP_LENGTH],
25    [u8; FP_LENGTH],
26    [u8; FP_LENGTH],
27);
28/// G1 point and scalar pair for MSM operations
29pub type G1PointScalar = (G1Point, [u8; SCALAR_LENGTH]);
30/// G2 point and scalar pair for MSM operations
31pub type G2PointScalar = (G2Point, [u8; SCALAR_LENGTH]);
32type PairingPair = (G1Point, G2Point);
33
34pub mod g1_add;
35pub mod g1_msm;
36pub mod g2_add;
37pub mod g2_msm;
38pub mod map_fp2_to_g2;
39pub mod map_fp_to_g1;
40pub mod pairing;
41mod utils;
42
43/// Returns the BLS12-381 precompiles with their addresses.
44pub fn precompiles() -> impl Iterator<Item = Precompile> {
45    [
46        g1_add::PRECOMPILE,
47        g1_msm::PRECOMPILE,
48        g2_add::PRECOMPILE,
49        g2_msm::PRECOMPILE,
50        pairing::PRECOMPILE,
51        map_fp_to_g1::PRECOMPILE,
52        map_fp2_to_g2::PRECOMPILE,
53    ]
54    .into_iter()
55}