# Incoming Redemption Assets not being tracked when repurchase is called

Cork Protocol's repurchase() transfers redemption assets in via lockUnchecked without updating the locked accounting, so post-expiry _separateLiquidity archives too little RA and funds get stuck.

- 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/126
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-cork-protocol%3AH-5
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error

**Target:** PsmLib repurchase() / PsmRedemptionAssetManager accounting
**Root cause:** repurchase() moves incoming redemption asset via lockUnchecked() instead of lockFrom(), so the PsmRedemptionAssetManager.locked counter is not incremented for that inflow.
**Steps:**
1. User deposits RA, receives CT + DS.
2. User redeems via DS + Pegged Asset path (before expiry).
3. User calls repurchase() paying RA to get DS + PA back; RA enters contract via lockUnchecked() without incrementing locked.
4. After DS expiry, redeemWithCt() triggers _separateLiquidity(), which converts only tracked RA to free and archives it, then resets balances.
5. Actual RA balance exceeds archived amount; surplus RA remains stuck in contract.
**How found:** Code review of all RA inflow/outflow paths (deposit, redeem variants) versus the locked counter; noticed repurchase() used lockUnchecked() rather than lockFrom(), breaking the invariant that every RA inflow increments locked.
**Exploitation:** Any user performing the repurchase flow before expiry causes the protocol's internal RA accounting to under-count; after expiry the untracked RA is excluded from poolArchive and stranded, a direct loss of funds to the protocol/users.
**Insight:** When auditing accounting structs with locked/free counters, enumerate every token inflow/outflow path and verify each uses the tracking helper; unchecked-transfer helpers are a common source of accounting drift that only manifests at a later settlement/reset step.

