-
Notifications
You must be signed in to change notification settings - Fork 147
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?
Conversation
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.
This test looks fine to me, it tests all LOG opcodes and runs those all as much as possible. However, I think we should also add these situations:
- Log data length is nonzero
- Log data length + data is nonzero (here we have to initialize the memory to something non-zero)
- The topics are nonzero
I am not sure because I am not deep into zkEVM, is calculating the logsBloom
part of the scope of the EVM (and would thus add extra logic/cycles) @jsign? If this is indeed part of it (either logsBloom
or calculating receiptTrie
or both) then those tests should be added for zkEVM (can be done in a different PR).
Those tests are also nice benchmark tests for non-zkEVM also 😄 👍
Will not explicitly approve for now.
Thanks for comment, I do not know |
Yep, calculating |
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.
Looking good! Reg @jochem-brouwer suggestion to cover non-zero scenarios (which I agree are useful), I'll let you decide if those might be worked in this PR or in a separate one -- for now leaving an approval if it is the latter.
Just left one comment for your consideration.
tests/zkevm/test_worst_compute.py
Outdated
|
||
|
||
@pytest.mark.parametrize( | ||
"opcode,topic_count", |
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.
Maybe we can remove the topic_count
parameter, and derive it from opcode - Op.LOG0
?
Mainly because combinations like Op.LOG0, 1
or Op.LOG3, 4
would never make sense?
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 like this suggestion 😄
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.
LGTM, just one suggestion that is in line with the comments from previous reviewers, thanks!
tests/zkevm/test_worst_compute.py
Outdated
env = Environment() | ||
max_code_size = fork.max_code_size() | ||
|
||
iter_code = Op.PUSH0 * (2 + topic_count) + opcode |
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.
iter_code = Op.PUSH0 * (2 + topic_count) + opcode | |
iter_code = Op.PUSH0 * len(opcode.kwargs) + opcode |
And you can remove the topic_count
parameter.
For the mypy error, I think if you rebase to main it should be gone, I just fixed that in another PR. |
🗒️ Description
Create Benchmark for
LOG
OpcodeThis PR introduces a benchmark for the
LOG
opcode in the EVM. TheLOG
operation includes multiple fields:offset
,size
, and up toN
topics depending on the variant (LOG0 through LOG4).Gas Cost Calculation
Using
LOG0
as an example, the gas cost for theLOG
operation is computed as:375
dynamic_gas = 375 * topic_count + 8 * size + memory_expansion_cost
To minimize gas costs:
PUSH0
(which costs 2 bytes) for pushing values to the stack, as it’s cheaper than other operation likePUSH1
(3 bytes with an immediate) orDUP1
(3 bytes).Using
PUSH0
is also more space-efficient, since it avoids including immediate values and reduces bytecode size.Benchmark Bytecode Pattern
A minimal loopable pattern for benchmarking LOGN looks like this:
Using
PUSH0
is also more space-efficient, since it avoids including immediate values and reduces bytecode size. This makes it preferable overDUP1
for setting up the stack for topics or memory offset/size.🔗 Related Issues
Issue #1689
✅ Checklist
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.