Security

DeFi Liquidation Logic: Health Factors & Bad Debt

A lending protocol is only as solvent as its liquidation engine. The primary risk for platforms like Aave or Compound is not hacking, but Bad Debt—a state where the value of the collateral falls below the value of the borrowed asset.
Once Debt > Collateral, the borrower has no incentive to repay. The protocol is left holding a bag of depreciating tokens, and liquidity providers lose money. Liquidation logic is the mechanism designed to prevent this.

The Health Factor

Solvency is tracked via a "Health Factor" (HF). HF = (Collateral Value * Liquidation Threshold) / Total Debt
  • HF > 1: The loan is safe.
  • HF < 1: The loan is under-collateralized and eligible for liquidation.
The Liquidation Threshold is always < 100% (e.g., 80% for ETH). This 20% buffer protects the protocol against price volatility between the moment HF drops below 1 and the moment the liquidation transaction is mined.

The Race Against Time

Liquidation is not automatic. It relies on third-party "Keepers" (bots) to monitor the chain and call the liquidate() function. In exchange for paying off the user's debt, the liquidator receives the user's collateral plus a Liquidation Bonus (usually 5-10%).
The Vulnerability: If the network is congested (gas prices spike) or the asset price crashes too fast (Black Thursday scenario), liquidators may fail to execute transactions in time. If the price drops so much that Collateral Value < Debt, no rational liquidator will intervene, because the collateral they receive is worth less than the debt they repay.

Chainlink & L2 Nuances

  • Oracle Latency: Liquidation logic depends on the oracle price. If Chainlink stops updating (heartbeat delay) during a crash, the protocol effectively operates on "stale" prices, allowing insolvent positions to remain open.
  • L2 Sequencer Downtime: On Arbitrum or Optimism, if the sequencer goes down, liquidators cannot submit transactions. Prices continue to move on CEXs. When the sequencer restarts, positions may instantly become bad debt.

Conclusion

Liquidation logic must be aggressive. Incentives for liquidators must cover gas costs even during extreme congestion. Without a robust liquidation engine, a lending protocol is just a Ponzi scheme waiting for the first market correction.