Skip to content

feat(tests): extra stack operation test for CLZ opcode #1821

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

LouisTsai-Csie
Copy link
Collaborator

@LouisTsai-Csie LouisTsai-Csie commented Jun 30, 2025

🗒️ Description

Hardening Fusaka for EIP-7939

Add two additional test cases for stack manipulation related to the CLZ (Count Leading Zeros) opcode:

  1. No Stack Overflow
    The CLZ operation must never cause a stack overflow, as it does not increase the number of items on the stack.
    Test: Push 1022 items onto the stack, then execute CLZ 256 times while storing the result after each call. Ensure that no stack overflow occurs during this process.
  2. Consistency Across Equivalent PUSH Operations
    For the same numeric value pushed onto the stack, the CLZ opcode should yield the same result, regardless of which PUSH variant (PUSH1 to PUSH32) was used.
    Examples:
  • Pushing the value 0x01 using any PUSH1–PUSH32 should result in the same CLZ output.
  • Pushing the value 0x0A000000 (10 00 00 00 in hex) using any PUSH4–PUSH32 should also produce a consistent result.

🔗 Related Issues or PRs

Issue #1795

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered adding an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.
  • Tests: For PRs implementing a missed test case, update the post-mortem document to add an entry the list.
  • Ported Tests: All converted JSON/YML tests from ethereum/tests or tests/static have been assigned @ported_from marker.

@LouisTsai-Csie LouisTsai-Csie self-assigned this Jun 30, 2025
@LouisTsai-Csie LouisTsai-Csie added type:test Type: Add/refactor fw unit tests; no fw or el client test case changes fork:osaka Osaka hardfork labels Jun 30, 2025
@LouisTsai-Csie LouisTsai-Csie marked this pull request as ready for review June 30, 2025 17:41
Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Looks good! Just a couple of comments, thanks!


for i in range(bit, 32):
op = getattr(Op, f"PUSH{i}")
code += Op.SSTORE(op[i], Op.CLZ(1 << bit))
Copy link
Member

Choose a reason for hiding this comment

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

I feel we should use Op.CLZ(op[1 << bit]) to guarantee that the PUSHn opcode is the one that pushes to the stack right before CLZ.

state_test(pre=pre, post=post, tx=tx)


@pytest.mark.parametrize("bit", list(range(1, 33)))
Copy link
Member

Choose a reason for hiding this comment

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

Could we cram all these into a single test? I feel this generates way too many tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I put all the test cases into a single test, and remove the parametrization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fork:osaka Osaka hardfork type:test Type: Add/refactor fw unit tests; no fw or el client test case changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants