Health Factor Explained in Detail
A health factor measures whether a borrower's adjusted collateral value is enough to support their debt. In many lending systems, a value below 1 means the position can be liquidated.
The exact formula is protocol-specific. In Aave-style systems, it depends on collateral value, liquidation thresholds, and debt value. Other protocols may use different names, buffers, collateral factors, or liquidation rules.
Smart contract example
This simplified formula shows the idea:
function healthFactor(address user) public view returns (uint256) {
uint256 debt = debtValue(user);
if (debt == 0) return type(uint256).max;
uint256 adjustedCollateral = collateralValue(user) * liquidationThreshold / 1e18;
return adjustedCollateral * 1e18 / debt;
}
If collateralValue, debtValue, decimals, or threshold values are wrong, the liquidation decision is wrong too.
Health Factor in Auditing
Health factor is often the solvency boundary for a lending protocol. A small accounting or oracle bug near that boundary can decide whether a user is safe, liquidatable, or already causing bad debt.
Auditors review the inputs before trusting the score: price feeds, collateral enablement, debt accrual, interest indexes, decimals, liquidation thresholds, and rounding direction.
Red flags in code
-
Formula assumes one universal decimal scale across all assets.
-
Debt interest or collateral indexes are not updated before the check.
-
Threshold changes apply retroactively without clear governance constraints.
-
Rounding near
1allows healthy positions to be liquidated or unhealthy positions to survive. -
Oracle fallback values can inflate collateral or shrink debt.
How to test or review it
-
Build tests for
1e18 - 1,1e18, and1e18 + 1when the liquidation threshold is scaled by1e18. -
Vary token decimals, price-feed decimals, debt indexes, and collateral factors.
-
Simulate collateral price drops and debt price increases independently.
-
Verify the health factor used by liquidation matches the value shown by view functions.
-
Add invariants that a healthy account cannot be liquidated and an account below threshold cannot borrow more or withdraw collateral.