Corruptible Upgradability Pattern
Several upgradeable contracts in the project do not reserve storage space with gap variables, so adding new state variables during a future upgrade could overwrite existing storage slots. This could corrupt contract state and cause core functionality to fail or behave unexpectedly.
- Disclosed after under an hour
#45368 [SC-Insight] Corruptible Upgradability Pattern
Submitted on May 13th 2025 at 11:10:07 UTC by @Anirruth for Audit Comp | Flare | FAssets
- Report ID: #45368
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/flare-labs-ltd/fassets/blob/main/docs/ImmunefiScope.md
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
- Corruptible Upgradability Pattern
Description
Brief/Intro
Upgradeable smart contracts without proper storage gaps present a critical vulnerability where storage collisions can occur during contract upgrades. When new variables are added contract during an upgrade, they can overwrite existing variables, corrupting the contract state
Vulnerability Details
The vulnerability occurs when upgradeable contracts fail to implement storage gaps (__gap) to reserve space for future state variables. If the owner performs an upgrade and wants to add a new variable the storage slots would be overwritten. The following contract are upgradable contracts but doesn't implement storage gaps : CoreVaultManager, FAsset, AssetManagerController, CollateralPool.
Impact Details
Storage collisions can cause contract variables to be overwritten or misread, leading to corrupted state and unexpected behavior. The entire contract logic may be compromised, causing core functionalities to fail or behave unexpectedly.
References
Implement uint[50] private __gap; for the upgradable contracts mentioned above.
Proof of Concept
Proof of Concept
- The owner wants to upgrade the contract and wants to introduce new variables.
- Without gaps, the newly introduces variable would overwrite existing storage slots and corrupt the variables.
- With storage gaps the new variables could use the gap storage slots.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the upgradeable contracts were written without reserved storage gap arrays, leaving no room for future state variables in the storage layout.
Impact
Storage collisions could corrupt contract state and cause core functionality to fail or behave unexpectedly, though the report rates this as an insight rather than a demonstrated loss of funds.
What the attacker needed
Contract owner performs an upgrade; new state variables are added
The fix
The upgradeable contracts should reserve storage space by declaring a private gap array of unused slots.
How it was found
- The owner upgrades the contract and introduces new variables.
- Because no gaps exist, the new variable overwrites an existing storage slot.
- The overwritten variable is corrupted, changing contract behaviour.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Upgradeable contracts keep their data in numbered storage slots, and an upgrade can add new variables. If no empty slots are reserved in advance, a new variable can land on a slot already used by an old one and overwrite its value. A storage gap is a block of unused slots kept in reserve so future variables have somewhere safe to go.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.