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

eof: Add support for SWAPN/DUPN #15845

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

eof: Add support for SWAPN/DUPN #15845

wants to merge 4 commits into from

Conversation

ekpyron
Copy link
Member

@ekpyron ekpyron commented Feb 10, 2025

Needs a second look - I just wrote exactly what I needed for #15844

@cameel
Copy link
Member

cameel commented Feb 10, 2025

I only skimmed over it for now, but one thing that's probably missing is semantic info. Shouldn't the new opcodes at the very least be included in isDupInstruction() and isSwapInstruction()?

@cameel

This comment was marked as outdated.

@cameel cameel added the EOF label Feb 12, 2025
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

One actual problem I found is that just adding the new items to isDupInstruction()/isSwapInstruction() does not seem to be enough for the optimizer to handle them properly. A few more changes are needed.

Other than that the usual stuff: tests, docstrings, asserts and some suggestions for consistency.

libevmasm/Assembly.h Outdated Show resolved Hide resolved
libevmasm/Assembly.cpp Outdated Show resolved Hide resolved
libevmasm/AssemblyItem.cpp Outdated Show resolved Hide resolved
libevmasm/AssemblyItem.h Outdated Show resolved Hide resolved
Comment on lines 152 to 153
virtual void appendSwapN(size_t _depth) = 0;
virtual void appendDupN(size_t _depth) = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Need docstrings here.

One very important thing to to mention is the range of _depth.

Would probably be useful to have that included in the docstrings in AssemblyItemType as well since this is the other main place where we seem to be documenting these things.

Copy link
Member

Choose a reason for hiding this comment

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

We should also assert against the range in the implementation. We do have asserts in assembleEOF() already but IMO that's a bit disconnected and we should be checking that as the precondition in these Assembly helpers as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should also assert against the range in the implementation. We do have asserts in assembleEOF() already but IMO that's a bit disconnected and we should be checking that as the precondition in these Assembly helpers as well.

Should we :-)? What if we get a new version of EOF that extends the range? I can add them, but I'm not entirely convinced :-).

Copy link
Member Author

Choose a reason for hiding this comment

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

I added asserts a few levels deeper in AssemblyItem, that should do it.

Copy link
Member

Choose a reason for hiding this comment

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

Well, at least the check for >=1 should be fairly universal.

For the upper bound, fair enough, I guess from the viewpoint of the abstract assembly the limitation to uint8 is still a bit arbitrary and you could argue that only assembleEOF() we really hit something that concretely depend on it (the ability to fit the number into a single byte).

In any case the asserts you added seem fine.

Copy link
Member

Choose a reason for hiding this comment

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

I'd still mention the 1-based indexing in AssemblyItemType docstrings though.

libevmasm/Instruction.cpp Show resolved Hide resolved
libevmasm/SemanticInformation.cpp Outdated Show resolved Hide resolved
liblangutil/EVMVersion.cpp Outdated Show resolved Hide resolved
@ekpyron ekpyron force-pushed the eofAddSwapnDupn branch 6 times, most recently from 9c42ce1 to c39219d Compare February 12, 2025 17:05
@ekpyron ekpyron marked this pull request as ready for review February 12, 2025 17:10
@ekpyron ekpyron requested a review from cameel February 12, 2025 17:11
@cameel
Copy link
Member

cameel commented Feb 12, 2025

Looks like it needs some squashing of review fixes before merge.

@cameel
Copy link
Member

cameel commented Feb 12, 2025

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

Successfully merging this pull request may close these issues.

3 participants