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 inbalances, andwithdraw()pays out from that mapping. - If flash-loaned ETH is “repaid” by calling
depositduring 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
depositcan 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.