-
Notifications
You must be signed in to change notification settings - Fork 270
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
Ignore UPGRADE_INTERFACE_VERSION if selector returns anything other than "5.0.0" #926
Conversation
packages/plugin-hardhat/test/transparent-admin-unknown-interface.js
Outdated
Show resolved
Hide resolved
} | ||
|
||
fallback(bytes calldata) external returns (bytes memory) { | ||
return abi.encode(greeting); |
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.
Does it not work with a direct cast
return abi.encode(greeting); | |
return bytes(greeting); |
?
Using abi.encode
does an extra encapsulation. Not sure that is needed.
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.
It actually was needed to force the return type to look like a string in
if (offset !== 32) { |
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 nits
throw new Error(`Unexpected type for UPGRADE_INTERFACE_VERSION at address ${address}. Expected a string`); | ||
// Log as debug and return undefined if the interface version is not a string. | ||
// Do not throw an error because this could be caused by a fallback function. | ||
debug(`Unexpected type for UPGRADE_INTERFACE_VERSION at address ${address}. Expected a string`); |
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.
I'd suggest adding a test to make sure this is logged if possible although it's just debug data. Surely is something you'd like to see if you're doing a production deployment.
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.
Thanks, this revealed that the tests were testing the wrong scenario, which is fixed in the latest two commits.
Added tests for the debug logging by using optional parameters for the relevant functions where we pass in a stub. It's not my preferred approach but couldn't get mocks to work well with this otherwise.
Fixes #925
Fixes upgrading a proxy from an implementation that has a fallback function and is not using OpenZeppelin Contracts 5.0. Also handles the case where a custom proxy admin may have a similar fallback function.
The fallback function causes the UPGRADE_INTERFACE_VERSION selector to return a value which can be anything, so if it returns anything other than "5.0.0", we should treat it as a pre-5.0 interface.