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: Contract creation fix and tests. #15595

Merged
merged 4 commits into from
Nov 29, 2024

Conversation

rodiazet
Copy link
Contributor

  • Fix wrong container ID calculation in case of unreferenced container before the referenced one.
  • Add test
  • Small refactor of ContainerID usage

Copy link

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

uint8_t nUnreferenced = 0;
for (uint8_t i = 0; i < static_cast<uint16_t>(m_subs.size()); ++i)
for (uint8_t i = 0; i < static_cast<ContainerID>(m_subs.size()); ++i)
Copy link
Member

Choose a reason for hiding this comment

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

i will overflow and the loop will never stop when there are 256 sections. You need a bigger type to iterate over sections:

Suggested change
for (uint8_t i = 0; i < static_cast<ContainerID>(m_subs.size()); ++i)
for (size_t i = 0; i < m_subs.size(); ++i)

Would be best if we could have this corner case covered with a test. Maybe one with empty subobjects to keep it compact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Shit I assumed for some reason that 0x100 == 100 👯

Copy link
Member

@cameel cameel Nov 28, 2024

Choose a reason for hiding this comment

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

This really makes me question whether not investing more time into tests at this stage is a wise decision. Ultimately mistakes like this should be caught by tests. We're rushing towards semantic tests, but some cases like this one definitely would not be caught by them. And these smaller PRs are the only place to consider corner cases in detail. Once it's all in, no one will have time to go back through the whole backend and figure out where extra tests are needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reminds me also to add proper error to AsmAnalysis covering the case when we have more then 256 subcontainers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

libevmasm/Assembly.cpp Show resolved Hide resolved
// return
// stop
//
// sub_0: assembly {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should be removing unreferenced containers somewhere before assembling after all. It's actually a bit weird that we show them in assembly but then they're missing from the bytecode. It makes the assembly less reliable as way for users to inspect what is being generated (and for me to verify that the expectations are actually correct because the change is only in the binary :)).

Of course it's not something to address in this PR, but maybe something to think about. The problem is actually similar to removing unreferenced functions from CFG in a way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would also remove the subcontainers earlier. On CFG level ideally.

cameel
cameel previously approved these changes Nov 28, 2024
cameel
cameel previously approved these changes Nov 28, 2024
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.

Looks good, I'd just tweak one test (see below).

Also, the PR now does quite a bit more than just fix the IDs - it also adds a new validation and fixes the infinite loop bug. If this wasn't experimental code, each of those would get a separate changelog entry so I think at least putting them in separate commits is warranted. The commit description no longer accurately reflects what's inside.

@rodiazet rodiazet changed the title eof: Fix container id in case of unreferenced containers in yul eof: Contantract creation fix and tests. Nov 29, 2024
@rodiazet rodiazet changed the title eof: Contantract creation fix and tests. eof: Contract creation fix and tests. Nov 29, 2024
@rodiazet rodiazet force-pushed the eof-container-id-fix branch 4 times, most recently from 4480387 to 52781f0 Compare November 29, 2024 15:06
@cameel cameel merged commit 0b01a8a into ethereum:develop Nov 29, 2024
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants