@@ -38,6 +38,7 @@ def gas_test(
3838 subject_address : Address | None = None ,
3939 subject_balance : int = 0 ,
4040 oog_difference : int = 1 ,
41+ out_of_gas_testing : bool = True ,
4142):
4243 """
4344 Creates a State Test to check the gas cost of a sequence of EOF code.
@@ -104,27 +105,33 @@ def gas_test(
104105 + (Op .DUP3 + Op .SWAP1 + Op .SUB + Op .PUSH2 (slot_warm_gas ) + Op .SSTORE )
105106 # store cold gas: DUP2 is the gas of the baseline gas run
106107 + (Op .DUP2 + Op .SWAP1 + Op .SUB + Op .PUSH2 (slot_cold_gas ) + Op .SSTORE )
107- # oog gas run:
108- # - DUP7 is the gas of the baseline gas run, after other CALL args were pushed
109- # - subtract the gas charged by the harness
110- # - add warm gas charged by the subject
111- # - subtract `oog_difference` to cause OOG exception (1 by default)
112- + Op .SSTORE (
113- slot_oog_call_result ,
114- Op .CALL (
115- gas = Op .ADD (warm_gas - gas_single_gas_run - oog_difference , Op .DUP7 ),
116- address = address_subject ,
117- ),
118- )
119- # sanity gas run: not subtracting 1 to see if enough gas makes the call succeed
120- + Op .SSTORE (
121- slot_sanity_call_result ,
122- Op .CALL (
123- gas = Op .ADD (warm_gas - gas_single_gas_run , Op .DUP7 ),
124- address = address_subject ,
125- ),
108+ + (
109+ (
110+ # do an oog gas run, unless skipped with `out_of_gas_testing=False`:
111+ # - DUP7 is the gas of the baseline gas run, after other CALL args were pushed
112+ # - subtract the gas charged by the harness
113+ # - add warm gas charged by the subject
114+ # - subtract `oog_difference` to cause OOG exception (1 by default)
115+ Op .SSTORE (
116+ slot_oog_call_result ,
117+ Op .CALL (
118+ gas = Op .ADD (warm_gas - gas_single_gas_run - oog_difference , Op .DUP7 ),
119+ address = address_subject ,
120+ ),
121+ )
122+ # sanity gas run: not subtracting 1 to see if enough gas makes the call succeed
123+ + Op .SSTORE (
124+ slot_sanity_call_result ,
125+ Op .CALL (
126+ gas = Op .ADD (warm_gas - gas_single_gas_run , Op .DUP7 ),
127+ address = address_subject ,
128+ ),
129+ )
130+ + Op .STOP
131+ )
132+ if out_of_gas_testing
133+ else Op .STOP
126134 )
127- + Op .STOP
128135 ),
129136 evm_code_type = EVMCodeType .LEGACY , # Needs to be legacy to use GAS opcode
130137 )
@@ -134,12 +141,14 @@ def gas_test(
134141 storage = {
135142 slot_warm_gas : warm_gas ,
136143 slot_cold_gas : cold_gas ,
137- slot_oog_call_result : LEGACY_CALL_FAILURE ,
138- slot_sanity_call_result : LEGACY_CALL_SUCCESS ,
139144 },
140145 ),
141146 }
142147
148+ if out_of_gas_testing :
149+ post [address_legacy_harness ].storage [slot_oog_call_result ] = LEGACY_CALL_FAILURE
150+ post [address_legacy_harness ].storage [slot_sanity_call_result ] = LEGACY_CALL_SUCCESS
151+
143152 tx = Transaction (to = address_legacy_harness , gas_limit = env .gas_limit , sender = sender )
144153
145154 state_test (env = env , pre = pre , tx = tx , post = post )
0 commit comments