Corruptible Upgradability Pattern
Several upgradeable vault contracts inherit from base contracts that lack storage gap slots, so adding new variables to those base contracts could overwrite storage in child contracts. This could corrupt the vault's storage during an upgrade, leading to critical misbehaviour.
0xadrii Follow with Hunter, NoOneWinner and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-midas-minter-redeemer-judging/issues/103
Found by
0xadrii, Hunter, NoOneWinner, WildSniper, aslanbek, eeshenggoh, eeyore, pandasec, pkqs90
Summary
Storage of vault contracts (e.g. DepositVault, RedemptionVault, ...) contracts might be corrupted during an upgrade.
Vulnerability Detail
Following is the inheritance of the DepositVault/RedemptionVault contracts.
Note: The contracts highlighted in Orange mean that there are no gap slots defined. The contracts highlighted in Green mean that gap slots have been defined
graph BT;
classDef nogap fill:#f96;
classDef hasgap fill:#99cc00;
DepositVault:::hasgap-->ManageableVault:::hasgap
RedemptionVault:::hasgap-->ManageableVault:::hasgap
ManageableVault:::hasgap-->Pausable:::nogap
ManageableVault:::hasgap-->Greenlistable:::nogap
ManageableVault:::hasgap-->Blacklistable:::nogap
ManageableVault:::hasgap-->WithSanctionsList:::nogap
Pausable:::nogap-->WithMidasAccessControl:::gap
Greenlistable:::nogap-->WithMidasAccessControl:::gap
Blacklistable:::nogap-->WithMidasAccessControl:::gap
WithSanctionsList:::nogap-->WithMidasAccessControl:::hasgap
The vault contracts are meant to be upgradeable. However, it inherits contracts that are not upgrade-safe.
The gap storage has been implemented on the DepositVault/RedemptionVault/ManageableVault/WithMidasAccessControl.
However, no gap storage is implemented on Pausable/Greenlistable/Blacklistable/WithSanctionsList. Among these contracts, Pausable/Greenlistable/WithSanctionsList are contracts with defined variables (non pure-function), and they should have gaps as well.
Without gaps, adding new storage variables to any of these contracts can potentially overwrite the beginning of the storage layout of the child contract, causing critical misbehaviors in the system.
Note that during the last sherlock audit, this was also reported as an issue. It was fixed by adding gaps to the non-pure contracts. However, since that audit, new contracts and new variables are introduced, so this issue occurs again.
Also, CustomAggregatorV3CompatibleFeed does not have gaps but is inherited by MBasisCustomAggregatorFeed/MTBillCustomAggregatorFeed. If the feed wants to be upgradeable, CustomAggregatorV3CompatibleFeed should also have gaps.
Impact
Storage of vault contracts might be corrupted during upgrading.
Code Snippet
- https://github.com/sherlock-audit/2024-08-midas-minter-redeemer/blob/main/midas-contracts/contracts/access/Greenlistable.sol#L22
- https://github.com/sherlock-audit/2024-08-midas-minter-redeemer/blob/main/midas-contracts/contracts/access/Pausable.sol#L14
- https://github.com/sherlock-audit/2024-08-midas-minter-redeemer/blob/main/midas-contracts/contracts/abstract/WithSanctionsList.sol#L18
Tool used
Manual review
Recommendation
Add gaps for non pure-function contracts: Pausable/Greenlistable/WithSanctionsList/CustomAggregatorV3CompatibleFeed.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
merlinboii commented:
Known Issue from the past audit contest and as the past issue there is no gap for several functions and the platform should to fix with the contract that they is decided to more potential to be changes. Assume that it is known issue and sponspor intended to design which contracts that they shoul introduce the gap.
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/RedDuck-Software/midas-contracts/pull/64
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 base contracts Pausable, Greenlistable, WithSanctionsList, and [redacted] were not designed with storage gaps, so they are not upgrade-safe.
Impact
Storage of vault contracts might be corrupted during upgrading.
What the attacker needed
Contracts are upgradeable; new variables added to base contracts
The fix
The protocol team fixed this issue by adding gaps to the non-pure contracts.
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 smart contracts use a pattern where each base contract reserves extra storage slots (called gaps) so that future versions can add variables without shifting the layout. If a base contract lacks these gaps, adding a new variable can overwrite data stored by a child contract, corrupting the contract's state. This report points out that several base contracts in the vault system are missing these gaps.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.