WTF-Solidity icon indicating copy to clipboard operation
WTF-Solidity copied to clipboard

[Improvement][47_Upgrade] preventing invalid contract upgrade

Open phoouze opened this issue 1 year ago • 0 comments

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!(是的我愿意)

phoouze avatar Oct 09 '24 09:10 phoouze