Zero-balance collateral opt-in can make unhealthy positions unliquidatable
ChainSentry Follow with 0xB4B, 0xSmartContractSamurai and 48 others
Originally disclosed on Code4rena
Submitted by ChainSentry, also found by 0xB4B, 0xSmartContractSamurai, ABAIKUNANBAEV, abdelhaq16, accessControl, AD404, Agontuk, aman, APex, auditinfra-io, AvantGard, beanie95, Bigsam, botdidy, bunnyhunter, CipherGhost, coinsspor, DarkWingCipher, deccs, deki, destro4evr, edoscoba, eightzerofour, emp_mirage, Emperor, ErmanSec, faldiox, fromeo_016, goodman387, gwumex, happykilling, harry, honey-k12, hyun, Insomnia, izhelyazkov, jesjupyter, juldesbourds, Kalogerone, kongwen68, legat, littlebull, lizardon, merlinboii, mosskappa, Najnomics, niffylord, nstatoshi, oade_hacks, odeili, omeftouh, opseeker, oziajibogu, PolarizedLight, Redteamer, ret2basic, Rifter, scanpt, sh1v, Squad_Depth, Stakeados, t4sk, TheCarrot, TheodorNEngoy, trapAkula, Trynax, twicek, udogodwin, Umesh1145, verbabuilders, Voltvoks, Wamir, WhiteKnightK, wladiluv3, wuji, ZakMHTX, ZanyBonzy, and zpbrent
contracts/kinetic-router/src/router.rs#L1256-L1281contracts/kinetic-router/src/calculation.rs#L130-L163contracts/kinetic-router/src/calculation.rs#L197-L245contracts/kinetic-router/src/liquidation.rs#L170-L185
K2 exposes a public entrypoint, set_user_use_reserve_as_coll(user, asset, true), that allows a borrower to mark an active reserve as collateral even when that borrower holds zero aTokens for that reserve. The same function also omits the protocol’s advertised MAX_USER_RESERVES = 15 anti-fragmentation check.
The router’s unified account-data logic later treats every bitmap bit as an active position to price and inspect, even if the reserve carries no user value. Direct liquidation calls that same unified accounting path before repaying debt. As a result, a borrower can:
- open an ordinary 2-asset borrow position,
- self-mark many unfunded reserves as collateral,
- leave their real collateral and debt unchanged, and then
- cause
liquidation_callto exceed realistic Soroban budget limits before any repayment occurs.
This is a liquidation-liveness failure on the protocol’s primary risk-management path.
Why the Protocol Documentation Nakes This a Bug
The project documentation explicitly says the 15-reserve cap exists to prevent this class of failure:
From 03-CORE-CONCEPTS.md:
“While the bitmap structurally supports 64 reserves, the protocol enforces
MAX_USER_RESERVES = 15per user… This tighter limit bounds the health-factor computation loop and prevents reserve fragmentation attacks.”
That statement matters because the bug is exactly a failure of that guarantee: set_user_use_reserve_as_coll(true) creates new active slots without enforcing the 15-reserve limit.
From 10-STORAGE.md:
“To find all of a user’s positions, iterate the
UserConfigurationbitmap.”
That statement matters because the implementation trusts the bitmap as the source of truth for which reserves to inspect. Once phantom bits are written, later health-factor and liquidation logic performs real work for those fake positions.
From 06-LIQUIDATION.md:
“The liquidation system is the primary risk-management mechanism of the K2 protocol.”
That statement matters because the PoC does not merely make a view function expensive. It breaks the documented primary mechanism for resolving unhealthy debt.
Root Cause
1. Zero-balance collateral opt-in writes a bitmap bit anyway
In contracts/kinetic-router/src/router.rs, set_user_use_reserve_as_coll(true) checks only that:
- the reserve exists,
- the reserve is active, and
- the oracle reports a nonzero price.
It does not check that the caller has a nonzero aToken balance for that reserve, and it does not check whether enabling the bit would exceed MAX_USER_RESERVES.
Relevant logic:
if use_as_collateral {
crate::price::verify_oracle_price_exists_and_nonzero(&env, &asset)?;
let mut user_config = storage::get_user_configuration(&env, &caller);
user_config.set_using_as_collateral(
k2_shared::safe_reserve_id(&env, reserve_data.id),
true
);
storage::set_user_configuration(&env, &caller, &user_config);
}
2. Unified account-data trusts the bitmap and iterates every marked reserve
In contracts/kinetic-router/src/calculation.rs, unified account-data:
- iterates the bitmap to discover active positions,
- batch-fetches prices for all marked assets, and
- calls
balance_of_with_indexper marked reserve.
Relevant logic:
let next_reserve_id = storage::get_next_reserve_id(env);
let iteration_bound = next_reserve_id.min(MAX_RESERVES as u32) as u8;
for reserve_id in 0..iteration_bound {
if user_config.is_using_as_collateral(reserve_id)
|| user_config.is_borrowing(reserve_id)
{
if let Some(asset) = storage::get_reserve_address_by_id(env, reserve_id as u32) {
...
all_assets.push_back(asset.clone());
active_positions.push_back((asset, reserve_data));
}
}
}
let price_map = crate::price::get_prices_for_assets(env, &all_assets)?;
for i in 0..active_positions.len() {
let (asset, reserve_data) = active_positions.get(i).unwrap();
let is_collateral = user_config.is_using_as_collateral(...);
let is_borrowing = user_config.is_borrowing(...);
...
let collateral_balance = if is_collateral {
// invokes balance_of_with_index(...)
}
3. Direct liquidation inherits that cost before debt repayment
In contracts/kinetic-router/src/liquidation.rs, liquidation_call computes borrower health using unified account-data before performing liquidation:
// Calculate health factor with fresh prices using unified function
let result = calculation::calculate_user_account_data_unified(env, &user, params)?;
let user_account_data = result.account_data;
if user_account_data.health_factor >= WAD {
return Err(KineticRouterError::InvalidLiquidation);
}
So once the borrower has written enough zero-balance collateral bits, liquidation spends budget on fake positions before any debt is repaid.
Impact
This bug turns a nominally healthy control path into a broken risk-management path under the same economic state.
In the validated PoC:
- the control borrower has 2 real positions: one collateral reserve and one debt reserve,
- the fragmented borrower has the same real collateral value and the same real debt value,
- the only difference is that the fragmented borrower self-added zero-balance collateral bits on extra reserves,
- the control borrower remains liquidatable,
- the fragmented borrower causes direct
liquidation_callto panic withHostError: Error(Budget, ExceededLimit).
The threshold is not theoretical:
- direct liquidation fails at 26 active slots total, created from only 24 zero-balance extra toggles
get_user_account_datafails at 34 active slots total, created from 32 zero-balance extra toggles
That is far below the 64-slot structural bitmap maximum, and it is exactly the sort of reserve-fragmentation failure the documentation says the 15-reserve cap is supposed to prevent.
Why This is Not the Same Root Cause as the Published Fragmentation Issues
There are published issues about fragmentation, but the public path here is materially different.
Published issue family 1:
swap_collateralbypasses the reserve cap by directly setting destination collateral bits during swaps.
Published issue family 2:
- unsolicited aToken transfers force collateral bits onto a victim through transfer finalization.
This submission does not use swaps and does not use inbound transfers.
Instead, the borrower uses their own public set_user_use_reserve_as_coll(true) calls on reserves where their aToken balance remains exactly zero throughout the PoC. The missing ownership check and missing reserve-cap check inside that specific entrypoint are the root cause here.
Recommendation
The fix should address both the state corruption and the downstream amplification:
- In
set_user_use_reserve_as_coll(true), require a nonzero aToken balance before setting the collateral bit. - In the same function, enforce
MAX_USER_RESERVESif the call would create a new active slot. - As defense in depth, have unified account-data and liquidation ignore collateral-only slots whose effective balance is zero, so any stale or phantom bitmap entries cannot amplify runtime cost.
Final Assessment
The protocol documents a 15-reserve cap specifically to bound health-factor work and prevent fragmentation attacks. This public entrypoint bypasses that guarantee without requiring swaps, transfers, or special privileges. The result is not merely a cosmetic bitmap inconsistency; it is a tested path that prevents liquidation of an unhealthy borrower under realistic Soroban limits while the same economic position remains liquidatable in the control case.
Proof of Concept
How to reproduce
If reproducing from a clean checkout, place the following test module at:
tests/integration-tests/src/test_zero_balance_slot_liquidation_budget.rs
and register it in:
tests/integration-tests/src/lib.rs
with:
mod test_zero_balance_slot_liquidation_budget;
Then run:
PATH="$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin:$PATH" bash build.sh
PATH="$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin:$PATH" cargo test --package k2-integration-tests zero_balance_collateral_toggles_break -- --nocapture
See original finding for full Proof of Concept
What the PoC proves
The PoC is intentionally differential.
It first proves the control case:
- a borrower with only the real collateral and debt slots is below HF 1.0, and
- direct
liquidation_callsucceeds under the same realistic budget limits.
It then proves the exploit case:
- the fragmented borrower has 26 active slots but only 2 economic positions,
- the first extra reserve has zero aToken balance,
total_collateral_baseis unchanged versus the control account,total_debt_baseis unchanged versus the control account,- and direct
liquidation_callnow panics withExceededLimit.
The second test confirms the same root cause independently through the public account-data path.
Observed results
Observed output from the validated run:
running 2 tests
direct liquidation budget panic reproduced at active_slots=26 extra_zero_balance_slots=24 panic=panicked at ...:
HostError: Error(Budget, ExceededLimit)
...
test test_zero_balance_slot_liquidation_budget::test_poc_zero_balance_collateral_toggles_break_direct_liquidation_budget ... ok
account-data budget panic reproduced at active_slots=34 extra_zero_balance_slots=32 panic=panicked at ...:
HostError: Error(Budget, ExceededLimit)
...
test test_zero_balance_slot_liquidation_budget::test_poc_zero_balance_collateral_toggles_break_account_data_budget ... ok
test result: ok. 2 passed; 0 failed
The direct-liquidation panic log also showed repeated balance_of_with_index calls on reserves whose user balance was zero, confirming that the budget was being spent on phantom positions rather than on any change in the borrower’s real economics.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in K2. Code4rena made it public on 20 August 2026. Found in the 2026-04-k2 audit contest (finding H-12), also found by 78 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.