-
Notifications
You must be signed in to change notification settings - Fork 151
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
) | ||
|
||
topic_count = len(opcode.kwargs or []) - 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 For kwargs, it is either a |
||
|
||
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, | ||
) |
There was a problem hiding this comment.
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