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

Storage gaps mismanagement may corrupt contract state #455

Closed
code423n4 opened this issue Jan 20, 2023 · 3 comments
Closed

Storage gaps mismanagement may corrupt contract state #455

code423n4 opened this issue Jan 20, 2023 · 3 comments
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

Comments

@code423n4
Copy link
Contributor

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.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jan 20, 2023
code423n4 added a commit that referenced this issue Jan 20, 2023
@0xean
Copy link

0xean commented Jan 23, 2023

given that gaps aren't a strict requirement and more of a best practice to make things easier / less error prone, I am downgrading this issue to QA.

For more discussion on the topic see - code-423n4/org#55

@c4-judge c4-judge added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax downgraded by judge Judge downgraded the risk level of this issue and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 23, 2023
@c4-judge
Copy link
Contributor

0xean changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

0xean marked the issue as grade-c

@c4-judge c4-judge added unsatisfactory does not satisfy C4 submission criteria; not eligible for awards grade-c labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants