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.
Keep learning this topic
Liquidation
Liquidation is a protocol action that repays or closes an undercollateralized borrow position and transfers collateral according to the protocol's rules.
Oracle Manipulation
Oracle manipulation occurs when an attacker distorts a data source that a smart contract trusts, causing the contract to make decisions from unsafe data.
Price Manipulation
Price manipulation is the intentional movement of an asset, pool, share, or collateral price so a protocol values assets incorrectly.
Oracle Manipulation & Price Manipulation
Oracle manipulation attacks distort price feeds, spot prices, and exchange rates. Learn Chainlink checks, TWAP defenses, and auditor review steps.
Flash Loans Attacks
Learn how flash loan attacks amplify oracle, accounting, and governance bugs in one transaction. See DeFi examples, exploit mechanics, and audit defenses.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Health Factor into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.