Storage gaps mismanagement may corrupt contract state #455
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
grade-c
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/Furnace.sol#L108
Vulnerability details
Impact
Mismanagement of storage gaps in All upgradable contracts within scope may cause a corrupted storage state of a contract that inherits from it, due to shifted storage slots. Link provided (
furnace.sol
) is one instance, however every upgradable contract has a different sized storage slot.Proof of Concept
Most every upgradable contract uses a different sized '_gap' for future upgrades.
For example in
furnace.sol
If the initial number of storage gaps was 47, then the current number should be 47 reserves slots - 5 used slots = 42. If this mistake is made during upgrading of a deployed contract, then storage slots of the contract that inherits from another contract could shift up by an unexcpected amount, which will corrupt the state of the contract.Recommended Mitigation Steps
It is recomended that you use an identical number of storage gaps in all upgradeable contracts. Also ensure that the number is only decremented when a new state variable is added, there is never a reason for it to increment.
The text was updated successfully, but these errors were encountered: