Skip to content

Commit b51eba1

Browse files
fix: update linting comment length
1 parent d9705ec commit b51eba1

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

src/ethereum_test_benchmark/benchmark_code_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class JumpLoopGenerator(BenchmarkCodeGenerator):
1717
def deploy_contracts(self, pre: Alloc, fork: Fork) -> Address:
1818
"""Deploy the looping contract."""
1919
# Benchmark Test Structure:
20-
# setup + JUMPDEST + attack + attack + ... + cleanup + JUMP(setup_length)
20+
# setup + JUMPDEST +
21+
# attack + attack + ... + attack +
22+
# cleanup + JUMP(setup_length)
2123
code = self.generate_repeated_code(self.attack_block, self.setup, self.cleanup, fork)
2224
self._contract_address = pre.deploy_contract(code=code)
2325
return self._contract_address

tests/benchmark/test_worst_blocks.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def calldata_generator(
205205
# Token accounting:
206206
# tokens_in_calldata = zero_bytes + 4 * non_zero_bytes
207207
#
208-
# So we calculate how many bytes we can fit into calldata based on available gas.
208+
# So we calculate how many bytes we can fit into calldata based on
209+
# available gas.
209210
max_tokens_in_calldata = gas_amount // total_cost_floor_per_token
210211
num_of_bytes = max_tokens_in_calldata if zero_byte else max_tokens_in_calldata // 4
211212
byte_data = b"\x00" if zero_byte else b"\xff"
@@ -268,7 +269,10 @@ def test_block_full_access_list_and_data(
268269
gas_benchmark_value: int,
269270
tx_gas_limit_cap: int,
270271
):
271-
"""Test a block with access lists (60% gas) and calldata (40% gas) using random mixed bytes."""
272+
"""
273+
Test a block with access lists (60% gas) and calldata (40% gas) using
274+
random mixed bytes.
275+
"""
272276
iteration_count = math.ceil(gas_benchmark_value / tx_gas_limit_cap)
273277

274278
gas_remaining = gas_benchmark_value
@@ -305,8 +309,10 @@ def test_block_full_access_list_and_data(
305309
)
306310
]
307311

308-
# Calculate calldata with 29% of gas for zero bytes and 71% for non-zero bytes
309-
# Token accounting: tokens_in_calldata = zero_bytes + 4 * non_zero_bytes
312+
# Calculate calldata with 29% of gas for zero bytes and 71% for
313+
# non-zero bytes
314+
# Token accounting: tokens_in_calldata = zero_bytes + 4 *
315+
# non_zero_bytes
310316
# We want to split the gas budget:
311317
# - 29% of gas_for_calldata for zero bytes
312318
# - 71% of gas_for_calldata for non-zero bytes

tests/benchmark/test_worst_compute.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ def test_worst_returndatasize_zero(
212212
benchmark_test: BenchmarkTestFiller,
213213
pre: Alloc,
214214
):
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+
"""
216219
benchmark_test(
217220
pre=pre,
218221
post={},
@@ -262,8 +265,10 @@ def test_worst_keccak(
262265
gsc = fork.gas_costs()
263266
mem_exp_gas_calculator = fork.memory_expansion_gas_calculator()
264267

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.
267272
max_keccak_perm_per_block = 0
268273
optimal_input_length = 0
269274
for i in range(1, 1_000_000, 32):
@@ -294,9 +299,11 @@ def test_worst_keccak(
294299
# The loop structure is: JUMPDEST + [attack iteration] + PUSH0 + JUMP
295300
#
296301
# 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
300307
# attack, whenever this is fixed adjust accordingly.
301308
benchmark_test(
302309
pre=pre,
@@ -1542,11 +1549,13 @@ def test_worst_tstore(
15421549
init_key = 42
15431550
setup = Op.PUSH1(init_key)
15441551

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
15461554
# the previous one.
15471555
attack_block = Op.TSTORE(Op.DUP2, Op.GAS if dense_val_mut else Op.DUP1)
15481556

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.
15501559
cleanup = Op.POP + Op.GAS if key_mut else Bytecode()
15511560

15521561
benchmark_test(
@@ -1707,8 +1716,10 @@ def test_worst_mod(
17071716
The order of accessing the numerators is selected in a way the mod value
17081717
remains in the range as long as possible.
17091718
"""
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.
17121723
# The result stays negative.
17131724
should_negate = op == Op.SMOD
17141725

