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

Add storage gap to RewardsStreamerMP to reserve storage slots for future upgrades #131

Open
0x-r4bbit opened this issue Feb 19, 2025 · 0 comments

Comments

@0x-r4bbit
Copy link
Collaborator

The RewardsStreamerMP contract (aka stake manager) is upgradeable.

To reduce the likelihood of storage collisions in the future, for cases when new fields are added (like how it happened in #123 ), it's a recommended practice to introduce a storage gap.

The idea is to add a static array declaration to the contract, which reserves the same amount of storage slots as the size of the array.

contract ExampleV1 {
    uint256 public somProp;
    uint256 public someOtherProp;
}


contract ExampleV2 {
    uint256 public somProp;
    address someAddress; // <- oops collision!
    uint256 public someOtherProp;
}

// storage gap version
contract ExampleV1 {
    uint256 public somProp;
    uint256 public someOtherProp;
    uint256[50] private __gap; // <-- 50 reserved additional slots
}

// now adding an `address` field in between is fine:

contract ExampleV2 {
    uint256 public somProp;
    uint256 public someOtherProp;
    address someAddress;   
    uint256[49] private __gap; // <-- reduce gap by 1 slot!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment