swap_collateral bypasses MAX_USER_RESERVES and MIN_FIRST_DEPOSIT , enabling reserve fragmentation that strands bad debt
The swap_collateral function creates new reserve positions without enforcing the per-user reserve cap or the minimum first deposit that supply and borrow enforce. An attacker could use cheap dust swaps to fragment their account across many reserves, potentially making an underwater account unliquidatable and stranding bad debt.
Submitted by Babauca, also found by 4funnds, Agontuk, ahahaHard1k, coinsspor, Cosmo, crunter, deccs, dyce1110, Eniwealth, fellows, hjo, lostOpcode, lucilfer12, Manga, Messiah, mskey, Nyx, oxwhite, oziajibogu, Rikka, S1m0n, smchuzza, Spottedhyena0, Takarez, tipao, twicek, v12, and ZakMHTX
Found with V12
contracts/kinetic-router/src/swap.rs#L298-L320contracts/kinetic-router/src/storage.rs#L9contracts/kinetic-router/src/operations.rs#L96-L106contracts/kinetic-router/src/operations.rs#L415-L425
swap_collateral() can create a brand new reserve position without enforcing either of the two invariants that every other reserve-entry path enforces:
- the per-user reserve cap,
MAX_USER_RESERVES = 15 - the minimum first position size,
MIN_FIRST_DEPOSIT = 1_000
Root Cause
The standard reserve-entry paths enforce the per-user reserve limit:
supply()at operations.rs:96-106 checkscount_active_reserves() >= MAX_USER_RESERVESbefore allowing a first position in a new reserve.borrow()at operations.rs:415-425 performs the same check before allowing a first borrow in a new reserve.validate_and_finalize_transfer()at router.rs:1876-1884 enforces the limit for aToken transfer recipients.
The supply() path also enforces the first-deposit floor at operations.rs:89-92:
if is_first_supply && amount < k2_shared::MIN_FIRST_DEPOSIT {
return Err(KineticRouterError::InvalidAmount);
}
swap_collateral() at swap.rs:298-320 skips both protections. It calls mint_scaled() on the destination aToken (line 305), then immediately sets user_config.set_using_as_collateral(...) (line 320) — with no count_active_reserves() check and no MIN_FIRST_DEPOSIT check.
The protocol documentation at docs/03-CORE-CONCEPTS.md:358-363 explicitly states this limit is security-critical:
the protocol enforces MAXUSERRESERVES = 15 per user (storage.rs:9). Supply and borrow operations revert with MaxUserReservesExceeded if a user attempts to interact with more than 15 distinct reserves. This tighter limit bounds the health-factor computation loop and prevents reserve fragmentation attacks.
Impact
- An attacker can expand their user bitmap beyond the documented hard cap using dust swaps (
amount=2, min_amount_out=1). - Each new reserve slot costs virtually nothing, making fragmentation cheap.
- A fragmented underwater account can become unliquidatable when the health-factor computation exceeds Soroban resource limits, stranding bad debt and threatening protocol solvency.
Recommended Remediation
Apply the same new-reserve protections inside swap_collateral() that already exist in supply() and borrow():
- Detect whether the destination reserve is a first position for the user.
- If it is, reject the swap when
count_active_reserves() >= MAX_USER_RESERVES. - If it is, reject the swap when
amount_to_supply < MIN_FIRST_DEPOSIT.
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 swap_collateral path mints the destination aToken and marks it as collateral without calling the reserve-count and minimum-first-deposit checks that supply and borrow perform.
Impact
An attacker could fragment an account across many reserves cheaply, and a fragmented underwater account could become unliquidatable when the health-factor computation exceeds resource limits, stranding bad debt.
What the attacker needed
Ability to call swap_collateral; small dust amounts to fund swaps
The fix
The swap_collateral function should detect a first position in the destination reserve and reject it when the user already holds the maximum number of reserves or when the amount is below the minimum first deposit.
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 lending protocol lets each user interact with only a limited number of different asset pools, partly so the system can quickly check whether the user is still safe to borrow against. One function that moves collateral between pools forgot to apply that limit, so someone could spread tiny amounts across many pools. If that account later goes bad, the safety check may become too expensive to run, leaving the debt unpaid.
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.