WTF-Solidity
WTF-Solidity copied to clipboard
[Improvement][47_Upgrade] preventing invalid contract upgrade
Description
In the upgrade function, we can add a check to prevent upgrading to the same implementation address.
require(implementation != newImplementation, "Can not upgrade to the same implementation");
The relevant code is as follows:
// 升级函数,改变逻辑合约地址,只能由admin调用
function upgrade(address newImplementation) external {
require(msg.sender == admin);
require(implementation != newImplementation, "Can not upgrade to the same implementation");
implementation = newImplementation;
}
Are you willing to submit a PR?(你愿意提交PR吗?)
- [X] Yes I am willing to submit a PR!(是的我愿意)