Gravitational plate of three masses and a slashed discABC0Static engraved plate. Three-dimensional view is unavailable or reduced motion is requested.

← back to fieldarticle

articleDec 16, 2022

Damn Vulnerable DeFi — Side entrance (high-level)

DVDeFi Challenge 4 Side entrance: flash-loan repayment checked only as ETH balance, while deposit() credits balances mapping—accounting mismatch class. High-level only.

Damn Vulnerable DeFi — Challenge #4 Side entrance (high-level)

Educational wargame challenge: a simple lending pool holds ETH, offers free flash loans, and also exposes open deposit / withdraw against an internal balances mapping. Lab goal: take the pool’s ETH.

Vulnerability class / root cause

  • Flash-loan repayment is validated by contract ETH balance after the callback—not by a dedicated repayment accounting path.
  • Separately, deposit() credits the caller in balances, and withdraw() pays out from that mapping.
  • If flash-loaned ETH is “repaid” by calling deposit during the callback, the pool’s raw ETH balance looks restored while the attacker also gains a credited withdrawable balance—an accounting mismatch / confused deputy between balance checks and bookkeeping.

Impact (abstract)

Pool liquidity can be withdrawn by someone who never made a real economic deposit, emptying the lending pool.

Mitigations / lessons

  • Track flash-loan debt explicitly; do not treat “ETH balance back to baseline” as proof of repayment if deposit can inflate the same balance.
  • Separate flash-loan liquidity from user deposit accounting, or disallow deposit/withdraw during an open flash loan.
  • Add invariants: sum of balances ≤ idle funds not reserved for flash accounting.
  • Audit any pattern where multiple entry points mutate the same asset pool under different meanings.

Solve steps and PoC omitted.

related

  1. Dec 25, 2022/articleDamn Vulnerable DeFi — Free Rider (msg.value reuse in NFT marketplace)
  2. Dec 21, 2022/articleDamn Vulnerable DeFi — Selfie (flash-loan governance)
  3. Dec 15, 2022/articleDamn Vulnerable DeFi — Truster (flash-loan callback target control)

graphfeed