Skip to content

feat(zkevm): add log opcode worst case #1745

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
68 changes: 68 additions & 0 deletions tests/zkevm/test_worst_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,3 +2173,71 @@ def test_worst_push(
post={},
tx=tx,
)


@pytest.mark.parametrize(
"opcode",
[
pytest.param(Op.LOG0, id="log0"),
pytest.param(Op.LOG1, id="log1"),
pytest.param(Op.LOG2, id="log2"),
pytest.param(Op.LOG3, id="log3"),
pytest.param(Op.LOG4, id="log4"),
],
)
@pytest.mark.parametrize(
"size",
[
0, # 0 bytes
10, # 10 bytes
100, # 100 bytes
1 * 1024, # 1KiB
10 * 1024, # 10KiB
100 * 1024, # 100KiB
1024 * 1024, # 1MiB
],
)
@pytest.mark.parametrize("empty_value", [True, False])
@pytest.mark.parametrize("fixed_offset", [True, False])
def test_worst_log_opcodes(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
opcode: Opcode,
empty_value: bool,
size: int,
fixed_offset: bool,
):
"""Test running a block with as many LOG opcodes as possible."""
env = Environment()
max_code_size = fork.max_code_size()

calldata = (
Op.PUSH0
if empty_value
else Op.PUSH32(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this could be further optimized for readability

)

topic_count = len(opcode.kwargs or []) - 2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here I want to extract the topic count, it is kwargs - 2 because offset and value should be excluded. And I could not use len(opcode.kwargs) - 2, this would result in data type checking issue.

For kwargs, it is either a List or None type, for the latter one, there is no len method. - Link


offset = Op.PUSH0 if fixed_offset else Op.MOD(Op.GAS, 7)

code_sequence = Op.DUP1 * topic_count + Op.PUSH32(size) + offset + opcode

code = code_loop_precompile_call(calldata, code_sequence, fork)
assert len(code) <= max_code_size

code_address = pre.deploy_contract(code=code)

tx = Transaction(
to=code_address,
gas_limit=env.gas_limit,
sender=pre.fund_eoa(),
)

state_test(
env=env,
pre=pre,
post={},
tx=tx,
)
Loading