Reproduced Exploit

Fungify interest payment spends cToken collateral and leaves 8.5 DAI of bad debt

payInterestInternal is the quoted function. It checks payInterestAllowed, converts the interest at the stored exchange rate, and subtracts the cTokens from the payer if the raw balance is large enough. It does not ask whether the payer's remaining collateral still covers their borrow.

Nov 2023•Ethereum•logic•2 min read

Loss

8.5 DAI of bad debt. The borrower keeps 8.5 DAI after payInterestInternal removes the 10 ether of cToken coll…

Chain

Ethereum

Category

logic

Date

Nov 2023

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack replays in your browser. Step through it by Solidity line or by opcode.

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: 62380-fng-17-cerc20interestmarket-collateral-can-be-directly-used. Standalone Foundry PoC and full write-up: 62380-fng-17-cerc20interestmarket-collateral-can-be-directly-used_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/missing-check · vuln/defi/bad-debt

Key info#

FieldValue
Loss8.5 DAI of bad debt. The borrower keeps 8.5 DAI after payInterestInternal removes the 10 ether of cToken collateral that backed it
Vulnerable contractCErc20InterestMarket.payInterestInternal
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit at 0x15452ec016c4dc8c549e7fe6ff4b26324ea8b7a4
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2023-11
Compilersolc 0.8.27, cancun, via IR
Bug classCollateral is reduced without Comptroller.isRedeemAllowed
flowchart TD A["Borrower posts 10 ether of cToken collateral"] --> B["Borrow 8.5 DAI at the 85 percent factor"] B --> C["payInterestInternal converts 10 ether of interest into cTokens"] C --> D["VULN accountTokens payer is set to 0 with no health check"] D --> E["badDebt is 8.5 DAI and the borrower keeps the DAI"] C --> F["Control calls isRedeemAllowed"] F --> G["Payment reverts, collateral stays 10 ether, badDebt stays 0"]

TL;DR#

payInterestInternal is the quoted function. It checks payInterestAllowed, converts the interest at the stored exchange rate, and subtracts the cTokens from the payer if the raw balance is large enough. It does not ask whether the payer's remaining collateral still covers their borrow.

The payer has 10 ether of cTokens and has borrowed 8.5 DAI, the maximum the 85 percent factor allows. Paying 10 ether of interest at a 1e18 exchange rate zeros the collateral. badDebt becomes 8.5 ether. The DAI has already been sent to the attacker.

The fixed market calls isRedeemAllowed first. That returns a non-zero code because zero remaining collateral cannot cover 8.5 DAI, the call reverts, and badDebt stays 0.

The vulnerable code#

SOLIDITY
uint256 balancePayer = accountTokens[payer];
require(balancePayer >= interestTokens, "insufficient payer reserve");
accountTokens[payer] = balancePayer - interestTokens; // @> VULN: collateral is reduced with no isRedeemAllowed health check

Impact#

The protocol is owed 8.5 DAI and holds none of the payer's collateral against it. The attacker keeps the 8.5 DAI. A redeem of the same 10 ether of cTokens would have been rejected.


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.