Skip to content

Commit 41f0caa

Browse files
fix: update linting comment length
1 parent bb20897 commit 41f0caa

File tree

5 files changed

+72
-56
lines changed

5 files changed

+72
-56
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
@@ -209,7 +209,8 @@ def calldata_generator(
209209
# Token accounting:
210210
# tokens_in_calldata = zero_bytes + 4 * non_zero_bytes
211211
#
212-
# So we calculate how many bytes we can fit into calldata based on available gas.
212+
# So we calculate how many bytes we can fit into calldata based on
213+
# available gas.
213214
max_tokens_in_calldata = gas_amount // total_cost_floor_per_token
214215
num_of_bytes = max_tokens_in_calldata if zero_byte else max_tokens_in_calldata // 4
215216
byte_data = b"\x00" if zero_byte else b"\xff"
@@ -272,7 +273,10 @@ def test_block_full_access_list_and_data(
272273
gas_benchmark_value: int,
273274
tx_gas_limit_cap: int,
274275
):
275-
"""Test a block with access lists (60% gas) and calldata (40% gas) using random mixed bytes."""
276+
"""
277+
Test a block with access lists (60% gas) and calldata (40% gas) using
278+
random mixed bytes.
279+
"""
276280
iteration_count = math.ceil(gas_benchmark_value / tx_gas_limit_cap)
277281

278282
gas_remaining = gas_benchmark_value
@@ -309,8 +313,10 @@ def test_block_full_access_list_and_data(
309313
)
310314
]
311315

312-
# Calculate calldata with 29% of gas for zero bytes and 71% for non-zero bytes
313-
# Token accounting: tokens_in_calldata = zero_bytes + 4 * non_zero_bytes
316+
# Calculate calldata with 29% of gas for zero bytes and 71% for
317+
# non-zero bytes
318+
# Token accounting: tokens_in_calldata = zero_bytes + 4 *
319+
# non_zero_bytes
314320
# We want to split the gas budget:
315321
# - 29% of gas_for_calldata for zero bytes
316322
# - 71% of gas_for_calldata for non-zero bytes

tests/benchmark/test_worst_compute.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,12 @@ def test_worst_returndatasize_nonzero(
215215
def test_worst_returndatasize_zero(
216216
benchmark_test: BenchmarkTestFiller,
217217
pre: Alloc,
218-
fork: Fork,
219-
gas_benchmark_value: int,
220-
) -> None:
218+
):
221219
"""
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.
224222
"""
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(
243224
pre=pre,
244225
post={},
245226
code_generator=ExtCallGenerator(setup=Bytecode(), attack_block=Op.RETURNDATASIZE),
@@ -288,8 +269,10 @@ def test_worst_keccak(
288269
gsc = fork.gas_costs()
289270
mem_exp_gas_calculator = fork.memory_expansion_gas_calculator()
290271

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.
293276
max_keccak_perm_per_block = 0
294277
optimal_input_length = 0
295278
for i in range(1, 1_000_000, 32):
@@ -320,9 +303,11 @@ def test_worst_keccak(
320303
# The loop structure is: JUMPDEST + [attack iteration] + PUSH0 + JUMP
321304
#
322305
# 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
326311
# attack, whenever this is fixed adjust accordingly.
327312
benchmark_test(
328313
pre=pre,
@@ -1566,11 +1551,13 @@ def test_worst_tstore(
15661551
init_key = 42
15671552
setup = Op.PUSH1(init_key)
15681553

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

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

15761563
benchmark_test(
@@ -1731,8 +1718,10 @@ def test_worst_mod(
17311718
The order of accessing the numerators is selected in a way the mod value
17321719
remains in the range as long as possible.
17331720
"""
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.
17361725
# The result stays negative.
17371726
should_negate = op == Op.SMOD
17381727

@@ -1804,7 +1793,8 @@ def test_worst_mod(
18041793
seed += 1
18051794
print(f"{seed=}")
18061795

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.
18081798
setup = sum((Op.PUSH32[n] for n in numerators), Bytecode())
18091799
attack_block = (
18101800
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(
18351825
offset: int,
18361826
offset_initialized: bool,
18371827
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+
"""
18401833
mem_exp_code = Op.MSTORE8(10 * 1024, 1) if big_memory_expansion else Bytecode()
18411834
offset_set_code = Op.MSTORE(offset, 43) if offset_initialized else Bytecode()
18421835
setup = mem_exp_code + offset_set_code + Op.PUSH1(42) + Op.PUSH1(offset)
@@ -2295,11 +2288,11 @@ def test_worst_clz_diff_input(
22952288
pre: Alloc,
22962289
fork: Fork,
22972290
env: Environment,
2298-
) -> None:
2291+
):
22992292
"""
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.
23012295
"""
2302-
tx_gas_limit = fork.transaction_gas_limit_cap() or env.gas_limit
23032296
max_code_size = fork.max_code_size()
23042297

23052298
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)