# Users redeeming early will withdraw `Ra` without decreasing the amount locked, which will lead to stolen funds when withdrawing after expiry

Cork Protocol's early LV redemption burns Ct/Ds for Ra but never decrements locked Ra, so later redemptions over-withdraw and drain funds from last users.

- Payout: Audit contest
- Severity: high
- Program: Cork Protocol
- Found by: 0x73696d616f
- Disclosed: 2024-08-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/166
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-cork-protocol%3AH-10
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Depeg-swap Vault/Psm Solidity contracts
**Root cause:** PsmLib::lvRedeemRaWithCtDs burns Ct/Ds and releases Ra to the redeemer but never calls RedemptionAssetManagerLib::decLocked, so the tracked locked Ra stays inflated.
**Steps:**
1. Call `Vault::redeemEarlyLv()` which routes to `VaultLib::redeemEarly()` -> `_redeemCtDsAndSellExcessCt()` -> `PsmLib::lvRedeemRaWithCtDs(amount, dsId)`.
2. Observe `lvRedeemRaWithCtDs` only calls `ds.burnBothforSelf(amount)`; no `self.psm.balances.ra.decLocked(amount)`.
3. Later, on `issueNewDs` or `PsmLib::redeemWithCt()`, `_separateLiquidity()` calls `self.psm.balances.ra.convertAllToFree()` treating the already-withdrawn Ra as still locked.
4. Checkpoint Ra/Pa is inflated; users redeeming via `redeemWithCt()` receive more Ra than entitled, leaving last redeemers unable to withdraw.
**How found:** Code review of the early-redemption path: noticed Ra leaves the Vault in `lvRedeemRaWithCtDs` but the locked-Ra counter is never decremented, then traced how `_separateLiquidity`/`convertAllToFree` trusts that stale counter.
**Exploitation:** Attacker redeems Lv early to pull Ra out while locked accounting stays unchanged, then redeems Ct/Ds after expiry against the inflated checkpoint to extract more Ra than owed, front-running honest users who are left short.
**Insight:** When a protocol tracks 'locked' vs 'free' balances separately from actual token balances, audit every path where the asset physically leaves the contract and confirm the corresponding counter is decremented—missing decLocked silently inflates solvency for all later redemptions.

## Proof of concept (copied exactly from the original report)

**PoC: lvRedeemRaWithCtDs missing decLocked**

```
function lvRedeemRaWithCtDs(State storage self, uint256 amount, uint256 dsId) internal {
    DepegSwap storage ds = self.ds[dsId];
    ds.burnBothforSelf(amount);
}
```

