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

fix(vm): Bytecode comparison #939

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

fix(vm): Bytecode comparison #939

wants to merge 2 commits into from

Conversation

marioevz
Copy link
Member

@marioevz marioevz commented Nov 5, 2024

🗒️ Description

Fixes Bytecode equality comparison method to take other properties into account when comparing against some other Bytecode object.

The issue surfaced when I tried to implement tests for EIP-5920 that contains the PAY opcode, which collides with the EXTDELEGATECALL opcode for EOF. When both opcodes were included in the same Enum, it seems like this class internally performs an optimization that compares all items and reuses instances that return __eq__() == True, which lead to the Op.PAY being equal to the value assigned to Op.EXTDELEGATECALL.

🔗 Related Issues

None.

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

@marioevz marioevz added type:bug Something isn't working scope:fw Scope: Framework (evm|tools|forks|pytest) labels Nov 5, 2024
@marioevz marioevz requested review from danceratopz and winsvega and removed request for danceratopz November 5, 2024 17:25
@@ -117,6 +117,14 @@ def __eq__(self, other):
- NotImplementedError: if the comparison is not between an Bytecode
or a bytes object.
"""
if isinstance(other, Bytecode):
return (
bytes(self) == bytes(other)
Copy link
Collaborator

@winsvega winsvega Nov 5, 2024

Choose a reason for hiding this comment

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

i think this must be enough. because pushed popped is our own construct.
I use opcode generation from int number. and I don't provide the poped or pushed values.

so for such dynamically generated opcodes. lets say I want opcode(x) where x is 0.255
this comparison won't work

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used in EOF for example, the same binary bytecode can have different max_stack_height in two different sections:

Section.Code(Op.RETF, inputs=1)

has not the same max_stack_height as:

Section.Code(Op.RETF, inputs=2)

so I think it might be worth it to differentiate between two bytecode objects if we have these properties available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:fw Scope: Framework (evm|tools|forks|pytest) type:bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants