Reproduced Exploit

Cryptex: liquidation seizes collateral twice because the debt is never reduced

liquidate sends the user's collateral to the liquidator and burns TCAP. It never calls modifyPosition, so debtOf stays 1000. The borrower can deposit another 1000 and be liquidated again. The liquidator finishes with 2000 collateral. The borrower still owes 1000 and has none. The control subtracts…

Sep 2024•Ethereum•logic•3 min read

Loss

2000 collateral taken while the borrower still owes 1000

Chain

Ethereum

Category

logic

Date

Sep 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

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.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 40212-liquidated-person-s-debts-are-not-reduced-in-liquidation-can. Standalone Foundry PoC and full write-up: 40212-liquidated-person-s-debts-are-not-reduced-in-liquidation-can_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/liquidation-logic · vuln/logic/state-update

Key info#

FieldValue
Loss2000 collateral taken while the borrower still owes 1000
Vulnerable contractVault.liquidate
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-09
Compilersolc 0.8.27, cancun, via IR
Bug classMissing modifyPosition after a liquidation payout

TL;DR#

liquidate sends the user's collateral to the liquidator and burns TCAP. It never calls modifyPosition, so debtOf stays 1000. The borrower can deposit another 1000 and be liquidated again. The liquidator finishes with 2000 collateral. The borrower still owes 1000 and has none. The control subtracts the burned amount from the debt, so the second liquidation reverts and the borrower keeps the second 1000.

Background#

Cantina's September 2024 Cryptex review of Vault.sol. The proof logs collateral at 0 after liquidate while mintedValueOfUser is unchanged. The recommended line is modifyPosition(_toMintId(user, pocketId), -burnAmount). Cryptex fixed it in commits 50c7925a and 441a8137.

The vulnerable code#

SOLIDITY
// @> VULN: modifyPosition is skipped, so debtOf[user] stays and the position can be liquidated again
pocket.withdraw(user, liquidationReward, msg.sender);
TCAPV2.burn(msg.sender, burnAmount);
emit Liquidated(msg.sender, user, pocketId, liquidationReward, burnAmount);

Root cause#

The payout and the burn are not paired with an update of the liquidated position. The position stays underwater for as long as any collateral is added later.

Preconditions#

  • The borrower has 1000 collateral and 1000 debt, and the position is liquidatable.
  • The liquidator holds TCAP equal to the burn amount, as in the report's proof, which mints TCAP to the caller.
  • liquidate is callable by that liquidator. It is not an owner action.

Attack walkthrough#

  1. The borrower opens a 1000 collateral / 1000 debt position. The pocket holds the 1000.
  2. The first liquidate burns 1000 TCAP and sends the 1000 collateral to the liquidator. Debt stays 1000.
  3. The borrower deposits another 1000. Debt is still 1000, so the position is liquidatable.
  4. The second liquidate sends that 1000 as well.
  5. The liquidator holds 2000. The borrower holds 0 and still owes 1000.

Diagrams#

flowchart TD A["Borrower opens 1000 collateral and 1000 debt"] --> B["First liquidate pays the 1000 out"] B --> C["VULN skips modifyPosition so the debt stays 1000"] C --> D["Borrower deposits another 1000"] D --> E["Second liquidate seizes that 1000 too"] E --> F["Liquidator holds 2000 and the debt is still 1000"] C --> G["Control subtracts burnAmount from the debt"] G --> H["Second liquidate reverts and the borrower keeps 1000"]

Impact#

The liquidator receives 2000 collateral for a 1000 debt that is never cleared. The extra 1000 is collateral the control leaves with the borrower. The borrower has no collateral and still owes 1000.

Remediation#

Before the payout, call modifyPosition with -burnAmount, as in the Cantina recommendation, and refuse a second liquidation once the debt is zero.

How to reproduce#

BASH
cd 40212-liquidated-person-s-debts-are-not-reduced-in-liquidation-can_exp
forge test -vv

test_exploit_second_liquidation_seizes_another_1000 asserts 2000 seized and debt still 1000. test_control_clearing_debt_stops_the_second_seizure asserts the second call reverts and the borrower keeps 1000. Captured output is output.txt.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

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.