No Storage Gap for Upgradeable Contracts #410
Labels
bug
Something isn't working
disagree with severity
Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments)
duplicate
This issue or pull request already exists
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-10-blur/blob/main/contracts/BlurExchange.sol#L30
Vulnerability details
Impact
For upgradeable contracts, inheriting contracts may introduce new variables. In order to be able to add new variables to the upgradeable contract without causing storage collisions, a storage gap should be added to the upgradeable acontract.
If no storage gap is added, when the upgradable contract introduces new variables,
it may override the variables in the inheriting contract.
Storage gaps are a convention for reserving storage slots in a base contract, allowing future versions of that contract to use up those slots without affecting the storage layout of child contracts.
To create a storage gap, declare a fixed-size array in the base contract with an initial number of slots.
This can be an array of uint256 so that each element reserves a 32 byte slot. Use the naming convention __gap so that OpenZeppelin Upgrades will recognize the gap:
Classification for a similar problem:
https://code4rena.com/reports/2022-05-alchemix/#m-05-no-storage-gap-for-upgradeable-contract-might-lead-to-storage-slot-collision
Openzeppelin Storage Gaps notification:
Proof of Concept
BlurExchange contract is intended to be upgradeable, including the inherited contracts ReentrancyGuarded, EIP712, OwnableUpgradeable, UUPSUpgradeable
However, neither ReentrancyGuarded nor the EIP712 or OwnableUpgradeable contract contains storage gaps.
The BlurExchange contract contains storage variables, therefore the base contracts ReentrancyGuarded and EIP712 or OwnableUpgradeable cannot be upgraded to include any additional variables because it would overwrite the variables declared in the child contract BlurExchange. This greatly limits contract upgradeability.
Recommended Mitigation Steps
Consider adding a storage gap at the end of the upgradeable abstract contract
The text was updated successfully, but these errors were encountered: