-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
base: develop
Are you sure you want to change the base?
Conversation
cbd97cc
to
b14ee0a
Compare
550b207
to
1614491
Compare
1614491
to
0d84691
Compare
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andclear
) and check the state in between. The behavior at the boundary is suspect in general, not just fordelete
. 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 anddelete
so if the PR fixeddelete
, 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.
test/libsolidity/semanticTests/storage/delete_overflow_bug_collision.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/semanticTests/storage/delete_overflow_bug_large_mapping_storage_boundary.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/semanticTests/storage/delete_overflow_bug_large_mapping_storage_boundary.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/semanticTests/storage/delete_overflow_bug_partial_assignment.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/semanticTests/storage/delete_overflow_bug_partial_assignment.sol
Outdated
Show resolved
Hide resolved
Please include a link to the issue you're fixing in the PR description. |
25bd6b5
to
b57d7a2
Compare
b57d7a2
to
47471c6
Compare
Fixes #15587