Skip to content
Smart contracts Audit finding Intermediate

SmartAccount.sol is intended to be upgradable but inherits from contracts that contain storage and no gaps

SmartAccount.sol is an upgradable contract that inherits from contracts with storage but no storage gaps, which could cause storage slot collisions when upgrading. An attacker or owner could upgrade to a broken implementation, potentially corrupting storage and causing loss of funds or functionality.

0x52 Follow with IllIllI, Diana and 11 others

Originally disclosed on Code4rena

Submitted by 0x52, also found by IllIllI, Diana, cryptostellar5, oyc_109, 0xSmartContract, SleepingBugs, adriro, Deivitto, V_B, betweenETHlines, peanuts, Koolex, and Rolezn

contracts/smart-contract-wallet/base/ModuleManager.sol#L18

SmartAccount.sol inherits from contracts that are not stateless and don’t contain storage gaps which can be dangerous when upgrading.

Proof of Concept

When creating upgradable contracts that inherit from other contracts is important that there are storage gap in case storage variable are added to inherited contracts. If an inherited contract is a stateless contract (i.e. it doesn’t have any storage) then it is acceptable to omit a storage gap, since these function similar to libraries and aren’t intended to add any storage. The issue is that SmartAccount.sol inherits from contracts that contain storage that don’t contain any gaps such as ModuleManager.sol. These contracts can pose a significant risk when updating a contract because they can shift the storage slots of all inherited contracts.

Recommended Mitigation Steps

Add storage gaps to all inherited contracts that contain storage variables.

livingrockrises (Biconomy) commented:

Regarding storage gaps I want to bring this up.

SmartAccount first storage is Singleton(first inherited contract) that says // singleton slot always needs to be first declared variable, to ensure that it is at the same location as in the Proxy contract.

“In case of an upgrade, adding new storage variables to the inherited contracts will collapse the storage layout.” Is this still valid?

livingrockrises (Biconomy) acknowledged

livingrockrises (Biconomy) commented:

Would like to hear judge’s views on fixing this and upgradeability as a whole.

gzeon (judge) commented:

Would like to hear judge’s views on fixing this and upgradeability as a whole.

Immediately actionable items would be to use the upgradable variant of OZ contract when available; ModuleManager should also be modified to include a storage gap.

Since the proxy implementation is upgradable by the owner (which can be anyone aka not a dev), it would be nice to implement UUPS like safe-rail (as mentioned in #352) to prevent the user upgrading to a broken implementation irreversibly.

Will also add that lack of storage gap is not typically a Med issue, but considering this contract has a mix of storage gapped and non-storage gapped base contract, and a risky upgrade mechanism, it is considered as Med risk in this contest.


The original report as published on Code4rena, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 inherited contracts (e.g., ModuleManager) contain storage variables but do not reserve storage gaps, so adding new variables in an upgrade would shift storage slots of other inherited contracts.

Impact

If an upgrade adds storage variables to an inherited contract without a gap, the storage layout could collapse, potentially rendering the contract unusable or causing loss of funds; the judge noted this is typically not a medium issue but considered medium here due to the mix of gapped and non-gapped bases and a risky upgrade mechanism.

What the attacker needed

Contract is upgradable; owner upgrades to new implementation

The fix

Add storage gaps to all inherited contracts that contain storage variables, and use upgradable variants of OpenZeppelin contracts where available.

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.

Upgradable smart contracts use a proxy pattern where the storage layout must stay consistent across upgrades. If a base contract adds new variables without reserving space (a storage gap), the positions of existing variables can shift, corrupting data. This report points out that some inherited contracts lack such gaps, risking storage collisions during upgrades.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0x52

View all

211 more disclosed reports, best first.

More from Biconomy - Smart Contract Wallet contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.