-
Notifications
You must be signed in to change notification settings - Fork 837
evm: add "count leading zeros" opcode example #4176
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR adds a new example demonstrating the CLZ (Count Leading Zeros) opcode introduced in EIP-7939 for the Osaka hardfork. The example shows how to use the new opcode with various test cases.
- Adds a comprehensive example file showcasing the CLZ opcode functionality
- Demonstrates four test cases covering edge cases: all zeros, minimal value, and different bit positions
- Uses manual bytecode assembly to construct and execute CLZ operations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
03b4221 to
f587e8c
Compare
| @@ -0,0 +1,72 @@ | |||
| import { Common, Hardfork, Mainnet } from '@ethereumjs/common' | |||
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.
Can we make the name of this file more expressive, so that people can spot what the example is about?
(clz might be in the head of people now, but will be forgotten soon).
So that would be clz-opcode.ts or so.
(simple solution)
I you want to go a little extra mile I would also be a fan of the a bit extended version, which would be to keep the name but do a subfolder opcodes (like precompiles).
I prepared for that to be possible (in the sense that the examples still run), this would need a slight addition to the package.json examples script (should be obvious).
f587e8c to
d971432
Compare
holgerd77
left a comment
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.
Nice, I have posted a few optimizations, but generally looks good! 🙂
PR #4133 added support for the new CLZ (count leading zeros) opcode from EIP-7939.
The
CLZopcode (0x1e) pops one 256-bit word (x) from the stack and pushes the number of leading zero bits inx.This PR adds a small example script to demonstrate the opcode in action. It creates an Osaka hardfork EVM with EIP-7939 enabled and executes the CLZ opcode on a few different 32-byte inputs.
Added subfolder
evm/examples/opcodesand updated example runner script to run examples in the new subfolder