# Corrupted storage after upgrade in the `MarketFactory` contract.

New `extensions` mapping inserted mid-layout in upgradeable MarketFactory shifts occupied storage slots, corrupting operators, markets and referral fees after upgrade.

- Payout: Audit contest
- Severity: medium
- Program: Perennial
- Found by: eeyore
- Disclosed: 2024-08-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/53
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-8
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:regression technique:source-review vuln:misconfiguration

**Target:** Upgradeable MarketFactory contract storage layout
**Root cause:** A new `extensions` mapping was declared between already-occupied storage slots in an upgradeable contract, so post-upgrade reads/writes of `extensions`, `operators`, `_markets`, and `_referralFees` hit shifted, stale slots.
**Steps:**
1. Compare old layout: `oracleFactory`, `_parameter`, `operators`, `_markets`, `referralFee`.
2. Compare new layout: `oracleFactory`, `verifier`, `_parameter`, `extensions`, `operators`, `_markets`, `_referralFees`, `signers`.
3. Observe `extensions` inserted before `operators`, shifting all subsequent slots.
4. Upgrade proxy to new implementation; existing slot data now misread as `extensions`/`operators`/`_markets`/`_referralFees`.
5. Fix: move `extensions` (and `signers`) after `_referralFees` so new vars append to unoccupied slots.
**How found:** Manual review comparing old vs new storage layouts of the upgradeable MarketFactory, spotting a mapping inserted between populated slots.
**Insight:** For upgradeable contracts, diff the full storage layout (including immutables vs slots and mapping positions) between deployed and new implementation; any variable inserted before existing state vars silently shifts every later slot.

