Self-liquidation with receive_a_token = true bypasses collateral seizure via from == to self-transfer in transfer_on_liquidation , socializing residual debt to reserve deficit
The router allowed a borrower to act as their own liquidator, and the aToken's transfer function did not handle self-transfers, so the collateral seizure became a no-op while the router still recorded it as removed. This let an underwater borrower wipe their residual debt into the reserve deficit and keep collateral that should have gone to an external liquidator.
Silvermist Follow with 0xBookerH, 0xterrah and 33 others
Originally disclosed on Code4rena
Submitted by Silvermist, also found by 0xBookerH, 0xterrah, abdelhaq16, Agontuk, ahmad044, AvantGard, botdidy, bunnyhunter, ChainSentry, deividrobinson, fuzious, harry, hezze, honey-k12, HUNTERRRRRRR, HUNTTTTTTER, ix2b100, Lamsy, meshaqRapha, minicookie, namaila, niffylord, Noahdgoat, openchat97, qed, rends_east, sahuang, sanidhyaved, TheSpark, twicek, unineko, WhiteKnightK, X-Tray03, Yellow-Wolf, and yonko
contracts/a-token/src/contract.rs#L471-L528contracts/kinetic-router/src/liquidation.rs#L387-L487contracts/kinetic-router/src/liquidation.rs#L576-L612contracts/a-token/src/contract.rs#L579-L587
The kinetic router’s liquidation_call does not reject liquidator == user, and the aToken’s transfer_on_liquidation does not short-circuit from == to. When a borrower self-liquidates with receive_a_token = true, the main collateral transfer silently becomes a storage no-op, but the router continues its accounting on the assumption that the collateral was actually seized. Under collateral_cap_triggered, this causes the router to burn the borrower’s residual debt and push it into reserve_deficit, socializing the loss to depositors while the borrower retains the principal and bonus portions of what should have been seized collateral.
The aToken implementation in contracts/a-token/src/contract.rs debits the sender and credits the receiver in two sequential storage reads, and this sequence silently round-trips when the two addresses are the same:
pub fn transfer_on_liquidation(
env: Env,
caller: Address,
from: Address,
to: Address,
amount: u128,
index: u128,
) -> Result<bool, TokenError> {
// ... auth + validation ...
// Debit from sender
let from_balance = storage::get_scaled_balance(&env, &from);
if from_balance < amount_scaled {
return Err(TokenError::InsufficientBalance);
}
storage::set_scaled_balance(&env, &from, &(from_balance - amount_scaled));
// Credit to receiver
let to_balance = storage::get_scaled_balance(&env, &to);
let is_first = to_balance == 0;
let new_to_balance = to_balance.checked_add(amount_scaled)
.ok_or(TokenError::TransferFailed)?;
storage::set_scaled_balance(&env, &to, &new_to_balance);
// ...
}
When from == to, the debit write persists balance - amount_scaled, the credit read observes that just-written value, and the credit write restores the original balance. Net balance change for the borrower is zero. The sibling function transfer_internal in the same file has precisely the guard that is missing here, with a WP-C6 comment that shows the authors understood the self-transfer hazard in the sibling path but never ported the fix:
fn transfer_internal(env: Env, from: Address, to: Address, amount: i128) -> Result<(), TokenError> {
if amount <= 0 {
return Err(TokenError::InvalidAmount);
}
// WP-C6: self-transfer would overwrite the debit with the credit, inflating balance
if from == to {
return Ok(());
}
// ...
}
The router compounds this. In contracts/kinetic-router/src/liquidation.rs, the receive_a_token branch calls transfer_on_liquidation and then derives effective_collateral_removed from the nominal input quantities, never re-reading the post-transfer aToken balance:
if _receive_a_token {
// ... transfer_on_liquidation(user, liquidator, liquidator_collateral, ...) ...
effective_collateral_removed = liquidator_collateral
.checked_add(actually_transferred_fee)
.ok_or(KineticRouterError::MathOverflow)?;
} else {
// ... burn + transfer underlying ...
effective_collateral_removed = collateral_amount_to_transfer;
}
When the transfer was a self-transfer no-op, the liquidator_collateral scaled tokens remain with the borrower, but the router records them as removed. If collateral_cap_triggered is true, the router then takes the bad-debt socialization path on the false premise that all collateral was seized:
if remaining_debt_balance > 0 {
let remaining_debt_u128 = safe_i128_to_u128(env, remaining_debt_balance);
if collateral_cap_triggered {
// H-05: All collateral seized - remaining debt is unrecoverable bad debt.
// ... burn_scaled remaining debt ...
storage::add_reserve_deficit(env, &debt_asset, remaining_debt_u128);
remaining_debt_balance = 0;
// ...
}
}
The residual debt is burned and added to reserve_deficit, and depositors absorb the loss.
An underwater borrower whose position reaches collateral_cap_triggered can call liquidation_call with themselves as both liquidator and user and receive_a_token = true. Per exploit, the borrower pays only the cap-adjusted debt_to_cover (a fraction of the outstanding debt), retains the principal and bonus collateral that would otherwise be paid to an external liquidator (only the treasury-fee slice, a user -> treasury non-self transfer, is actually debited), and the residual debt is burned and pushed into reserve_deficit, socialized to depositors. In a legitimate external liquidation of the same cap-triggered state, the borrower would lose the full collateral balance and the external liquidator would capture the 5% bonus. The exploit redirects that reward to the borrower. The marginal extraction versus a baseline third-party liquidation is approximately scaled_coll_before * (10_000 - flash_loan_premium_bps) / 10_000 in scaled aTokens, effectively the entire liquidator reward on every cap-triggered underwater position.
Attack Scenario
- The attacker opens a borrow position with high LTV.
- The collateral asset price declines through a sequence of sub-20% moves (each permissible under the default
max_price_change_bps = 2000circuit breaker), pushing the position deeply underwater and intocollateral_cap_triggeredstate. The Reflector feed andrefresh_pricesare both permissionless, so this sequence requires no admin intervention. - The attacker calls
liquidation_call(attacker, collateral_asset, debt_asset, attacker, debt_to_cover, true). - The router verifies
HF < WAD(true), computescollateral_cap_triggered = true, and callstransfer_on_liquidation(caller=router, from=attacker, to=attacker, amount=liquidator_collateral, ...), which is a no-op on the attacker’s scaled balance. - The router derives
effective_collateral_removedfrom the nominal input and proceeds to the cap-triggered branch: the residual debt is burned and added toreserve_deficit. - The attacker retains the seized portion of the collateral and exits with their debt wiped and the loss socialized to depositors.
Recommended Mitigation Steps
Reject self-liquidation in the router before any state mutation. Add to internal_liquidation_call in contracts/kinetic-router/src/liquidation.rs:
fn internal_liquidation_call(
env: &Env,
liquidator: Address,
collateral_asset: Address,
debt_asset: Address,
user: Address,
debt_to_cover: u128,
_receive_a_token: bool,
) -> Result<(), KineticRouterError> {
validation::validate_liquidation_whitelist_access(env, &liquidator)?;
validation::validate_liquidation_blacklist_access(env, &liquidator)?;
if liquidator == user {
return Err(KineticRouterError::InvalidLiquidation);
}
// ...
}
Proof of Concept
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
Likely the router did not reject liquidator == user, and the aToken's transfer_on_liquidation lacked the from == to guard present in its sibling transfer_internal, so the router's accounting diverged from the actual balance change.
Impact
An underwater borrower could keep collateral that an external liquidator would have seized and have residual debt socialised to depositors, though the treasury-fee slice is still debited.
What the attacker needed
A borrow position with high LTV; collateral price falls into cap-triggered state; attacker can call liquidation_call
The fix
The router should reject self-liquidation before any state mutation, as the report recommends.
How it was found
- The attacker opens a borrow position with high LTV.
- The collateral price falls in sub-20% steps until the position is deeply underwater and collateral_cap_triggered is true.
- The attacker calls liquidation_call with themselves as both liquidator and user, and receive_a_token set to true.
- The router calls transfer_on_liquidation from the attacker to the attacker, which leaves the scaled balance unchanged.
- The router treats the nominal collateral as removed and enters the cap-triggered branch, burning the residual debt and adding it to reserve_deficit.
- The attacker keeps the collateral and exits with the debt wiped, while depositors absorb the loss.
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, if you borrow too much and your collateral loses value, someone else can liquidate you: they repay part of your debt and take your collateral at a discount. This report shows that a borrower could liquidate themselves, and because a transfer from an address to itself does nothing, the system thought the collateral was taken when it was not. The leftover debt was then written off and spread across all depositors, while the borrower kept the collateral.
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.