@@ -212,7 +212,10 @@ def test_worst_returndatasize_zero(
212
212
benchmark_test : BenchmarkTestFiller ,
213
213
pre : Alloc ,
214
214
):
215
- """Test running a block with as many RETURNDATASIZE opcodes as possible with a zero buffer."""
215
+ """
216
+ Test running a block with as many RETURNDATASIZE opcodes as possible with
217
+ a zero buffer.
218
+ """
216
219
benchmark_test (
217
220
pre = pre ,
218
221
post = {},
@@ -262,8 +265,10 @@ def test_worst_keccak(
262
265
gsc = fork .gas_costs ()
263
266
mem_exp_gas_calculator = fork .memory_expansion_gas_calculator ()
264
267
265
- # Discover the optimal input size to maximize keccak-permutations, not keccak calls.
266
- # The complication of the discovery arises from the non-linear gas cost of memory expansion.
268
+ # Discover the optimal input size to maximize keccak-permutations,
269
+ # not to maximize keccak calls.
270
+ # The complication of the discovery arises from
271
+ # the non-linear gas cost of memory expansion.
267
272
max_keccak_perm_per_block = 0
268
273
optimal_input_length = 0
269
274
for i in range (1 , 1_000_000 , 32 ):
@@ -294,9 +299,11 @@ def test_worst_keccak(
294
299
# The loop structure is: JUMPDEST + [attack iteration] + PUSH0 + JUMP
295
300
#
296
301
# Now calculate available gas for [attack iteration]:
297
- # Numerator = max_code_size-3. The -3 is for the JUMPDEST, PUSH0 and JUMP.
298
- # Denominator = (PUSHN + PUSH1 + KECCAK256 + POP) + PUSH1_DATA + PUSHN_DATA
299
- # TODO: the testing framework uses PUSH1(0) instead of PUSH0 which is suboptimal for the
302
+ # Numerator = max_code_size-3. (JUMPDEST, PUSH0 and JUMP)
303
+ # Denominator = (PUSHN + PUSH1 + KECCAK256 + POP) + PUSH1_DATA +
304
+ # PUSHN_DATA
305
+ # TODO: the testing framework uses PUSH1(0) instead of PUSH0 which is
306
+ # suboptimal for the
300
307
# attack, whenever this is fixed adjust accordingly.
301
308
benchmark_test (
302
309
pre = pre ,
@@ -1542,11 +1549,13 @@ def test_worst_tstore(
1542
1549
init_key = 42
1543
1550
setup = Op .PUSH1 (init_key )
1544
1551
1545
- # If `dense_val_mut` is set, we use GAS as a cheap way of always storing a different value than
1552
+ # If `dense_val_mut` is set, we use GAS as a cheap way of always
1553
+ # storing a different value than
1546
1554
# the previous one.
1547
1555
attack_block = Op .TSTORE (Op .DUP2 , Op .GAS if dense_val_mut else Op .DUP1 )
1548
1556
1549
- # If `key_mut` is True, we mutate the key on every iteration of the big loop.
1557
+ # If `key_mut` is True, we mutate the key on every iteration of the
1558
+ # big loop.
1550
1559
cleanup = Op .POP + Op .GAS if key_mut else Bytecode ()
1551
1560
1552
1561
benchmark_test (
@@ -1707,8 +1716,10 @@ def test_worst_mod(
1707
1716
The order of accessing the numerators is selected in a way the mod value
1708
1717
remains in the range as long as possible.
1709
1718
"""
1710
- # For SMOD we negate both numerator and modulus. The underlying computation is the same,
1711
- # just the SMOD implementation will have to additionally handle the sign bits.
1719
+ # For SMOD we negate both numerator and modulus. The underlying
1720
+ # computation is the same,
1721
+ # just the SMOD implementation will have to additionally handle the
1722
+ # sign bits.
1712
1723
# The result stays negative.
1713
1724
should_negate = op == Op .SMOD
1714
1725
@@ -1780,7 +1791,8 @@ def test_worst_mod(
1780
1791
seed += 1
1781
1792
print (f"{ seed = } " )
1782
1793
1783
- # TODO: Don't use fixed PUSH32. Let Bytecode helpers to select optimal push opcode.
1794
+ # TODO: Don't use fixed PUSH32. Let Bytecode helpers to select optimal
1795
+ # push opcode.
1784
1796
setup = sum ((Op .PUSH32 [n ] for n in numerators ), Bytecode ())
1785
1797
attack_block = (
1786
1798
Op .CALLDATALOAD (0 ) + sum (make_dup (len (numerators ) - i ) + op for i in indexes ) + Op .POP
@@ -1812,7 +1824,10 @@ def test_worst_memory_access(
1812
1824
offset_initialized : bool ,
1813
1825
big_memory_expansion : bool ,
1814
1826
):
1815
- """Test running a block with as many memory access instructions as possible."""
1827
+ """
1828
+ Test running a block with as many memory access instructions as
1829
+ possible.
1830
+ """
1816
1831
mem_exp_code = Op .MSTORE8 (10 * 1024 , 1 ) if big_memory_expansion else Bytecode ()
1817
1832
offset_set_code = Op .MSTORE (offset , 43 ) if offset_initialized else Bytecode ()
1818
1833
setup = mem_exp_code + offset_set_code + Op .PUSH1 (42 ) + Op .PUSH1 (offset )
@@ -2273,7 +2288,10 @@ def test_worst_clz_diff_input(
2273
2288
gas_benchmark_value : int ,
2274
2289
env : Environment ,
2275
2290
):
2276
- """Test running a block with as many CLZ with different input as possible."""
2291
+ """
2292
+ Test running a block with as many CLZ with different input as
2293
+ possible.
2294
+ """
2277
2295
max_code_size = fork .max_code_size ()
2278
2296
2279
2297
code_prefix = Op .JUMPDEST
0 commit comments