EIP-7939 CLZ Opcode for FEVM
#1229
snissn
started this conversation in
Enhancements - Technical
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all — we’d like to propose a FIP adding support for Ethereum EIP-7939 (“Count Leading Zeros”) to the Filecoin EVM (FEVM).
EIP-7939 introduces a new opcode,
CLZ(0x1e), which returns the number of leading zero bits in a 256-bit word. This opcode is activated on Ethereum mainnet as part of the Fusaka upgrade (see announcement: https://blog.ethereum.org/2025/11/06/fusaka-mainnet-announcement).Draft FIP: FIPS/fip-draft_eip-7939-clz.md
Implementation: filecoin-project/builtin-actors#1709
Motivation / Why now
Counting leading zeros is a common primitive used in:
Without a dedicated opcode, contracts must emulate
CLZusingSHR/comparisons, which increases bytecode size, complexity, and runtime cost. Supporting EIP-7939 in FEVM improves portability with modern EVM environments and lowers costs for these workloads.Specification (high level)
CLZ0x1ex, pushesrCLZ(0) = 256CLZ(x)is the number of leading zero bits in the 256-bit representation ofx5gas (matchingMUL) on Ethereum. However, the FEVM uses Filecoin gas accounting (FIP-0054) rather than Ethereum’s opcode gas schedule, so we don’t need to define a new FEVM “opcode gas cost” constant;CLZexecution is metered under Filecoin gas like other opcodes.Implementation status
A reference implementation is ready in
builtin-actorsand includes:CLZat0x1eCLZinside a deployed EVM actorBackwards Compatibility
Before activation, byte
0x1eis an undefined opcode that aborts execution. After activation it will executeCLZ. This is backwards-incompatible for any contract that intentionally depended on0x1ebeing invalid.Feedback requested
0x1eas a new opcode in FEVM (backwards compatibility / upgrade timing)?Thanks in advance for reviews and feedback.
— Aarav Mehta (@aaravm), Michael Seiler (@snissn)
Beta Was this translation helpful? Give feedback.
All reactions