What exactly is the reason for `uint256[50] private ______gap;`?

What exactly is the reason for uint256[50] private ______gap;, which can be found at the bottom of every contract in OpenZeppelin-ETH?

1 Like

https://github.com/OpenZeppelin/openzeppelin-eth/issues/47
Since OpenZeppelin contracts are used by inheritance, user-defined variables will be placed by the compiler after OpenZeppelin's ones. If, in a newer version, new variables are added by the library, the storage layouts would be incompatible, and an upgrade would not be possible.

The gap is a workaround to that issue: by leaving a 50-slot gap, we're able to increase the contract's storage by that amount (provided we also remove the same slots from the gap) with no clashing issues.

5 Likes