@@ -1780,7 +1791,8 @@ def test_worst_mod(
17801791
seed += 1
17811792
print(f"{seed=}")
17821793

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.
17841796
setup = sum((Op.PUSH32[n] for n in numerators), Bytecode())
17851797
attack_block = (
17861798
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(
18121824
offset_initialized: bool,
18131825
big_memory_expansion: bool,
18141826
):
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+
"""
18161831
mem_exp_code = Op.MSTORE8(10 * 1024, 1) if big_memory_expansion else Bytecode()
18171832
offset_set_code = Op.MSTORE(offset, 43) if offset_initialized else Bytecode()
18181833
setup = mem_exp_code + offset_set_code + Op.PUSH1(42) + Op.PUSH1(offset)
@@ -2273,7 +2288,10 @@ def test_worst_clz_diff_input(
22732288
gas_benchmark_value: int,
22742289
env: Environment,
22752290
):
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+
"""
22772295
max_code_size = fork.max_code_size()
22782296

22792297
code_prefix = Op.JUMPDEST

tests/benchmark/test_worst_memory.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ def test_worst_calldatacopy(
8282
if min_gas > gas_benchmark_value:
8383
pytest.skip("Minimum gas required for calldata ({min_gas}) is greater than the gas limit")
8484

85-
# We create the contract that will be doing the CALLDATACOPY multiple times.
85+
# We create the contract that will be doing the CALLDATACOPY multiple
86+
# times.
8687
#
87-
# If `non_zero_data` is True, we leverage CALLDATASIZE for the copy length. Otherwise, since we
88-
# don't send zero data explicitly via calldata, PUSH the target size and use DUP1 to copy it.
88+
# If `non_zero_data` is True, we leverage CALLDATASIZE for the copy
89+
# length. Otherwise, since we
90+
# don't send zero data explicitly via calldata, PUSH the target size and
91+
# use DUP1 to copy it.
8992
setup = Bytecode() if non_zero_data or size == 0 else Op.PUSH3(size)
9093
src_dst = 0 if fixed_src_dst else Op.MOD(Op.GAS, 7)
9194
attack_block = Op.CALLDATACOPY(
@@ -101,8 +104,8 @@ def test_worst_calldatacopy(
101104
# If the origin is CALL, we need to create a contract that will call the
102105
# target contract with the calldata.
103106
if origin == CallDataOrigin.CALL:
104-
# If `non_zero_data` is False we leverage just using zeroed memory. Otherwise, we
105-
# copy the calldata received from the transaction.
107+
# If `non_zero_data` is False we leverage just using zeroed memory.
108+
# Otherwise, we copy the calldata received from the transaction.
106109
setup = (
107110
Op.CALLDATACOPY(Op.PUSH0, Op.PUSH0, Op.CALLDATASIZE) if non_zero_data else Bytecode()
108111
) + Op.JUMPDEST
@@ -166,8 +169,10 @@ def test_worst_codecopy(
166169
attack_block, Bytecode(), Bytecode(), fork
167170
)
168171

169-
# The code generated above is not guaranteed to be of max_code_size, so we pad it since
170-
# a test parameter targets CODECOPYing a contract with max code size. Padded bytecode values
172+
# The code generated above is not guaranteed to be of max_code_size, so
173+
# we pad it since
174+
# a test parameter targets CODECOPYing a contract with max code size.
175+
# Padded bytecode values
171176
# are not relevant.
172177
code += Op.INVALID * (max_code_size - len(code))
173178
assert len(code) == max_code_size, (
@@ -209,8 +214,10 @@ def test_worst_returndatacopy(
209214
fixed_dst: bool,
210215
):
211216
"""Test running a block filled with RETURNDATACOPY executions."""
212-
# Create the contract that will RETURN the data that will be used for RETURNDATACOPY.
213-
# Random-ish data is injected at different points in memory to avoid making the content
217+
# Create the contract that will RETURN the data that will be used for
218+
# RETURNDATACOPY.
219+
# Random-ish data is injected at different points in memory to avoid
220+
# making the content
214221
# predictable. If `size` is 0, this helper contract won't be used.
215222
code = (
216223
Op.MSTORE8(0, Op.GAS)
@@ -223,7 +230,8 @@ def test_worst_returndatacopy(
223230
returndata_gen = Op.STATICCALL(address=helper_contract) if size > 0 else Bytecode()
224231
dst = 0 if fixed_dst else Op.MOD(Op.GAS, 7)
225232

226-
# We create the contract that will be doing the RETURNDATACOPY multiple times.
233+
# We create the contract that will be doing the RETURNDATACOPY multiple
234+
# times.
227235
returndata_gen = Op.STATICCALL(address=helper_contract) if size > 0 else Bytecode()
228236
attack_block = Op.RETURNDATACOPY(dst, Op.PUSH0, Op.RETURNDATASIZE)
229237

@@ -236,7 +244,8 @@ def test_worst_returndatacopy(
236244
# STATICCALL(address=helper_contract)
237245
# JUMP(#)
238246
# ```
239-
# The goal is that once per (big) loop iteration, the helper contract is called to
247+
# The goal is that once per (big) loop iteration, the helper contract is
248+
# called to
240249
# generate fresh returndata to continue calling RETURNDATACOPY.
241250

242251
benchmark_test(

tests/benchmark/test_worst_stateful_opcodes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def test_worst_address_state_warm(
140140
opcode: Op,
141141
absent_target: bool,
142142
):
143-
"""Test running a block with as many stateful opcodes doing warm access for an account."""
143+
"""
144+
Test running a block with as many stateful opcodes doing warm access
145+
for an account.
146+
"""
144147
# Setup
145148
target_addr = Address(100_000)
146149
post = {}
@@ -374,7 +377,10 @@ def test_worst_storage_access_warm(
374377
gas_benchmark_value: int,
375378
env: Environment,
376379
):
377-
"""Test running a block with as many warm storage slot accesses as possible."""
380+
"""
381+
Test running a block with as many warm storage slot accesses as
382+
possible.
383+
"""
378384
blocks = []
379385

380386
# The target storage slot for the warm access is storage slot 0.

0 commit comments

Comments
 (0)