Skip to content

Fix array assignment and deletion at storage slot overflow boundary #15984

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

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

r0qs
Copy link
Member

@r0qs r0qs commented Apr 7, 2025

Fixes #15587

@r0qs r0qs marked this pull request as draft April 7, 2025 09:37
@r0qs r0qs force-pushed the storageOverflowDeleteBug branch 2 times, most recently from cbd97cc to b14ee0a Compare April 7, 2025 10:02
@r0qs r0qs added this to the 0.8.30 milestone Apr 7, 2025
@r0qs r0qs force-pushed the storageOverflowDeleteBug branch 10 times, most recently from 550b207 to 1614491 Compare April 11, 2025 14:37
@r0qs r0qs force-pushed the storageOverflowDeleteBug branch from 1614491 to 0d84691 Compare April 14, 2025 15:34
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.

First batch of review comments. Mostly about making sure the test coverage is adequate.

Comment on lines 7 to 16
function f() public returns (uint256[10] memory) {
uint256[10][1] storage x = getArray();
for (uint i = 0; i < 10; i++)
x[0][i] = i;
delete x[0];
return x[0];
}
}
// ----
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Copy link
Member

Choose a reason for hiding this comment

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

You should split this into two operations (fill and clear) and check the state in between. The behavior at the boundary is suspect in general, not just for delete. If the filling part is broken too, we won't notice otherwise.

The same applies to the other tests in this PR. Especially in delete_overflow_bug_large_mapping_storage_boundary.sol, you are not checking the values between the partial assignment and delete so if the PR fixed delete, but not the assignment, we would not notice.

Copy link
Member

Choose a reason for hiding this comment

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

Also, you should use a getter for reading the values in expectations instead of returning it from the function. Otherwise actual storage reads and writes are getting optimized out by LoadResolver. It may not affect the result in practice, since the optimizer should preserve the semantics of generated Yul no matter if it's correct or not, but if we can eliminate this confounding variable, we should.

Copy link
Member Author

@r0qs r0qs Apr 23, 2025

Choose a reason for hiding this comment

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

You should split this into two operations (fill and clear) and check the state in between. The behavior at the boundary is suspect in general, not just for delete. If the filling part is broken too, we won't notice otherwise.

The same applies to the other tests in this PR. Especially in delete_overflow_bug_large_mapping_storage_boundary.sol, you are not checking the values between the partial assignment and delete so if the PR fixed delete, but not the assignment, we would not notice.

Yeah, indeed, thanks for pointing that out. I actually noticed that assignments still seem to be broken with the current fix. The problem seems to be in the copyArrayToStorage function.

@cameel
Copy link
Member

cameel commented Apr 22, 2025

Please include a link to the issue you're fixing in the PR description.

@r0qs r0qs changed the title Storage overflow delete bug Fix array assignment and deletion at storage slot overflow boundary Apr 23, 2025
@r0qs r0qs force-pushed the storageOverflowDeleteBug branch 2 times, most recently from 25bd6b5 to b57d7a2 Compare April 23, 2025 20:28
@r0qs r0qs force-pushed the storageOverflowDeleteBug branch from b57d7a2 to 47471c6 Compare April 23, 2025 20:47
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.

Inconsistent Treatment of Storage Arrays on the Slot Overflow Boundary
3 participants