Potential Storage Collision Due to Missing Storage Gaps in Upgradeable Contracts
In the current implementation of the Swan
and SwanManager
contracts, which utilize the UUPS upgradeable pattern, there are missing storage gaps (__gap
) that are crucial for maintaining a consistent storage layout across contract upgrades. This omission can lead to potential storage collisions when adding new state variables in future upgrades.
In upgradeable contracts using the UUPS pattern, it is vital to maintain storage alignment between the contract versions. Currently, the Swan
and SwanManager
contracts lack reserved storage slots (__gap
), which means that any newly added state variables in a contract upgrade may overwrite existing variables. This can corrupt the contract state, leading to unintended and unpredictable behavior.
When a new version of the Swan
contract is deployed with additional state variables:
Without a storage gap, the new variables might overwrite existing storage slots occupied by inherited contracts.
This scenario can lead to unintended overwriting of critical data such as ownership information or mappings.
State Corruption: Critical variables, such as ownership or mappings, could be overwritten, resulting in the loss of state integrity and potential contract failure.
Security Breaches: Attackers might exploit the corrupted state to gain unauthorized access or manipulate contract data maliciously.
Contract Failure: The contract could become unusable due to inconsistent state, affecting all users of the system and causing irreparable data loss.
Manual code review
Reference to OpenZeppelin upgradeability best practices
Introduce Storage Gaps:
Add a storage gap to both the SwanManager
and Swan
contracts to reserve storage slots for future variable additions.
Follow OpenZeppelin's Guidelines:
Ensure that the storage layout remains consistent and compatible across upgrades.
Avoid changing the order or types of existing state variables to prevent misalignment issues during future contract upgrades.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.