@@ -215,31 +215,12 @@ def test_worst_returndatasize_nonzero(
215
215
def test_worst_returndatasize_zero (
216
216
benchmark_test : BenchmarkTestFiller ,
217
217
pre : Alloc ,
218
- fork : Fork ,
219
- gas_benchmark_value : int ,
220
- ) -> None :
218
+ ):
221
219
"""
222
- Test running a block with as many RETURNDATASIZE opcodes as possible with a
223
- zero buffer.
220
+ Test running a block with as many RETURNDATASIZE opcodes as possible with
221
+ a zero buffer.
224
222
"""
225
- max_code_size = fork .max_code_size ()
226
-
227
- dummy_contract_call = Bytecode ()
228
-
229
- code_prefix = dummy_contract_call + Op .JUMPDEST
230
- iter_loop = Op .POP (Op .RETURNDATASIZE )
231
- code_suffix = Op .JUMP (len (code_prefix ) - 1 )
232
- code_iter_len = (max_code_size - len (code_prefix ) - len (code_suffix )) // len (iter_loop )
233
- code = code_prefix + iter_loop * code_iter_len + code_suffix
234
- assert len (code ) <= max_code_size
235
-
236
- tx = Transaction (
237
- to = pre .deploy_contract (code = bytes (code )),
238
- gas_limit = gas_benchmark_value ,
239
- sender = pre .fund_eoa (),
240
- )
241
-
242
- state_test (
223
+ benchmark_test (
243
224
pre = pre ,
244
225
post = {},
245
226
code_generator = ExtCallGenerator (setup = Bytecode (), attack_block = Op .RETURNDATASIZE ),
@@ -288,8 +269,10 @@ def test_worst_keccak(
288
269
gsc = fork .gas_costs ()
289
270
mem_exp_gas_calculator = fork .memory_expansion_gas_calculator ()
290
271
291
- # Discover the optimal input size to maximize keccak-permutations, not keccak calls.
292
- # The complication of the discovery arises from the non-linear gas cost of memory expansion.
272
+ # Discover the optimal input size to maximize keccak-permutations,
273
+ # not to maximize keccak calls.
274
+ # The complication of the discovery arises from
275
+ # the non-linear gas cost of memory expansion.
293
276
max_keccak_perm_per_block = 0
294
277
optimal_input_length = 0
295
278
for i in range (1 , 1_000_000 , 32 ):
@@ -320,9 +303,11 @@ def test_worst_keccak(
320
303
# The loop structure is: JUMPDEST + [attack iteration] + PUSH0 + JUMP
321
304
#
322
305
# Now calculate available gas for [attack iteration]:
323
- # Numerator = max_code_size-3. The -3 is for the JUMPDEST, PUSH0 and JUMP.
324
- # Denominator = (PUSHN + PUSH1 + KECCAK256 + POP) + PUSH1_DATA + PUSHN_DATA
325
- # TODO: the testing framework uses PUSH1(0) instead of PUSH0 which is suboptimal for the
306
+ # Numerator = max_code_size-3. (JUMPDEST, PUSH0 and JUMP)
307
+ # Denominator = (PUSHN + PUSH1 + KECCAK256 + POP) + PUSH1_DATA +
308
+ # PUSHN_DATA
309
+ # TODO: the testing framework uses PUSH1(0) instead of PUSH0 which is
310
+ # suboptimal for the
326
311
# attack, whenever this is fixed adjust accordingly.
327
312
benchmark_test (
328
313
pre = pre ,
@@ -1566,11 +1551,13 @@ def test_worst_tstore(
1566
1551
init_key = 42
1567
1552
setup = Op .PUSH1 (init_key )
1568
1553
1569
- # If `dense_val_mut` is set, we use GAS as a cheap way of always storing a different value than
1554
+ # If `dense_val_mut` is set, we use GAS as a cheap way of always
1555
+ # storing a different value than
1570
1556
# the previous one.
1571
1557
attack_block = Op .TSTORE (Op .DUP2 , Op .GAS if dense_val_mut else Op .DUP1 )
1572
1558
1573
- # If `key_mut` is True, we mutate the key on every iteration of the big loop.
1559
+ # If `key_mut` is True, we mutate the key on every iteration of the
1560
+ # big loop.
1574
1561
cleanup = Op .POP + Op .GAS if key_mut else Bytecode ()
1575
1562
1576
1563
benchmark_test (
@@ -1731,8 +1718,10 @@ def test_worst_mod(
1731
1718
The order of accessing the numerators is selected in a way the mod value
1732
1719
remains in the range as long as possible.
1733
1720
"""
1734
- # For SMOD we negate both numerator and modulus. The underlying computation is the same,
1735
- # just the SMOD implementation will have to additionally handle the sign bits.
1721
+ # For SMOD we negate both numerator and modulus. The underlying
1722
+ # computation is the same,
1723
+ # just the SMOD implementation will have to additionally handle the
1724
+ # sign bits.
1736
1725
# The result stays negative.
1737
1726
should_negate = op == Op .SMOD
1738
1727
@@ -1804,7 +1793,8 @@ def test_worst_mod(
1804
1793
seed += 1
1805
1794
print (f"{ seed = } " )
1806
1795
1807
- # TODO: Don't use fixed PUSH32. Let Bytecode helpers to select optimal push opcode.
1796
+ # TODO: Don't use fixed PUSH32. Let Bytecode helpers to select optimal
1797
+ # push opcode.
1808
1798
setup = sum ((Op .PUSH32 [n ] for n in numerators ), Bytecode ())
1809
1799
attack_block = (
1810
1800
Op .CALLDATALOAD (0 ) + sum (make_dup (len (numerators ) - i ) + op for i in indexes ) + Op .POP
@@ -1835,8 +1825,11 @@ def test_worst_memory_access(
1835
1825
offset : int ,
1836
1826
offset_initialized : bool ,
1837
1827
big_memory_expansion : bool ,
1838
- ) -> None :
1839
- """Test running a block with as many memory access instructions as possible."""
1828
+ ):
1829
+ """
1830
+ Test running a block with as many memory access instructions as
1831
+ possible.
1832
+ """
1840
1833
mem_exp_code = Op .MSTORE8 (10 * 1024 , 1 ) if big_memory_expansion else Bytecode ()
1841
1834
offset_set_code = Op .MSTORE (offset , 43 ) if offset_initialized else Bytecode ()
1842
1835
setup = mem_exp_code + offset_set_code + Op .PUSH1 (42 ) + Op .PUSH1 (offset )
@@ -2295,11 +2288,11 @@ def test_worst_clz_diff_input(
2295
2288
pre : Alloc ,
2296
2289
fork : Fork ,
2297
2290
env : Environment ,
2298
- ) -> None :
2291
+ ):
2299
2292
"""
2300
- Test running a block with as many CLZ with different input as possible.
2293
+ Test running a block with as many CLZ with different input as
2294
+ possible.
2301
2295
"""
2302
- tx_gas_limit = fork .transaction_gas_limit_cap () or env .gas_limit
2303
2296
max_code_size = fork .max_code_size ()
2304
2297
2305
2298
code_prefix = Op .JUMPDEST
0 commit comments