Dust-sized debt can turn a very safe account into a MathOverflow denial of service
The health-factor calculation reverts with a MathOverflow error when an account has a tiny nonzero debt and a very large collateral value, because the computed health factor exceeds u128::MAX. An attacker can create such a state by borrowing one raw unit of debt and then adding collateral, causing many protocol functions that read the health factor to revert.
Submitted by YradAngel, also found by 0xGutzzz, maxzuvex, and Silvermist
contracts/kinetic-router/src/calculation.rs#L29-L52contracts/kinetic-router/src/calculation.rs#L392-L397contracts/kinetic-router/src/operations.rs#L285-L411contracts/kinetic-router/src/operations.rs#L11-L130
The health-factor function uses u128::MAX as the protocol’s “infinite health” value when a user has no debt. But the same function reverts when the account has a tiny nonzero debt and the computed health factor would be larger than u128::MAX.
That makes a very small debt residue dangerous. A user can have a large amount of collateral, only one base unit of debt, and be economically far safer than required, yet get_user_account_data, withdrawals, collateral toggles, swaps, liquidations, and other HF-dependent flows revert with MathOverflow.
Root Cause
calculate_health_factor_u256() calculates HF in U256, then narrows the result to u128.
if total_debt_base == 0 {
return u128::MAX;
}
collateral
.mul(&threshold)
.mul(&wad)
.div(&bps)
.div(&debt)
.to_u128()
.unwrap_or_else(|| panic_with_error!(env, KineticRouterError::MathOverflow))
This creates a discontinuity:
debt = 0 -> return u128::MAX
debt = 1 -> panic if HF > u128::MAX
The second state is not riskier than the first. It is still an extremely safe account. The calculation should saturate to the same maximum sentinel instead of treating the large value as an invalid arithmetic state.
Why This Is Reachable
The user does not need to start with enough collateral to overflow the calculation. They only need to create the dust debt while their account is still below the overflow boundary.
The sequence is:
- Supply collateral below the overflow threshold.
- Borrow one raw unit of an 18-decimal asset.
- The post-borrow HF is huge but still representable, so the borrow succeeds.
- Supply more collateral.
- Supply does not need to verify the supplier’s HF because more collateral cannot make the account less solvent.
- The next HF read computes a value above
u128::MAXand panics.
With a $1 oracle price and 14-decimal oracle precision, one raw unit of debt on an 18-decimal reserve can become total_debt_base = 1. Once collateral value crosses roughly u128::MAX / (liquidation_threshold * WAD / 10000), the U256 HF result no longer fits in u128.
For an 85% liquidation threshold, that boundary is around 4e20 base units, which corresponds to an ordinary few-hundred-dollar collateral position under the protocol’s base-value scale.
Impact
The account becomes operationally stuck despite being overcollateralized. Any code path that recomputes account data can fail with MathOverflow, including:
get_user_account_datawithdraw- additional
borrow set_user_use_reserve_as_collswap_collateralliquidation_call- transfer finalization for users with debt
The user may be able to recover only by repaying the dust through a path that does not first require a health-factor read. If the user no longer has the debt asset, they must acquire it externally because normal protocol flows that would use the collateral may already be blocked.
This can also happen naturally after near-full repayment if interest or rounding leaves a tiny debt remainder and the user later has enough collateral for the health-factor result to exceed u128::MAX.
Recommended Fix
Treat an above-u128::MAX health factor as saturated maximum health, not as an arithmetic failure.
collateral
.mul(&threshold)
.mul(&wad)
.div(&bps)
.div(&debt)
.to_u128()
.unwrap_or(u128::MAX)
This matches the existing zero-debt sentinel and preserves the intended invariant: extremely healthy accounts should remain usable.
Proof of Concept
The PoC creates a new 18-decimal borrow reserve, opens exactly one raw unit of debt while the user has a representable HF, then adds collateral until the health factor no longer fits in u128.
See original finding for full Proof of Concept
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The health-factor calculation narrows a U256 result to u128 and panics on overflow instead of saturating to u128::MAX, creating a discontinuity between zero debt and tiny nonzero debt.
Impact
The account becomes operationally stuck despite being overcollateralized, and any code path that recomputes account data can fail with MathOverflow, including withdrawals, additional borrows, collateral toggles, swaps, liquidations, and transfer finalization.
What the attacker needed
Ability to borrow and supply collateral; collateral value large enough to overflow u128
The fix
Treat an above-u128::MAX health factor as saturated maximum health by using unwrap_or(u128::MAX) instead of panicking.
How it was found
- Supply collateral below the overflow threshold.
- Borrow one raw unit of an 18-decimal asset.
- The post-borrow health factor is huge but still representable, so the borrow succeeds.
- Supply more collateral.
- Supply does not need to verify the supplier’s health factor because more collateral cannot make the account less solvent.
- The next health-factor read computes a value above u128::MAX and panics.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A health factor is a number that shows how safe a loan is: higher means safer. The code treats a loan with no debt as infinitely safe, but if there is even a tiny amount of debt and the loan is extremely safe, the calculation tries to store a number that is too big and crashes. This crash blocks many actions like withdrawing or liquidating, even though the account is actually very safe.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.