articleJul 20, 2022
Damn Vulnerable DeFi — Unstoppable (high-level)
DVDeFi Challenge 1 Unstoppable: assert tying internal poolBalance to token balance enables DoS if tokens arrive outside depositTokens. High-level root cause and mitigations.
Damn Vulnerable DeFi — Challenge #1 Unstoppable (high-level)
Educational challenge: a lender holds a large DVT balance and offers free flash loans. Lab goal: stop the pool from offering flash loans (availability failure), starting from a small DVT balance.
Vulnerability class / root cause
- Internal accounting variable
poolBalanceis updated only along thedepositTokenspath. flashLoanuses a hardassert(poolBalance == token.balanceOf(pool))(or equivalent) before lending.- ERC-20 tokens can still arrive via plain
transfer, increasing the real token balance without updatingpoolBalance. - That desync trips the assert and halts flash loans (denial of service). Related taxonomy often cited: unexpected ether/token balance assumptions (SWC-132-style thinking).
Impact (abstract)
Flash-loan functionality becomes permanently (or until manual rescue) unavailable—protocol liveness failure, not necessarily direct theft of the million tokens.
Mitigations / lessons
- Do not
asserton balances that third parties can nudge; prefer graceful errors or accounting that ignores unsolicited transfers. - Track deposits only via explicit deposit APIs; treat direct transfers as donations that must not break invariants—or reject them.
- Avoid assert-for-input-validation (assert may consume remaining gas / be treated as invariant, depending on toolchain era).
- Monitor for stuck lending paused states after unexpected ERC-20 receipts.
Solve steps and PoC omitted.