Reproduced Exploit
Cork: repurchase pulls RA and does not lock it
Deposit uses lockFrom, which increases locked and pulls RA. Repurchase uses lockUnchecked, which only pulls RA. After a DS plus PA redeem has brought locked back to 0, a 1000 RA repurchase leaves the tokens in the contract and locked at 0. At expiry, separateLiquidity archives 0. Redeeming the cove…
Loss
1000 RA stuck in the PSM. The CT redemption pays 0
Chain
Ethereum
Category
logic
Date
Aug 2024
Source
AuditVault
EVM Playground
Source-level debugger — step opcodes and Solidity in sync
The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc. Standalone Foundry PoC and full write-up: 41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/logic/state-update·vuln/dos/frozen-funds
Key info#
| Field | Value |
|---|---|
| Loss | 1000 RA stuck in the PSM. The CT redemption pays 0 |
| Vulnerable contract | Psm.repurchase |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2024-08 |
| Compiler | solc 0.8.27, cancun, via IR |
| Bug class | Incoming RA transferred without increasing locked |
TL;DR#
Deposit uses lockFrom, which increases locked and pulls RA. Repurchase uses lockUnchecked, which only pulls RA. After a DS plus PA redeem has brought locked back to 0, a 1000 RA repurchase leaves the tokens in the contract and locked at 0. At expiry, separateLiquidity archives 0. Redeeming the cover token pays nothing. Calling lockFrom from repurchase archives the 1000 RA and pays it to the CT holder.
Background#
Sherlock's August 2024 Cork contest, issue 126, reported by dimulski and several others. PsmLib.repurchase transfers redemption assets with lockUnchecked instead of lockFrom. After expiry, _separateLiquidity archives convertAllToFree(), which only knows about locked. The team fixed it in Cork-Technology/Depeg-swap pull 77.
The vulnerable code#
function lockUnchecked(uint256 amount, address from) internal {
ra.transferFrom(from, address(this), amount); // @> VULN: locked is not increased
}
lockFrom does locked += amount and then the same transfer. _separateLiquidity stores convertAllToFree() and resets the balances.
Root cause#
The repurchase inflow is a token transfer with no matching write to the variable expiry later treats as the whole RA inventory.
Preconditions#
- A deposit has minted CT and a DS plus PA redeem has returned
lockedto 0 while the CT supply remains. - The market expiry is this block, so
separateLiquidityis allowed. - The user repurchases with 1000 RA.
Attack walkthrough#
- Deposit locks 1000 RA, mints 1000 CT and 1000 DS.
- Redeeming DS plus PA unlocks the RA and leaves the CT in place.
- Repurchase pulls 1000 RA through
lockUnchecked.lockedstays 0. separateLiquidityarchives 0.redeemWithCtpays 0. The PSM still holds 1000 RA.
Diagrams#
Impact#
The cover-token holder receives none of the RA that was paid in at repurchase. 1000 RA remains in the PSM and is absent from the archive, so no later CT redemption can claim it. The lockFrom control archives 1000 RA, pays it out, and leaves the PSM empty.
How to reproduce#
cd 41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc_exp
forge test -vv
test_exploit_ra_stuck asserts a 0 archive, a 0 CT payout, and 1000 RA stuck. test_control_lockFrom_archives_ra asserts the full payout. Output is output.txt.
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc.md
- Sherlock issue 126: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/126
- PsmLib repurchase: https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/libraries/PsmLib.sol
- Fix: https://github.com/Cork-Technology/Depeg-swap/pull/77
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc_exp (evm-hack-registry mirror).
- AuditVault finding: 41479-h-5-incoming-redemption-assets-not-being-tracked-when-repurc.
Alerts & third-party analyses
These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.