Skip to content
medium DeFi Economic No SWC entry CWE-682

Bad Debt Not Socialised / Handled

SAFE-0221 DeFi Economic Checked automatically by the scanner
1

What goes wrong

A lending market has no path to handle under-water positions where collateral < debt after a crash. Liquidators avoid unprofitable liquidations, bad debt accrues silently, and the last withdrawers are left insolvent (bank run).

2

The vulnerable pattern

proof of concept — how it is exploited
// price gaps down 40% in one block; a position is 90% collateralised.
// liquidation is unprofitable so nobody liquidates -> the shortfall
// becomes the depositors' loss on a first-come-first-served exit.
3

How to fix it

the pattern that is safe
// track and socialise bad debt, or backstop with a reserve/insurance fund
if (collateralValue < debt) { _socialiseLoss(debt - collateralValue); }
Venus / Aave bad-debt events. Plan for insolvency.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0221 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs