@@ -19,6 +19,9 @@ use revm::{
19
19
primitives:: PrecompileOutput ,
20
20
} ;
21
21
22
+ /// The max pairing size for BLS12-381 input given a 20M gas limit.
23
+ const BLS12_MAX_PAIRING_SIZE_ISTHMUS : usize = 235_008 ;
24
+
22
25
/// The address of the BLS12-381 pairing check precompile.
23
26
const BLS12_PAIRING_CHECK : Address = address ! ( "0x000000000000000000000000000000000000000f" ) ;
24
27
@@ -32,8 +35,8 @@ const PAIRING_MULTIPLIER_BASE: u64 = 32600;
32
35
const PAIRING_OFFSET_BASE : u64 = 37700 ;
33
36
34
37
/// The address of the BLS12-381 pairing precompile.
35
- pub ( crate ) const FPVM_BLS12_PAIRING : PrecompileWithAddress =
36
- PrecompileWithAddress ( BLS12_PAIRING_CHECK , Precompile :: Standard ( fpvm_bls12_pairing ) ) ;
38
+ pub ( crate ) const FPVM_BLS12_PAIRING_ISTHMUS : PrecompileWithAddress =
39
+ PrecompileWithAddress ( BLS12_PAIRING_CHECK , Precompile :: Standard ( fpvm_bls12_pairing_isthmus ) ) ;
37
40
38
41
/// Performs an FPVM-accelerated BLS12-381 pairing check.
39
42
fn fpvm_bls12_pairing ( input : & Bytes , gas_limit : u64 ) -> PrecompileResult {
@@ -91,11 +94,33 @@ fn fpvm_bls12_pairing(input: &Bytes, gas_limit: u64) -> PrecompileResult {
91
94
Ok ( PrecompileOutput :: new ( required_gas, result_data. into ( ) ) )
92
95
}
93
96
97
+ /// Performs an FPVM-accelerated `bls12` pairing check precompile call
98
+ /// after the Isthmus Hardfork.
99
+ fn fpvm_bls12_pairing_isthmus ( input : & Bytes , gas_limit : u64 ) -> PrecompileResult {
100
+ if input. len ( ) > BLS12_MAX_PAIRING_SIZE_ISTHMUS {
101
+ return Err ( PrecompileError :: Other ( alloc:: format!(
102
+ "Pairing input length must be at most {}" ,
103
+ BLS12_MAX_PAIRING_SIZE_ISTHMUS
104
+ ) )
105
+ . into ( ) ) ;
106
+ }
107
+
108
+ fpvm_bls12_pairing ( input, gas_limit)
109
+ }
110
+
94
111
#[ cfg( test) ]
95
112
mod tests {
96
113
use super :: * ;
97
114
use alloc:: vec;
98
115
116
+ #[ test]
117
+ fn test_fpvm_bls12_pairing_isthmus_max_bytes ( ) {
118
+ let input = Bytes :: from ( vec ! [ 0u8 ; BLS12_MAX_PAIRING_SIZE_ISTHMUS + 1 ] ) ;
119
+ let gas_limit = PAIRING_MULTIPLIER_BASE ;
120
+ let err = PrecompileError :: Other ( "Pairing input length must be at most 235008" . to_string ( ) ) ;
121
+ assert_eq ! ( fpvm_bls12_pairing_isthmus( & input, gas_limit) , Err ( err. into( ) ) ) ;
122
+ }
123
+
99
124
#[ test]
100
125
fn test_fpvm_bls12_offset ( ) {
101
126
let input = Bytes :: from ( vec ! [ 0u8 ; INPUT_LENGTH + 1 ] ) ;
0 commit comments