MIN_LEFTOVER_BASE Prevents Valid Max-Close-Factor Liquidations
A hardcoded $1,000 minimum leftover threshold in the liquidation logic rejects partial liquidations that are otherwise valid under the protocol's 50% close factor, because the liquidation bonus can push remaining collateral below that floor. Liquidators cannot reliably repay the maximum permitted amount, which reduces liquidation throughput during stressed markets.
Submitted by Egobouros, also found by AvantGard
contracts/shared/src/constants.rs#L37-L40contracts/kinetic-router/src/liquidation.rs#L20-L35contracts/kinetic-router/src/liquidation.rs#L633-L654contracts/kinetic-router/src/router.rs#L1095-L1125
The protocol defines MIN_LEFTOVER_BASE as 1_000 * WAD, so any partial liquidation that leaves either the borrower’s remaining debt value or remaining collateral value below $1,000 reverts.
This is much larger than a dust threshold. It conflicts with the liquidation close-factor logic because the close factor is supposed to define the maximum debt that may be repaid, but the leftover check rejects otherwise valid repayments below that maximum. In common liquidation states, the maximum 50% liquidation is unusable: full liquidation is rejected by the close factor, while the maximum permitted partial liquidation is rejected because the liquidation bonus pushes the remaining collateral below the $1,000 leftover floor.
Vulnerability Details
MIN_LEFTOVER_BASE is hardcoded to $1,000:
pub const MIN_CLOSE_FACTOR_THRESHOLD: u128 = 2_000_000_000_000_000_000_000; // 2000 * WAD
pub const MIN_LEFTOVER_BASE: u128 = 1_000_000_000_000_000_000_000; // 1000 * WAD
For positions whose individual debt and collateral are both at least $2,000, and whose health factor is above the partial-liquidation threshold, the router applies the default 50% close factor:
let close_factor = if individual_debt_base < MIN_CLOSE_FACTOR_THRESHOLD
|| individual_collateral_base < MIN_CLOSE_FACTOR_THRESHOLD
|| health_factor < partial_liq_threshold {
MAX_LIQUIDATION_CLOSE_FACTOR
} else {
DEFAULT_LIQUIDATION_CLOSE_FACTOR
};
let max_liquidatable_debt = individual_debt_base
.checked_mul(close_factor)?
.checked_div(BASIS_POINTS_MULTIPLIER)?;
if debt_to_cover_base > max_liquidatable_debt {
return Err(KineticRouterError::LiquidationAmountTooHigh);
}
After the liquidation executes, the code checks the remaining debt and collateral values:
if remaining_debt_balance > 0 && remaining_collateral_balance > 0 {
...
if remaining_debt_value < MIN_LEFTOVER_BASE || remaining_collateral_value < MIN_LEFTOVER_BASE {
panic_with_error!(env, LiquidationError::LeavesTooLittleDebt);
}
}
The two constraints are inconsistent. The close factor says the liquidator may repay up to D * 50%, but the leftover check silently imposes a second limit:
remaining_collateral = C - debt_to_cover * (1 + liquidation_bonus)
remaining_collateral must be either 0 or >= 1000 WAD
Therefore, any repayment in this interval is rejected:
(C - 1000 WAD) / (1 + bonus) < debt_to_cover < C / (1 + bonus)
This interval frequently overlaps the valid close-factor range. When it does, the maximum close-factor liquidation reverts even though debt_to_cover_base <= max_liquidatable_debt.
The same leftover check is also present in the two-step flash liquidation path in router.rs, returning InvalidLiquidation.
Impact
Liquidators cannot reliably use the protocol’s advertised close factor. Some liquidations that should be valid under the 50% close-factor rule revert solely because the remaining collateral or debt is below an arbitrary $1,000 floor.
This reduces liquidation throughput exactly when rapid deleveraging is needed. In stressed markets, forcing liquidators to search for smaller, non-reverting repayment amounts increases execution risk, reduces competition, and can leave more bad debt in the system. Full liquidation is not a workaround for affected positions, because the close-factor check rejects repayments above the 50% cap while the leftover check rejects the maximum permitted partial repayment.
Recommended Mitigation
Do not use a fixed $1,000 threshold for leftover debt or collateral.
Prefer one of the following:
- Reduce
MIN_LEFTOVER_BASEto a true dust value, such as a few dollars in base currency. - Make the leftover threshold reserve-specific and configurable by governance.
- Apply the check only when the remaining value is genuinely uneconomical relative to transaction costs and liquidation incentives.
- If a liquidation would otherwise leave dust, automatically clamp the repayment to a full close-out when that is allowed by the close-factor rules.
At minimum, the leftover rule must not reject any repayment amount that the close-factor logic explicitly permits.
Proof of Concept
Consider a borrower with:
- Debt value: $4,000
- Collateral value: $3,000
- Liquidation threshold: 80%
- Liquidation bonus: 5%
- Partial liquidation threshold: default
0.5 WAD
The borrower’s health factor is:
HF = collateral * liquidation_threshold / debt
HF = 3000 * 0.80 / 4000 = 0.60
Because HF >= 0.5, debt is at least $2,000, and collateral is at least$2,000, the default 50% close factor applies. The maximum allowed repayment is therefore:
max_liquidatable_debt = 4000 * 50% = 2000
A liquidator repays exactly the maximum valid amount, $2,000. With a 5% liquidation bonus, the protocol seizes:
collateral_seized = 2000 * 1.05 = 2100
Post-liquidation balances are:
remaining_debt = 4000 - 2000 = 2000
remaining_collateral = 3000 - 2100 = 900
The liquidation passes the close-factor check because $2,000 <= $2,000, but then reverts because the remaining collateral is non-zero and below MIN_LEFTOVER_BASE:
remaining_collateral_value = 900 WAD < 1000 WAD
The following self-contained Rust test reproduces the failing condition:
#[test]
fn poc_min_leftover_rejects_valid_max_close_factor_liquidation() {
const WAD: u128 = 1_000_000_000_000_000_000;
const BPS: u128 = 10_000;
const DEFAULT_CLOSE_FACTOR: u128 = 5_000;
const MIN_CLOSE_FACTOR_THRESHOLD: u128 = 2_000 * WAD;
const MIN_LEFTOVER_BASE: u128 = 1_000 * WAD;
let debt_value = 4_000 * WAD;
let collateral_value = 3_000 * WAD;
let health_factor = 600_000_000_000_000_000u128; // 0.60 WAD
let partial_liq_threshold = 500_000_000_000_000_000u128; // default 0.50 WAD
let liquidation_bonus_bps = 500u128; // 5%
assert!(debt_value >= MIN_CLOSE_FACTOR_THRESHOLD);
assert!(collateral_value >= MIN_CLOSE_FACTOR_THRESHOLD);
assert!(health_factor >= partial_liq_threshold);
let max_liquidatable_debt = debt_value * DEFAULT_CLOSE_FACTOR / BPS;
assert_eq!(max_liquidatable_debt, 2_000 * WAD);
let debt_to_cover = max_liquidatable_debt;
// This is accepted by validate_close_factor().
assert!(debt_to_cover <= max_liquidatable_debt);
let collateral_seized = debt_to_cover * (BPS + liquidation_bonus_bps) / BPS;
assert_eq!(collateral_seized, 2_100 * WAD);
let remaining_debt = debt_value - debt_to_cover;
let remaining_collateral = collateral_value - collateral_seized;
assert_eq!(remaining_debt, 2_000 * WAD);
assert_eq!(remaining_collateral, 900 * WAD);
// This matches the liquidation.rs/router.rs leftover check and causes a revert.
assert!(remaining_debt > 0);
assert!(remaining_collateral > 0);
assert!(remaining_collateral < MIN_LEFTOVER_BASE);
}
This demonstrates that a liquidation can be simultaneously within the protocol’s close-factor limit and rejected by the $1,000 leftover check.
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
Likely the fixed $1,000 leftover floor is inconsistent with the close-factor cap, so the leftover check silently rejects repayments the close factor explicitly permits.
Impact
Liquidators cannot reliably use the advertised close factor, which reduces liquidation throughput when rapid deleveraging is needed and can leave more bad debt in the system.
What the attacker needed
A borrower position meeting the close-factor conditions; a liquidator repaying the maximum permitted amount
The fix
The leftover threshold should be reduced to a true dust value, made reserve-specific and configurable, or clamped to a full close-out, so it never rejects a repayment the close factor permits.
How it was found
- Take a borrower with $4,000 debt, $3,000 collateral, 80% liquidation threshold and 5% bonus.
- Confirm the health factor is 0.60, so the default 50% close factor applies.
- Repay the maximum allowed $2,000, which seizes $2,100 of collateral.
- Observe remaining collateral of $900 is non-zero and below the $1,000 floor, so the transaction reverts.
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.
In a lending protocol, a liquidator repays part of a borrower's debt and receives some of their collateral at a discount. The protocol sets a maximum amount a liquidator may repay (the close factor), but a separate rule also refuses any liquidation that leaves less than $1,000 of debt or collateral behind. These two rules clash, so a repayment that the first rule allows can still be blocked by the second.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.