Reproduced Exploit

Teller: liquidation books the original principal after part of it was repaid

A loan of 100 is repaid by 80 and then auctioned at 50. liquidateDefaultedLoanWithIncentive reads the original principal, 100, as the amount still due. That 100 is added to totalPrincipalTokensRepaid, which was already 80, and the liquidation difference is 50 - 100 = -50. Withdrawable value is 100…

Nov 2024•Ethereum•logic•3 min read

Loss

80 tokens stay trapped. Lenders can withdraw 50 of the 130 held, and new borrows underflow

Chain

Ethereum

Category

logic

Date

Nov 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: 44215-h-3-using-original-principal-amount-as-due-amount-inside-liq. Standalone Foundry PoC and full write-up: 44215-h-3-using-original-principal-amount-as-due-amount-inside-liq_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/state-update

Key info#

FieldValue
Loss80 tokens stay trapped. Lenders can withdraw 50 of the 130 held, and new borrows underflow
Vulnerable contractLenderGroup._getAmountOwedForBid
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-11
Compilersolc 0.8.27, cancun
Bug classamount due is the original principal, not the remainder

TL;DR#

A loan of 100 is repaid by 80 and then auctioned at 50. liquidateDefaultedLoanWithIncentive reads the original principal, 100, as the amount still due. That 100 is added to totalPrincipalTokensRepaid, which was already 80, and the liquidation difference is 50 - 100 = -50. Withdrawable value is 100 + (-50) = 50 while the contract holds 130. The 80 that accounting will not release stays in the group, and 100 - 180 underflows so no new borrow can be opened.

The vulnerable code#

SOLIDITY
function _getAmountOwedForBid(uint256 bidId) internal view returns (uint256 amountDue) {
    amountDue = principal[bidId]; // @> VULN: original principal, not principal minus repaidPrincipal
}

Use the remaining principal, principal[bidId] - repaidPrincipal[bidId]. On these numbers that is 20. Difference becomes 50 - 20 = +30, withdrawable becomes 130, and repaid principal ends at 100.

Root cause#

repayLoanCallback already added the 80 to totalPrincipalTokensRepaid. Liquidation adds the original 100 again because _getAmountOwedForBid ignores repaidPrincipal. The difference is also taken from the original principal, so the pool looks 50 short instead of 30 ahead.

Preconditions#

  • Principal, committed, and lended are 100. Repaid is 0. The contract holds no tokens yet.
  • A repayment of 80 arrives and is counted.
  • The auction settles at 50, which is pulled into the contract.

Attack walkthrough#

  1. openLoan records principal 100.
  2. repayLoanCallback adds 80 to repaid principal and pulls 80 tokens in.
  3. Liquidation reads amount due as 100, not 20.
  4. It adds 100 to repaid principal, now 180, and sets the difference to -50.
  5. availableToWithdraw is 50. The withdrawal pays 50 and leaves 80.
  6. getPrincipalAmountAvailableToBorrow computes 100 - 180 and reverts.
  7. The control, using the remaining 20, releases all 130.

Diagrams#

flowchart TD A["Loan principal 100"] --> B["80 principal is repaid and counted"] B --> C["Auction settles at 50"] C --> D["VULN amount due is the original 100"] D --> E["Repaid principal becomes 180 and difference is -50"] E --> F["Lenders withdraw 50 and 80 stays trapped"] F --> G["New borrows underflow"] D --> H["Control uses the remaining 20"] H --> I["Control releases all 130"]

Impact#

Lenders can take only 50 of the 130 tokens the group holds after this repay-and-liquidate. 80 is trapped by the withdraw cap. totalPrincipalTokensLended - totalPrincipalTokensRepaid underflows, so the group cannot accept another bid. The report's same root cause also breaks share pricing when the estimated value hits zero.

How to reproduce#

BASH
cd 44215-h-3-using-original-principal-amount-as-due-amount-inside-liq_exp
forge test -vv

output.txt is the captured passing run. The control test checks the recommended fix.

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.