@@ -44,11 +44,17 @@ def precompile_addresses(fork: Fork) -> Iterator[Tuple[Address, bool]]:
44
44
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stPreCompiledContracts/idPrecompsFiller.yml"
45
45
],
46
46
pr = ["https://github.com/ethereum/execution-spec-tests/pull/1120" ],
47
+ coverage_missed_reason = (
48
+ "Original test saves variables to memory, loads from storage, uses calldataload to get "
49
+ "the precompile address to call, uses lt and gt to compare the gas differences, "
50
+ "sends non-zero data and value with the transaction, uses conditional jumps to save "
51
+ "different values to storage."
52
+ ),
47
53
)
48
54
@pytest .mark .valid_from ("Berlin" )
49
55
@pytest .mark .parametrize_by_fork ("address,precompile_exists" , precompile_addresses )
50
56
def test_precompiles (
51
- state_test : StateTestFiller , address : str , precompile_exists : bool , pre : Alloc
57
+ state_test : StateTestFiller , address : Address , precompile_exists : bool , pre : Alloc
52
58
):
53
59
"""
54
60
Tests the behavior of precompiled contracts in the Ethereum state test.
@@ -69,27 +75,40 @@ def test_precompiles(
69
75
"""
70
76
env = Environment ()
71
77
78
+ # Empty account to serve as reference
79
+ empty_account = pre .fund_eoa (amount = 0 )
80
+
81
+ # Memory
82
+ args_offset = 0
83
+ ret_offset = 32
84
+ length = 32
85
+
72
86
account = pre .deploy_contract (
73
- Op .MSTORE (0 , 0 ) # Pre-expand the memory so the gas costs are exactly the same
87
+ Op .MSTORE (args_offset , 0xFF ) # Pre-expand the memory and setup inputs for pre-compiles
88
+ + Op .MSTORE (ret_offset , 0xFF )
89
+ + Op .MSTORE8 (args_offset , 0xFF )
90
+ + Op .MSTORE8 (ret_offset , 0xFF )
91
+ + Op .POP (Op .BALANCE (empty_account )) # Warm the accounts
92
+ + Op .POP (Op .BALANCE (address ))
74
93
+ Op .GAS
75
94
+ Op .CALL (
95
+ gas = 50_000 ,
76
96
address = address ,
77
- value = 0 ,
78
- args_offset = 0 ,
79
- args_size = 32 ,
80
- output_offset = 32 ,
81
- output_size = 32 ,
97
+ args_offset = args_offset ,
98
+ args_size = length ,
99
+ ret_offset = ret_offset ,
100
+ ret_size = length ,
82
101
)
83
102
+ Op .POP
84
103
+ Op .SUB (Op .SWAP1 , Op .GAS )
85
104
+ Op .GAS
86
105
+ Op .CALL (
87
- address = pre . fund_eoa ( amount = 0 ) ,
88
- value = 0 ,
89
- args_offset = 0 ,
90
- args_size = 32 ,
91
- output_offset = 32 ,
92
- output_size = 32 ,
106
+ gas = 50_000 ,
107
+ address = empty_account ,
108
+ args_offset = args_offset ,
109
+ args_size = length ,
110
+ ret_offset = ret_offset ,
111
+ ret_size = length ,
93
112
)
94
113
+ Op .POP
95
114
+ Op .SUB (Op .SWAP1 , Op .GAS )
@@ -109,6 +128,6 @@ def test_precompiles(
109
128
110
129
# A high gas cost will result from calling a precompile
111
130
# Expect 0x00 when a precompile exists at the address, 0x01 otherwise
112
- post = {account : Account (storage = {0 : "0x00" if precompile_exists else "0x01" })}
131
+ post = {account : Account (storage = {0 : 0 if precompile_exists else 1 })}
113
132
114
133
state_test (env = env , pre = pre , post = post , tx = tx )
0 commit comments