# Divergent health and liquidation ratio metrics

Compare every collateral-ratio computation across mint, withdraw, borrow and liquidate paths for mismatched valuation or thresholds

_Area: DeFi oracles, liquidations and flash loans. Seen in 6 disclosed reports; latest 2025-02-17. Updated 2026-11-14._

## How it works
A protocol encodes "is this position safe?" in more than one place: a mint/withdraw/borrow guard, a liquidation eligibility check, a bad-debt check, a max-repayable helper. Each is written independently and each may value collateral differently — raw vs risk-weighted, price-dependent vs nominal, strict `<` vs `<=`. The assumption that breaks is that all these checks describe the same health state. When they diverge, a position can sit in a state one check forbids but the corrective path (liquidation) refuses to touch, or a state one check calls safe while another lets it be seized.

## Where it shows up
- Liquidation guard that only tests a combined/total ratio while mint/withdraw test a stricter sub-ratio (e.g. exogenous-only collateral) [E1](https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07.md)
- Bad-debt or health checks that reuse risk-weighted (collateralWeight/debtWeight) values where raw excess collateral is what matters [E2](https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md)
- Health factor not recomputed between lend and borrow of the same pair in one transaction; share-based or stale LTV [E3](https://bugbountylibrary.com/r/dhl%3A20250112-unilend.md)
- Connector/wrapper calling a nominal ICR getter (no price argument) instead of the price-dependent current ICR [E4](https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md)
- Two health paths where a flag or early return switches one to bare collateral while liquidation always uses weighted collateral [E5](https://bugbountylibrary.com/r/c4%3A2024-02-wise-lending%3AM-04.md)
- Same condition encoded twice with different comparison operators or boundary equality (`<` vs `> 1e18`) [E6](https://bugbountylibrary.com/r/c4%3A2023-03-polynomial%3AM-09.md)

## How to review
Enumerate every function that computes or compares a collateral ratio, then build a table: inputs (raw vs weighted, price-dependent vs nominal), threshold constant, comparison operator. The invariant to enforce: for any position state, the set of states the mint/withdraw/borrow guards permit must be a subset of the states liquidation can correct, and every check must use the same valuation basis. Test boundary equality explicitly (ratio == threshold) and test the case where weighted ratio < 1 but raw collateral still covers debt [E2](https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md). For wrappers, confirm the getter's semantics match the underlying protocol's real ICR [E4](https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md).

## How finders spotted it
- Diffed liquidate()'s CR-only guard against the exogenous-collateral checks in mintDyad()/withdraw(), then built a fork PoC moving the WETH oracle to show the revert [E1](https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07.md)
- Read the weighting math in the bad-debt check, noticed weights distort the ratio, and constructed a numeric counterexample where ratio < 1e18 but liquidation stays profitable [E2](https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md)
- Noticed a health getter took no price argument and always returned below the 1.5e18 threshold; confirmed with a PoC [E4](https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md)
- Compared the collateral valuation in the withdraw health check (bare vs weighted depending on a flag) against the liquidation check, spotting the early return [E5](https://bugbountylibrary.com/r/c4%3A2024-02-wise-lending%3AM-04.md)
- Compared the inequality in canLiquidate() against the safety check in maxLiquidatableDebt(), spotting the off-by-one at safetyRatio == 1e18 [E6](https://bugbountylibrary.com/r/c4%3A2023-03-polynomial%3AM-09.md)

## Variants seen
- Stricter invariant on mint/withdraw than on liquidate, leaving unliquidatable under-backed positions [E1](https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07.md)
- Weighted ratio misclassifying a solvent pool as bad debt [E2](https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md)
- Stale/miscomputed health factor within a single transaction [E3](https://bugbountylibrary.com/r/dhl%3A20250112-unilend.md)
- Wrong getter variant (nominal vs current) in a connector [E4](https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md)
- Flag/early-return switching valuation basis between paths [E5](https://bugbountylibrary.com/r/c4%3A2024-02-wise-lending%3AM-04.md)
- Operator/boundary mismatch between two encodings of one condition [E6](https://bugbountylibrary.com/r/c4%3A2023-03-polynomial%3AM-09.md)

## Impact and severity
Ranged from bricked borrow/repay [E4](https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md) and blocked liquidations causing LP/MM losses [E2](https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md) to unliquidatable positions breaking the TVL > supply invariant, amplified by a correlated ETH drop hitting many vaults at once [E1](https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07.md), and a pool drained of 60 stETH funded by chained flash loans [E3](https://bugbountylibrary.com/r/dhl%3A20250112-unilend.md). Severity rises with how many positions share the divergent state and whether an attacker can reach it atomically.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8.md
- E3: https://bugbountylibrary.com/r/dhl%3A20250112-unilend.md
- E4: https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-17.md
- E5: https://bugbountylibrary.com/r/c4%3A2024-02-wise-lending%3AM-04.md
- E6: https://bugbountylibrary.com/r/c4%3A2023-03-polynomial%3AM-09.md
