Skip to content

Latest commit

 

History

History
49 lines (29 loc) · 2.39 KB

File metadata and controls

49 lines (29 loc) · 2.39 KB

Energetic Opaque Elephant

Medium

Lack of Storage Gap Will Cause Storage Conflicts in WeightedIndex Contract

Summary

The WeightedIndex contract is designed as an upgradeable contract but lacks the implementation of a storage gap. This omission could result in storage conflicts during future upgrades, potentially corrupting data or introducing critical bugs. Including a storage gap would safeguard the contract against such issues, even if the protocol currently does not foresee upgrades.

Root Cause

The WeightedIndex contract inherits from OpenZeppelin’s Initializable, indicating it is part of an upgradeable contract system. However, it does not include a storage gap to account for future state variable additions. Without a storage gap, any new variables added during an upgrade could overwrite existing storage slots, causing storage collisions.

Internal Pre-conditions

  1. The contract is deployed as an upgradeable contract via a proxy.
  2. Future upgrades to the contract may introduce new state variables.

External Pre-conditions

No response

Attack Path

  1. The contract is upgraded with new state variables.
  2. Storage collisions occur because the new state variables overwrite existing storage slots.
  3. This corruption could lead to loss of data, unexpected behavior, or vulnerabilities in the contract.

Impact

The WeightedIndex contract will suffer from storage conflicts during upgrades, leading to data corruption or critical bugs. This can result in disrupted functionality or vulnerabilities that attackers could exploit.

PoC

No response

Mitigation

Introduce a storage gap in the WeightedIndex contract by appending an unused fixed-size array at the end of the storage layout, as shown below:

contract WeightedIndex is Initializable, IInitializeSelector, DecentralizedIndex {  
    // Storage gap for upgradeability  
+   uint256[50] private __gap;  
}

Even if the protocol does not foresee upgrades, adding a storage gap is a precautionary measure that ensures safe upgrades in the future if the need arises.