Skip to content

feat(evm): add EIP-7939 CLZ opcode (0x1e)#1709

Open
snissn wants to merge 5 commits intomasterfrom
eip7939-clz
Open

feat(evm): add EIP-7939 CLZ opcode (0x1e)#1709
snissn wants to merge 5 commits intomasterfrom
eip7939-clz

Conversation

@snissn
Copy link
Contributor

@snissn snissn commented Jan 21, 2026

Summary

Implements Ethereum EIP-7939 (Count Leading Zeros) for the FEVM EVM interpreter by adding the CLZ opcode at byte 0x1e.

Changes

  • Adds CLZ (0x1e) to the opcode table and instruction dispatch.
  • Implements CLZ semantics over 256-bit words (CLZ(0) = 256).
  • Adds tests covering the EIP-7939 test vectors:
    • unit + bytecode-level tests in the interpreter
    • end-to-end actor test executing CLZ in a deployed EVM actor

Notes

  • Full workspace cargo test may require a wasm32-capable clang; on macOS this can be run with CC=/opt/homebrew/opt/llvm/bin/clang cargo test.

Related

Copy link
Contributor

Copilot AI left a 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 implements EIP-7939 (Count Leading Zeros) for the FEVM EVM interpreter by adding the CLZ opcode at byte position 0x1e. The opcode counts the number of leading zero bits in a 256-bit word, returning 256 when the input is zero.

Changes:

  • Added CLZ opcode (0x1e) to the opcode dispatch table
  • Implemented CLZ semantics using U256's leading_zeros() method
  • Added comprehensive test coverage including unit tests, bytecode-level tests, and end-to-end actor tests

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
actors/evm/src/interpreter/execution.rs Adds CLZ opcode at 0x1e to the opcode table and includes it in underflow testing
actors/evm/src/interpreter/instructions/mod.rs Defines CLZ instruction using the def_primop! macro with single operand
actors/evm/src/interpreter/instructions/bitwise.rs Implements clz function and includes unit tests and bytecode-level integration tests
actors/evm/tests/eip7939_clz.rs Adds end-to-end test with EIP-7939 test vectors using a deployed EVM actor

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting Review in FilOz Jan 27, 2026
@BigLep BigLep requested a review from LesnyRumcajs January 27, 2026 04:32
@BigLep
Copy link
Member

BigLep commented Jan 27, 2026

@LesnyRumcajs : are you or someone on Forest able to take a look at this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this PR doesn't need to change the lockfile (fine to do it in a separate PR); especially the syn major version downgrade is suspicious.

Comment on lines +46 to +49
#[inline]
pub fn clz(value: U256) -> U256 {
U256::from(value.leading_zeros())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it might be obvious to some, but my brain doesn't immediately click that clz is count leading zeroes. One line of docs would reduce mental overhead.

mod tests {
use crate::evm_unit_test;

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a valuable test. If we want to check the def_opcodes macro works, lets write a test to for it entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting Review

Development

Successfully merging this pull request may close these issues.

3 participants