1
1
use revm:: precompile:: {
2
- bn128:: { ADD_INPUT_LEN , MUL_INPUT_LEN , PAIR_ELEMENT_LEN } ,
2
+ bn128:: { self , ADD_INPUT_LEN , MUL_INPUT_LEN , PAIR_ELEMENT_LEN } ,
3
3
utilities:: { bool_to_bytes32, right_pad} ,
4
4
PrecompileError , PrecompileOutput , PrecompileResult , PrecompileWithAddress ,
5
5
} ;
@@ -32,7 +32,7 @@ cfg_if::cfg_if! {
32
32
pub mod add {
33
33
use super :: * ;
34
34
35
- pub use revm :: precompile :: bn128:: add:: { ADDRESS , ISTANBUL_ADD_GAS_COST } ;
35
+ pub use bn128:: add:: { ADDRESS , ISTANBUL_ADD_GAS_COST } ;
36
36
37
37
/// Bn128 add precompile with ISTANBUL gas rules
38
38
pub const ISTANBUL : PrecompileWithAddress =
@@ -45,7 +45,7 @@ pub mod add {
45
45
pub mod mul {
46
46
use super :: * ;
47
47
48
- pub use revm :: precompile :: bn128:: mul:: { ADDRESS , ISTANBUL_MUL_GAS_COST } ;
48
+ pub use bn128:: mul:: { ADDRESS , ISTANBUL_MUL_GAS_COST } ;
49
49
50
50
/// Bn128 mul precompile with ISTANBUL gas rules
51
51
pub const ISTANBUL : PrecompileWithAddress =
@@ -57,42 +57,30 @@ pub mod mul {
57
57
pub mod pair {
58
58
use super :: * ;
59
59
60
- pub use revm:: precompile:: bn128:: pair:: { ADDRESS , ISTANBUL_PAIR_BASE , ISTANBUL_PAIR_PER_POINT } ;
61
-
62
- // CONSTANTS
63
- // --------------------------------------------------------------------------------------------
60
+ pub use bn128:: pair:: { ADDRESS , ISTANBUL_PAIR_BASE , ISTANBUL_PAIR_PER_POINT } ;
64
61
65
62
/// The number of pairing inputs per pairing operation. If the inputs provided to the precompile
66
63
/// call are < 4, we append (G1::infinity, G2::generator) until we have the required no. of
67
64
/// inputs.
68
- const N_PAIRING_PER_OP : usize = 4 ;
69
-
70
- /// The number of bytes taken to represent a pair (G1, G2).
71
- const N_BYTES_PER_PAIR : usize = 192 ;
72
-
73
- // BN128 PAIRING PRECOMPILE
74
- // --------------------------------------------------------------------------------------------
65
+ const BERNOULLI_LEN_LIMIT : usize = 4 ;
75
66
76
- /// The BN128 PAIRING precompile with address .
67
+ /// The Bn128 pair precompile with BERNOULLI input rules .
77
68
pub const BERNOULLI : PrecompileWithAddress = PrecompileWithAddress ( ADDRESS , bernoulli_run) ;
78
69
79
- /// The bernoulli BN128 PAIRING precompile implementation.
70
+ /// The bernoulli Bn128 pair precompile implementation.
80
71
///
81
72
/// # Errors
82
73
/// - `PrecompileError::Other("BN128PairingInputOverflow: input overflow".into())` if the input
83
74
/// length is greater than 768 bytes.
84
75
fn bernoulli_run ( input : & [ u8 ] , gas_limit : u64 ) -> PrecompileResult {
85
- if input. len ( ) > N_PAIRING_PER_OP * N_BYTES_PER_PAIR {
76
+ if input. len ( ) > BERNOULLI_LEN_LIMIT * PAIR_ELEMENT_LEN {
86
77
return Err ( PrecompileError :: Other ( "BN128PairingInputOverflow: input overflow" . into ( ) ) ) ;
87
78
}
88
79
run_pair ( input, ISTANBUL_PAIR_PER_POINT , ISTANBUL_PAIR_BASE , gas_limit)
89
80
}
90
81
91
- /// The BN128 PAIRING precompile with address.
92
- pub const FEYNMAN : PrecompileWithAddress =
93
- PrecompileWithAddress ( ADDRESS , |input, gas_limit| {
94
- run_pair ( input, ISTANBUL_PAIR_PER_POINT , ISTANBUL_PAIR_BASE , gas_limit)
95
- } ) ;
82
+ /// The Bn128 pair precompile in FEYNMAN hardfork.
83
+ pub const FEYNMAN : PrecompileWithAddress = bn128:: pair:: ISTANBUL ;
96
84
}
97
85
98
86
// Copied from https://github.com/bluealloy/revm/blob/v75/crates/precompile/src/bn128.rs Under MIT License
0 commit comments