@@ -2,6 +2,7 @@ use pallet_evm::{Precompile, PrecompileHandle, PrecompileResult, PrecompileSet};
2
2
use sp_core:: H160 ;
3
3
use sp_std:: marker:: PhantomData ;
4
4
5
+ use pallet_evm:: Precompiles ;
5
6
use pallet_evm_precompile_modexp:: Modexp ;
6
7
use pallet_evm_precompile_sha3fips:: Sha3FIPS256 ;
7
8
use pallet_evm_precompile_simple:: { ECRecover , ECRecoverPublicKey , Identity , Ripemd160 , Sha256 } ;
15
16
pub fn new ( ) -> Self {
16
17
Self ( Default :: default ( ) )
17
18
}
18
- pub fn used_addresses ( ) -> [ H160 ; 7 ] {
19
- [
20
- hash ( 1 ) ,
21
- hash ( 2 ) ,
22
- hash ( 3 ) ,
23
- hash ( 4 ) ,
24
- hash ( 5 ) ,
25
- hash ( 1024 ) ,
26
- hash ( 1025 ) ,
27
- ]
28
- }
29
19
}
30
20
impl < R > PrecompileSet for FrontierPrecompiles < R >
31
21
where
@@ -34,23 +24,42 @@ where
34
24
fn execute ( & self , handle : & mut impl PrecompileHandle ) -> Option < PrecompileResult > {
35
25
match handle. code_address ( ) {
36
26
// Ethereum precompiles :
37
- a if a == hash ( 1 ) => Some ( ECRecover :: execute ( handle) ) ,
38
- a if a == hash ( 2 ) => Some ( Sha256 :: execute ( handle) ) ,
39
- a if a == hash ( 3 ) => Some ( Ripemd160 :: execute ( handle) ) ,
40
- a if a == hash ( 4 ) => Some ( Identity :: execute ( handle) ) ,
41
- a if a == hash ( 5 ) => Some ( Modexp :: execute ( handle) ) ,
27
+ a if Precompiles :: < R > :: contains_key ( b"ECRecover" . to_vec ( ) , a) => {
28
+ Some ( ECRecover :: execute ( handle) )
29
+ }
30
+ a if Precompiles :: < R > :: contains_key ( b"Sha256" . to_vec ( ) , a) => {
31
+ Some ( Sha256 :: execute ( handle) )
32
+ }
33
+ a if Precompiles :: < R > :: contains_key ( b"Ripemd160" . to_vec ( ) , a) => {
34
+ Some ( Ripemd160 :: execute ( handle) )
35
+ }
36
+ a if Precompiles :: < R > :: contains_key ( b"Identity" . to_vec ( ) , a) => {
37
+ Some ( Identity :: execute ( handle) )
38
+ }
39
+ a if Precompiles :: < R > :: contains_key ( b"Modexp" . to_vec ( ) , a) => {
40
+ Some ( Modexp :: execute ( handle) )
41
+ }
42
42
// Non-Frontier specific nor Ethereum precompiles :
43
- a if a == hash ( 1024 ) => Some ( Sha3FIPS256 :: execute ( handle) ) ,
44
- a if a == hash ( 1025 ) => Some ( ECRecoverPublicKey :: execute ( handle) ) ,
43
+ a if Precompiles :: < R > :: contains_key ( b"Sha3FIPS256" . to_vec ( ) , a) => {
44
+ Some ( Sha3FIPS256 :: execute ( handle) )
45
+ }
46
+ a if Precompiles :: < R > :: contains_key ( b"ECRecoverPublicKey" . to_vec ( ) , a) => {
47
+ Some ( ECRecoverPublicKey :: execute ( handle) )
48
+ }
45
49
_ => None ,
46
50
}
47
51
}
48
52
49
53
fn is_precompile ( & self , address : H160 ) -> bool {
50
- Self :: used_addresses ( ) . contains ( & address)
54
+ match address {
55
+ a if Precompiles :: < R > :: contains_key ( b"ECRecover" . to_vec ( ) , a) => true ,
56
+ a if Precompiles :: < R > :: contains_key ( b"Sha256" . to_vec ( ) , a) => true ,
57
+ a if Precompiles :: < R > :: contains_key ( b"Ripemd160" . to_vec ( ) , a) => true ,
58
+ a if Precompiles :: < R > :: contains_key ( b"Identity" . to_vec ( ) , a) => true ,
59
+ a if Precompiles :: < R > :: contains_key ( b"Modexp" . to_vec ( ) , a) => true ,
60
+ a if Precompiles :: < R > :: contains_key ( b"Sha3FIPS256" . to_vec ( ) , a) => true ,
61
+ a if Precompiles :: < R > :: contains_key ( b"ECRecoverPublicKey" . to_vec ( ) , a) => true ,
62
+ _ => false ,
63
+ }
51
64
}
52
65
}
53
-
54
- fn hash ( a : u64 ) -> H160 {
55
- H160 :: from_low_u64_be ( a)
56
- }
0 commit comments