Skip to content

feat(tests): add worst-case block test for 7702 set code #1758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/zkevm/test_worst_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Account,
Address,
Alloc,
AuthorizationTuple,
Block,
BlockchainTestFiller,
Environment,
Expand Down Expand Up @@ -156,3 +157,44 @@ def test_block_full_of_ether_transfers(
blocks=[Block(txs=txs)],
exclude_full_post_state_in_output=True,
)


@pytest.mark.valid_from("Prague")
def test_block_full_of_7702_set_code(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
iteration_count: int,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a defined parametrization?
(Edit: see also my message below)

):
"""
Test worst-case block scenario with 7702 set code.

This test is designed to test the worst-case block scenario with 7702 set code.
"""
env = Environment()
attack_gas_limit = env.gas_limit
sender = pre.fund_eoa()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to pre-set these to an authorization for the reset to do something.

Suggested change
sender = pre.fund_eoa()
sender = pre.fund_eoa(delegation=Address(0x1))

Copy link
Collaborator

@jsign jsign Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but sounds it would only have effects for the first tx of the list. Starting with the second and further txs, the delegation will be considered a noop, no? So most tx won't be doing any real work.

I wonder if this test should probably:

  • Try calculating the maximum number of delegations possible for gas_limit (and remove the iteration_count parameter).
  • Create N different accounts as suggested by @marioevz code suggestion.
  • Create the N different delegations for target T in a single tx (to save as much intrinsic gas as possible? But not sure this will have a limit reg tx size)
  • Let T in the bullet above be parametrizable, i.e.: 0x00 for testing as many resets, and non-0x00 for testing real delegations.


txs = []
for i in range(iteration_count):
txs.append(
Transaction(
gas_limit=attack_gas_limit,
to=sender,
authorization_list=[
AuthorizationTuple(
address=Address(0x0),
nonce=i + 1,
signer=sender,
),
],
sender=sender,
)
)

blockchain_test(
genesis_environment=env,
pre=pre,
post={},
blocks=[Block(txs=txs)],
exclude_full_post_state_in_output=True,
)
Loading