Skip to content
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

tool: support reinitializer in slither-check-upgradeability #2534

Closed
wants to merge 3 commits into from

Conversation

QiuhaoLi
Copy link
Contributor

Currently, the slither-check-upgradeability tool doesn't support the reinitializer in OZ's Initializable contract. For example, the CounterV2 below is a new implementation of Counter which adds a new storage variable and changed the changeX function:

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract Counter is Initializable {
    uint256 public x;

    function initialize(uint256 _x) public initializer {
        x = _x;
    }

    function changeX() public {
        x++;
    }
}

contract CounterV2 is Initializable {
    uint256 public x;
    uint256 public y;

    function initialize(uint256 _y) public reinitializer(2) {
        y = _y;
    }

    function changeX() public {
        x = x + y;
    }
}

Since slither-check-upgradeability can't recognize the reinitializer modifier, it will report a high-seveirity finding that the CounterV2.initialize(uint256) does not call the initializer modifier:

qiuhao@laptop:~/tmp/foundry_test/upgrade$ slither-check-upgradeability src/Counter.sol Counter --new-contract-name Counte
rV2
...
CounterV2.initialize(uint256) (src/Counter.sol#20-22) does not call the initializer modifier.
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializer-is-not-called

This PR supports the reinitializer modifier and fixes some tests for tests/tool/check_upgradeability.

@CLAassistant
Copy link

CLAassistant commented Aug 15, 2024

CLA assistant check
All committers have signed the CLA.

@0xalpharush
Copy link
Contributor

This was merged as part of #2536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants