Skip to content
Smart contracts Audit finding Intermediate

No storage gap for upgradeable contracts

The upgradeable abstract contracts SafeAccessControlEnumerableUpgradeable and SafeOwnableUpgradeable lack a storage gap, so if they later add new variables, those variables could overwrite storage in inheriting contracts. An attacker could not directly exploit this, but it could cause storage collisions and unexpected behaviour in upgraded contracts.

prePO contest

Originally disclosed on Code4rena

For SafeAccessControlEnumerableUpgradeable and SafeOwnableUpgradeable, which are upgradeable abstract contracts, inheriting contracts may introduce new variables. In order to be able to add new variables to the upgradeable abstract contract without causing storage collisions, a storage gap should be added to the upgradeable abstract contract.

If no storage gap is added, when the upgradable abstract contract introduces new variables, it may override the variables in the inheriting contract.

Proof of Concept

https://github.com/prepo-io/prepo-monorepo/blob/9ed5587e557a1189df6c5bb0229ad8c171eaabce/packages/prepo-shared-contracts/contracts/SafeAccessControlEnumerableUpgradeable.sol#L7-L9

https://github.com/prepo-io/prepo-monorepo/blob/9ed5587e557a1189df6c5bb0229ad8c171eaabce/packages/prepo-shared-contracts/contracts/SafeOwnableUpgradeable.sol#L7-L8

Recommended Mitigation Steps

Consider adding a storage gap at the end of the upgradeable abstract contract

uint256[50] private __gap;

prePO (sponsor) confirmed and resolved:

Fixed in PR 356.

cccz (warden) reviewed mitigation:

Fixed by adding uint256[50] private __gap in abstract upgradeable smart contracts to ensure no storage shifting down storage in the inheritance chain of the inheriting contracts.


The original report as published on Code4rena. 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 upgradeable abstract contracts did not reserve storage slots with a gap, so future variable additions could collide with inheriting contracts' storage.

Impact

If the abstract contracts are upgraded with new variables, they could overwrite variables in inheriting contracts, leading to storage collisions and potentially unexpected contract behaviour.

What the attacker needed

Upgradeable contracts; future upgrade adds variables

The fix

The issue was fixed by adding a storage gap array to the upgradeable abstract 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 keep their data in a fixed layout, like numbered slots. If a parent contract adds a new variable, it can take a slot that a child contract was already using, corrupting the child's data. This report says the parent contracts should reserve empty slots (a storage gap) to prevent that.

What is Smart contracts?

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

More from prePO 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.