Skip to content

fix(tests): fixes EXTCODECOPY bench test #1865

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 1 commit into
base: main
Choose a base branch
from

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Jul 7, 2025

🗒️ Description

In #1864 I realized a problem with the EXTCODECOPY test. It copies to memory to offset 85. This is correct if the CREATE2 hash alignment starts at 0. It however starts at byte 11 (the address starts at 12). This means that the memory region [11,96) is occupied by the bytes to hash to get the correct address. If we thus EXTCODECOPY to byte 85, we overwrite the bytes there (initcode hash is stored there). This means that all EXTCODECOPYs after the first one target incorrect addressess, i.e. they have empty code.

I checked this file if there are more of these tests but this seem to be the only one. (This could be a problem with other tests also using CREATE2 and using operations which writes to memory. It should not overwrite the to-be-hashed data to retrieve the CREATE2 address created from the factory)

CC @jsign

🔗 Related Issues or PRs

N/A.

✅ 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.

@jochem-brouwer jochem-brouwer requested a review from jsign July 7, 2025 03:28
Copy link
Collaborator

@jsign jsign left a comment

Choose a reason for hiding this comment

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

Good catch!

Just in case, I debugged a run of both the previous and new code in Geth, and can confirm the bug and fix.

@@ -182,7 +182,7 @@ def test_worst_bytecode_single_opcode(

attack_call = Bytecode()
if opcode == Op.EXTCODECOPY:
attack_call = Op.EXTCODECOPY(address=Op.SHA3(32 - 20 - 1, 85), dest_offset=85, size=1000)
attack_call = Op.EXTCODECOPY(address=Op.SHA3(32 - 20 - 1, 85), dest_offset=96, size=1000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Parallel suggestion: maybe something like this can be clearer for readers:

Suggested change
attack_call = Op.EXTCODECOPY(address=Op.SHA3(32 - 20 - 1, 85), dest_offset=96, size=1000)
create2_params_offset = 32 - 20 - 1
create2_params_size = 85
attack_call = Op.EXTCODECOPY(address=Op.SHA3(create2_params_offset, create2_params_size), dest_offset=create2_params_offset+create2_params_size, size=1000)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good point, I'll follow up to somewhat take out these "magic numbers" 😄 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants