Skip to content
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

feat(fw): allow adding verbatim bytes to Bytecode #1119

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

chfast
Copy link
Member

@chfast chfast commented Jan 23, 2025

🗒️ Description

This provides a basic requested feature to allow concatenating Bytecode with verbatim bytes.
This implementation overload the __add__ and make the basic use case work.
However, this is not very consistent. E.g.

  • code + b"\x00" means something different than code + Bytecode(b"\x00")
  • Bytecode() + b"\x00" works in places where Bytecode() is expected but b"\x00" don't.

The reason this is not a complete solution is that Bytecode() already has a constructor from bytes but its purpose is different and unknown to me. We should consider changing the semantic of conversion from bytes to Bytecode() by just copying the bytes.

There is one more option for handling truncated opcode immediate bytes: take verbatim bytes from [], e.g. Op.PUSH3[b"\x00"]. This currently compiles, but Bytecode also tries to be smart here and extends the provided bytes to the desired length. I'm not 100% sure what it does but I couldn't built a code with truncated immediates this way. However, there is one example that seems to be working:

data=Container.Code(code=Op.PUSH1(1) + Op.RJUMPV[rjumpv_bytes]),

🔗 Related Issues

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • Tests: A PR with removal of converted JSON/YML tests from ethereum/tests have been opened.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@chfast chfast requested review from marioevz, gumb0 and winsvega January 23, 2025 21:38
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.

LGTM. I pushed some minor fixes and will merge once the CI passes.

@marioevz
Copy link
Member

Regarding the inconsistencies, this feature should be handled with care anyway, and I think we should only use it when absolutely necessary, so I will keep an eye on usages during reviews to make sure it doesn't get out of control :P

@marioevz marioevz merged commit b8edede into ethereum:main Jan 27, 2025
11 checks passed
@marioevz marioevz deleted the bytecode_verbatim_bytes branch January 27, 2025 22:25
Copy link
Collaborator

@pdobacz pdobacz left a comment

Choose a reason for hiding this comment

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

I had some late comments

@@ -116,7 +116,7 @@ def test_rjump_truncated_rjump_2(
):
"""EOF1I4200_0002 (Invalid) EOF code containing truncated RJUMP."""
eof_test(
data=Container.Code(Op.RJUMP + Op.STOP),
data=Container.Code(Op.RJUMP + b"\x00"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

to address @marioevz 's concerns, maybe this should be Op.RJUMP + verbatim(b"\x00"), and verbatim produces some type which can be added to Bytecode but isn't bytes explicitly, possibly Bytecode would be fine? This would make spotting abuse much easier.

Basically verbatim could be what @chfast envisioned for the constructor Bytecode.

marioevz added a commit to marioevz/execution-spec-tests that referenced this pull request Jan 30, 2025
* feat(fw): allow adding verbatim bytes to Bytecode

* fix: linting, tests

---------

Co-authored-by: Mario Vega <[email protected]>
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.

4 participants