# Vault.settle(account=coordinator) will lose profitShares

Vault.settle() credits profitShares to coordinator in storage, but _saveContext later overwrites them with stale in-memory shares when account==coordinator, losing the coordinator's profit shares.

- Payout: Audit contest
- Severity: medium
- Program: Perennial
- Found by: 0x1982us
- Disclosed: 2025-01-14
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-01-perennial-v2-4-update-judging/issues/24
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-perennial-v2-4-update%3AM-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Vault.sol settle/_credit/_saveContext accounting
**Root cause:** _credit() writes profitShares directly to storage for the coordinator account but does not update context.local.shares; when account==coordinator, _saveContext() later stores the stale context.local over the credited value.
**Steps:**
1. Call `Vault.settle(account=coordinator)` while checkpoints are pending.
2. In `_settle`, `_credit(coordinator, profitShares)` stores `_accounts[coordinator].shares += profitShares`.
3. `context.local.shares` for coordinator remains unchanged (e.g. 0).
4. `_saveContext` executes `_accounts[account].store(context.local)` with account==coordinator, overwriting the credited shares with the stale value.
5. Coordinator loses the profitShares.
**How found:** Code reading of settle/_credit/_saveContext flow: noticed _credit writes storage but not context.local.shares, and _saveContext overwrites storage for the same account when account==coordinator.
**Exploitation:** Any caller can trigger settle with account=coordinator; the coordinator's accrued profitShares are silently zeroed by the stale memory write, causing loss of protocol/coordinator profit accounting.
**Insight:** When a function both mutates storage directly and later flushes a cached memory struct to the same slot, check for aliasing where the target account equals the context account; the stale memory write silently reverts the direct credit.

