-
Notifications
You must be signed in to change notification settings - Fork 271
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 storage layout comparison for function types, disallow internal functions in storage #1032
Conversation
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.
mostly looks good, but shouldn't it also check for internal functions as a storage variable? for example:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract StorageUpgrade_FunctionType_Visibility_V2_Bad {
function () internal m;
}
function m
will break after an upgrade as it gets moved around storage, no? similar to internal functions in structs
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.
Very interesting finding!
I wonder if we should document how to reset the internal function pointers in the docs. It's true we now have a clear instruction within the CLI but we're not providing a concrete example other than the one shared in #1031.
What do you think?
Functions do not live in storage, so The issue with storing internal function pointers in storage is that after upgrading to another implementation, the pointer in storage is a pointer to code that isn't used anymore. That's why it needs reinitialization. |
Agree we should check storage variables that have function types even outside of structs, and will add a section in the docs. |
Yup, meant to refer to the pointer changing when upgrading to a different implementation. |
|
Co-authored-by: Francisco <[email protected]>
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.
LGTM! Minor suggestion.
Co-authored-by: Francisco <[email protected]>
This fixes 2 things:
Fixes An error due to function defined in struct in library #1031. In storage layout comparisons, type changes involving function pointers caused an error because of an incorrect assertion. The original and updated types could be unrelated during the comparison, but
getVisibilityChange
was asserting that both are functions. We should only callgetVisibilityChange
if both the original and updated types are indeed functions.Fixes Disallow internal function types in storage #555. Internal functions are code pointers which will no longer be valid after an upgrade, so they should not be allowed. Added this as a validation error, and allow it to be skipped with the
unsafeAllow.internal-function-storage
option (if skipping, users need to make sure they always reassign the internal functions in storage variables during each upgrade).