Reserve deficit is excluded from borrow-cap and debt-ceiling checks, allowing new borrows above configured risk limits
The borrow-cap and debt-ceiling checks count only the live debt-token supply and ignore the stored reserve deficit created by bad-debt liquidation. After a deficit exists, a borrower with sufficient collateral can open new debt that pushes total reserve exposure above the configured cap or ceiling.
0xastronatey Follow with accessControl, derkomai and 15 others
Originally disclosed on Code4rena
Submitted by 0xastronatey, also found by accessControl, derkomai, dipanshuchhanikar, Drothon, dzdzdz05, fuddle_yichi, harry, khaye26, mabdelnafea, PadIA, qed, rubencrxz, sahuang, tradingview, udogodwin, xw6fqfrry8, and y4y
contracts/kinetic-router/src/liquidation.rs#L576-L610contracts/kinetic-router/src/validation.rs#L367-L409contracts/kinetic-router/src/operations.rs#L320-L330contracts/kinetic-router/src/treasury.rs#L107-L140
When liquidation burns unrecoverable bad debt, K2 stores that loss in RESERVE_DEFICIT and reduces the debt-token supply accordingly. The borrow-cap and debt-ceiling gate in validate_borrow_cap_after_interest later checks only the live debt-token supply plus the new borrow amount. It never adds the stored reserve deficit, even though the protocol itself treats that deficit as real outstanding reserve exposure that must be covered by transferring underlying tokens back into the reserve (via cover_deficit). After a bad-debt liquidation, any borrower with sufficient collateral can open new debt that makes reserve_deficit + live_debt exceed the configured borrow cap or debt ceiling, bypassing the protocol’s hard exposure limits precisely when the reserve is already impaired.
Root Cause
1) Bad debt is moved out of debt-token supply into RESERVE_DEFICIT
When collateral is exhausted during liquidation, the router burns the borrower’s remaining debt and records the unrecovered amount as a reserve deficit.
contracts/kinetic-router/src/liquidation.rs#L576-L610
// Post-burn bad debt socialization.
// When collateral_cap_triggered, ALL remaining debt is unrecoverable (no collateral left
// for another liquidation). Socialize unconditionally — threshold is irrelevant here.
let min_remaining_whole = updated_debt_reserve_data.configuration.get_min_remaining_debt();
if remaining_debt_balance > 0 {
let remaining_debt_u128 = safe_i128_to_u128(env, remaining_debt_balance);
if collateral_cap_triggered {
// All collateral seized — remaining debt is unrecoverable bad debt.
let mut bad_debt_burn_args = Vec::new(env);
bad_debt_burn_args.push_back(IntoVal::into_val(&env.current_contract_address(), env));
bad_debt_burn_args.push_back(user.to_val());
bad_debt_burn_args.push_back(IntoVal::into_val(&remaining_debt_u128, env));
bad_debt_burn_args.push_back(IntoVal::into_val(
&updated_debt_reserve_data.variable_borrow_index,
env,
));
let bad_debt_burn_result = env.try_invoke_contract::<(bool, i128, i128), KineticRouterError>(
&updated_debt_reserve_data.debt_token_address,
&Symbol::new(env, "burn_scaled"),
bad_debt_burn_args,
);
// ...
// Track bad debt as deficit instead of socializing to depositors
storage::add_reserve_deficit(env, &debt_asset, remaining_debt_u128);
// <-- deficit remains real reserve exposure, but is no longer included in debt-token total supply
After this path executes, the debt token’s total_supply is reduced by the burned amount, but the reserve’s real exposure has not decreased - it has merely been reclassified from live debt into tracked deficit.
2) Borrow-cap and debt-ceiling validation ignores that tracked deficit
The borrow gate computes new_total_debt from only the debt token’s indexed total supply and the requested borrow amount. It never adds storage::get_reserve_deficit(env, asset), even though that deficit is unrecovered bad debt for the same reserve.
contracts/kinetic-router/src/validation.rs#L367-L409
pub fn validate_borrow_cap_after_interest(
env: &Env,
amount: u128,
reserve_data: &k2_shared::ReserveData,
asset: &Address,
variable_borrow_index: u128,
) -> Result<(), KineticRouterError> {
let borrow_cap = reserve_data.configuration.get_borrow_cap();
let debt_ceiling = storage::get_reserve_debt_ceiling(env, asset);
// F-14
if borrow_cap > 0 || debt_ceiling > 0 {
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
// <-- only live debt-token supply is counted; reserve_deficit is excluded
let decimals = reserve_data.configuration.get_decimals();
let multiplier = 10u128
.checked_pow(decimals as u32)
.ok_or(KineticRouterError::MathOverflow)?;
let new_total_debt = current_debt
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// <-- cap/ceiling compare against current_debt + amount, not current_debt + deficit + amount
if borrow_cap > 0 {
let cap_in_smallest_units = borrow_cap
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > cap_in_smallest_units {
return Err(KineticRouterError::BorrowCapExceeded);
}
}
if debt_ceiling > 0 {
let ceiling_in_smallest_units = debt_ceiling
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > ceiling_in_smallest_units {
return Err(KineticRouterError::DebtCeilingExceeded);
}
}
}
The invariant live_debt + reserve_deficit <= borrow_cap is never checked. Only live_debt + new_borrow <= borrow_cap is enforced.
3) The borrow path relies on the deficit-blind check as the sole cap gate
Every borrow calls this validation before health-factor and liquidity checks. If the borrower has enough collateral and the aToken still has cash, the borrow succeeds even when total reserve exposure already exceeds the configured cap once deficit is included.
contracts/kinetic-router/src/operations.rs#L320-L330
if on_behalf_of == updated_reserve_data.debt_token_address {
panic_with_error!(&env, OperationError::RecipientIsDebtToken);
}
// Re-validate cap after interest accrual (interest increases total debt)
validation::validate_borrow_cap_after_interest(
&env, amount, &updated_reserve_data, &asset,
updated_reserve_data.variable_borrow_index)?;
// <-- this is the only borrow-cap/debt-ceiling gate, and it ignores stored reserve deficit
let oracle_config = crate::price::get_oracle_config(&env)?;
let oracle_to_wad = calculate_oracle_to_wad_factor(oracle_config.price_precision);
validation::validate_user_can_borrow(
&env, &on_behalf_of, &asset, amount, &updated_reserve_data, oracle_to_wad)?;
4) The protocol itself treats deficit as a real cash shortfall that must be covered
cover_deficit requires someone to transfer real underlying into the aToken before the deficit is reduced. This confirms the deficit is not just metadata - it is outstanding reserve exposure that represents a real cash shortfall in the lending pool.
contracts/kinetic-router/src/treasury.rs#L107-L140
let current_deficit = storage::get_reserve_deficit(&env, &asset);
if current_deficit == 0 {
return Err(KineticRouterError::InvalidAmount);
}
// Cover at most the current deficit
let cover_amount = amount.min(current_deficit);
// Get the reserve's aToken address
let reserve_data = storage::get_reserve_data(&env, &asset)?;
// Transfer underlying tokens from caller to aToken contract (replenishes pool liquidity)
let transfer_args = soroban_sdk::vec![
&env,
caller.to_val(),
reserve_data.a_token_address.to_val(),
IntoVal::into_val(&safe_u128_to_i128(&env, cover_amount), &env),
];
// <-- deficit is only reduced after real underlying is transferred back into the reserve
// ...
// Reduce the tracked deficit
storage::reduce_reserve_deficit(&env, &asset, cover_amount);
Internal Pre-conditions
- The debt reserve has a non-zero borrow cap or debt ceiling configured.
- A liquidation has created a non-zero
RESERVE_DEFICITfor that reserve (collateral was exhausted before debt was fully repaid). - The debt token’s live total supply was reduced when bad debt was burned.
- The reserve still has enough aToken cash for a later borrow.
- The attacker has enough collateral to pass normal health-factor validation.
External Pre-conditions
A borrower becomes deeply undercollateralized because collateral price falls. The PoC below uses the test oracle admin to model this market movement; the exploit itself does not require malicious admin behaviour. No DEX liquidity, frontrunning, callback reentrancy, or privileged role cooperation is required after the deficit exists.
Attack Path
- The reserve admin has configured
asset_bwith a 900-token borrow cap, a normal risk-control setting. - A borrower supplies 1,000
asset_aas collateral and borrows 800asset_b, staying below the 900-token cap. asset_afalls from$1.00to$0.01. With 7-decimal assets and the test oracle’s 14-decimal$1price, this isPRICE_ONE_DOLLAR / 100 = 1_000_000_000_000.- A liquidator liquidates the borrower. The borrower has only about
$10of collateral against about$800of debt, so collateral is exhausted. The router burns the unrecoverable remaining debt and records it asasset_breserve deficit atliquidation.rs#L609-L610. - Because that remaining debt was burned, the debt token’s total supply for
asset_bis now near zero, butget_reserve_deficit(asset_b)is roughly 790 tokens. - A second attacker supplies 500
asset_bas collateral and borrows 200asset_b. The borrow should be rejected becausedeficit + new_live_debt ≈ 790 + 200 = 990, which exceeds the 900-token cap. - The borrow succeeds because
validate_borrow_cap_after_interestchecks onlycurrent_debt + amountatvalidation.rs#L386-L390, wherecurrent_debtis the live debt-token total after bad debt was burned.
Worked example with realistic parameters
ASSET_DECIMALS = 7, PRICE_ONE_DOLLAR = 100_000_000_000_000, and USER_STARTING_BALANCE = 10_000_000_000 are the existing K2 C4 scaffold defaults in tests/c4/src/lib.rs#L163-L169. A 900-token cap is 900 * 10^7 = 9_000_000_000 units. After the bad-debt liquidation, a deficit of about 7_900_000_000 units remains. A new 2_000_000_000 unit borrow passes because the cap check sees only 0 + 2_000_000_000 <= 9_000_000_000, even though actual exposure is about 7_900_000_000 + 2_000_000_000 > 9_000_000_000.
Impact
- Impact: Configured borrow caps and debt ceilings are hard risk limits designed to bound the protocol’s exposure to any single reserve. Once bad debt is recorded, the protocol can take on additional debt above those limits, increasing supplier and treasury exposure precisely when the reserve is already impaired.
- Likelihood: Requires a reserve deficit, but deficits are an explicitly supported liquidation outcome (not an artificial state). Any deep price crash on a collateral asset can trigger this.
Negative Check
-
Why existing validation does not block this attack:
- Access control does not prevent this. The victim, liquidator, and later borrower each use their own authorized public entrypoints:
borrow,liquidation_call, andborrow. - The reentrancy guard does not apply because this is a normal multi-transaction sequence, not reentrancy.
- The aToken cash check does not prevent this because the reserve can still have large LP liquidity after a bad-debt event.
- Health-factor validation does not prevent this because the later borrower supplies sufficient collateral. The broken invariant is the reserve-level cap, not borrower solvency.
- Access control does not prevent this. The victim, liquidator, and later borrower each use their own authorized public entrypoints:
-
Why this is distinct from known issues:
- This is not the V12 “Deficit treated as available liquidity” issue. That finding targets interest-rate repricing in
calculate_interest_rates_for_reserveatcalculation.rs#L938-L999. This finding targets the separate borrow-cap/debt-ceiling gate invalidation.rs#L367-L409and shows a hard risk-limit bypass even without relying on rate mispricing. - This is not Halborn 7.15. Halborn’s borrow-limit issue was a general cap-enforcement inconsistency; this path depends specifically on post-liquidation
RESERVE_DEFICITbeing excluded after debt-token supply is burned. - This is not a WatchPug duplicate; the listed WatchPug findings cover aToken transfer/liquidation settlement/rounding and min-remaining-debt conflicts, not deficit-aware borrow-cap accounting.
- This is not the V12 “Deficit treated as available liquidity” issue. That finding targets interest-rate repricing in
Mitigation
Include the tracked reserve deficit in both borrow-cap and debt-ceiling exposure calculations.
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
let current_deficit = storage::get_reserve_deficit(env, asset); // Fixed: include unrecovered bad debt
let new_total_debt = current_debt
.checked_add(current_deficit)
.ok_or(KineticRouterError::MathOverflow)?
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// Compare this deficit-aware exposure against both borrow_cap and debt_ceiling.
Proof of Concept
See original finding for full Proof of Concept
Context
K2 is a Soroban (Stellar) lending protocol whose router contract lives under contracts/kinetic-router. Like most lending markets it exposes two reserve-level risk limits: a borrow cap and a debt ceiling, both configured per asset by the reserve admin. The purpose of these limits is to bound how much of a single asset the protocol can be exposed to, regardless of how much collateral an individual borrower posts.
The router enforces those limits in a single function, validate_borrow_cap_after_interest, called from the borrow path in operations.rs. The check compares the debt token's current indexed total supply plus the requested borrow amount against the configured cap and ceiling.
Separately, the protocol has a bad-debt mechanism. When a liquidation exhausts a borrower's collateral before the debt is fully repaid, the router burns the remaining debt and records the unrecovered amount in a per-asset RESERVE_DEFICIT. That deficit is treated as real exposure: it can only be cleared through cover_deficit, which requires someone to transfer actual underlying tokens into the aToken contract before the tracked deficit is reduced.
The finding is that the borrow-cap and debt-ceiling gate never adds the stored deficit to the exposure it measures. After a bad-debt liquidation, new borrowing can push reserve_deficit + live_debt above the configured hard limit.
Setup
The report lists the following files as relevant:
contracts/kinetic-router/src/liquidation.rs(lines 576 to 610)contracts/kinetic-router/src/validation.rs(lines 367 to 409)contracts/kinetic-router/src/operations.rs(lines 320 to 330)contracts/kinetic-router/src/treasury.rs(lines 107 to 140)
The proof of concept uses the existing K2 C4 test scaffold defaults in tests/c4/src/lib.rs (lines 163 to 169):
ASSET_DECIMALS = 7PRICE_ONE_DOLLAR = 100_000_000_000_000USER_STARTING_BALANCE = 10_000_000_000
Internal preconditions stated in the report:
- The debt reserve has a non-zero borrow cap or debt ceiling configured.
- A liquidation has created a non-zero
RESERVE_DEFICITfor that reserve (collateral was exhausted before debt was fully repaid). - The debt token's live total supply was reduced when bad debt was burned.
- The reserve still has enough aToken cash for a later borrow.
- The attacker has enough collateral to pass normal health-factor validation.
External preconditions: a borrower becomes deeply undercollateralized because a collateral price falls. The PoC uses the test oracle admin to model that market movement; the exploit itself does not require malicious admin behaviour. The report states that no DEX liquidity, frontrunning, callback reentrancy or privileged role cooperation is required once the deficit exists.
Finding it
There is an asymmetry between how the protocol accounts for bad debt and how it measures exposure for its risk limits. When bad debt is burned, the debt token's total_supply drops, but the reserve's real exposure does not. The loss is reclassified into RESERVE_DEFICIT, and the protocol's own cover_deficit function confirms that this deficit represents a genuine cash shortfall: it only shrinks after real underlying is transferred back into the reserve.
The borrow gate, however, derives new_total_debt purely from the debt token's indexed total supply plus the requested amount. It never reads storage::get_reserve_deficit(env, asset). The invariant that should hold, live_debt + reserve_deficit <= borrow_cap, is never checked; only live_debt + new_borrow <= borrow_cap is enforced. That means the hard limit can be exceeded exactly when the reserve is already impaired.
Exploitation
Step 1: configure a cap
The reserve admin configures asset_b with a 900-token borrow cap, described in the report as a normal risk-control setting.
Step 2: borrow below the cap
A borrower supplies 1,000 asset_a as collateral and borrows 800 asset_b, staying below the 900-token cap.
Step 3: crash the collateral price
asset_a falls from $1.00 to $0.01. With 7-decimal assets and the test oracle's 14-decimal $1 price, the new price is PRICE_ONE_DOLLAR / 100 = 1_000_000_000_000.
Step 4: liquidate and burn bad debt
A liquidator liquidates the borrower. The borrower has only about $10 of collateral against about $800 of debt, so collateral is exhausted. The router burns the unrecoverable remaining debt and records it as an asset_b reserve deficit at liquidation.rs#L609-L610.
The code path that does this is in liquidation.rs#L576-L610:
// Post-burn bad debt socialization.
// When collateral_cap_triggered, ALL remaining debt is unrecoverable (no collateral left
// for another liquidation). Socialize unconditionally — threshold is irrelevant here.
let min_remaining_whole = updated_debt_reserve_data.configuration.get_min_remaining_debt();
if remaining_debt_balance > 0 {
let remaining_debt_u128 = safe_i128_to_u128(env, remaining_debt_balance);
if collateral_cap_triggered {
// All collateral seized — remaining debt is unrecoverable bad debt.
let mut bad_debt_burn_args = Vec::new(env);
bad_debt_burn_args.push_back(IntoVal::into_val(&env.current_contract_address(), env));
bad_debt_burn_args.push_back(user.to_val());
bad_debt_burn_args.push_back(IntoVal::into_val(&remaining_debt_u128, env));
bad_debt_burn_args.push_back(IntoVal::into_val(
&updated_debt_reserve_data.variable_borrow_index,
env,
));
let bad_debt_burn_result = env.try_invoke_contract::<(bool, i128, i128), KineticRouterError>(
&updated_debt_reserve_data.debt_token_address,
&Symbol::new(env, "burn_scaled"),
bad_debt_burn_args,
);
// ...
// Track bad debt as deficit instead of socializing to depositors
storage::add_reserve_deficit(env, &debt_asset, remaining_debt_u128);
// <-- deficit remains real reserve exposure, but is no longer included in debt-token total supply
After this path, the debt token's total supply is reduced by the burned amount, and the same amount is recorded as deficit. The exposure has been reclassified, not removed.
Step 5: observe the state
Because the remaining debt was burned, the debt token's total supply for asset_b is now near zero, but get_reserve_deficit(asset_b) is roughly 790 tokens.
Step 6: borrow again, above the real limit
A second attacker supplies 500 asset_b as collateral and borrows 200 asset_b. The borrow should be rejected because deficit + new_live_debt ≈ 790 + 200 = 990, which exceeds the 900-token cap.
The borrow succeeds because validate_borrow_cap_after_interest checks only current_debt + amount at validation.rs#L386-L390, where current_debt is the live debt-token total after the bad debt was burned.
The gate itself, from validation.rs#L367-L409:
pub fn validate_borrow_cap_after_interest(
env: &Env,
amount: u128,
reserve_data: &k2_shared::ReserveData,
asset: &Address,
variable_borrow_index: u128,
) -> Result<(), KineticRouterError> {
let borrow_cap = reserve_data.configuration.get_borrow_cap();
let debt_ceiling = storage::get_reserve_debt_ceiling(env, asset);
// F-14
if borrow_cap > 0 || debt_ceiling > 0 {
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
// <-- only live debt-token supply is counted; reserve_deficit is excluded
let decimals = reserve_data.configuration.get_decimals();
let multiplier = 10u128
.checked_pow(decimals as u32)
.ok_or(KineticRouterError::MathOverflow)?;
let new_total_debt = current_debt
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// <-- cap/ceiling compare against current_debt + amount, not current_debt + deficit + amount
if borrow_cap > 0 {
let cap_in_smallest_units = borrow_cap
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > cap_in_smallest_units {
return Err(KineticRouterError::BorrowCapExceeded);
}
}
if debt_ceiling > 0 {
let ceiling_in_smallest_units = debt_ceiling
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > ceiling_in_smallest_units {
return Err(KineticRouterError::DebtCeilingExceeded);
}
}
}
Step 7: confirm the gate is the only one
The borrow path in operations.rs#L320-L330 calls this validation before the health-factor and liquidity checks, and it is the sole borrow-cap/debt-ceiling gate:
if on_behalf_of == updated_reserve_data.debt_token_address {
panic_with_error!(&env, OperationError::RecipientIsDebtToken);
}
// Re-validate cap after interest accrual (interest increases total debt)
validation::validate_borrow_cap_after_interest(
&env, amount, &updated_reserve_data, &asset,
updated_reserve_data.variable_borrow_index)?;
// <-- this is the only borrow-cap/debt-ceiling gate, and it ignores stored reserve deficit
let oracle_config = crate::price::get_oracle_config(&env)?;
let oracle_to_wad = calculate_oracle_to_wad_factor(oracle_config.price_precision);
validation::validate_user_can_borrow(
&env, &on_behalf_of, &asset, amount, &updated_reserve_data, oracle_to_wad)?;
If the borrower has enough collateral and the aToken still has cash, the borrow succeeds even when total reserve exposure already exceeds the configured cap once the deficit is included.
Worked example with realistic parameters
Using the scaffold defaults, a 900-token cap is 900 * 10^7 = 9_000_000_000 units. After the bad-debt liquidation, a deficit of about 7_900_000_000 units remains. A new 2_000_000_000 unit borrow passes because the cap check sees only 0 + 2_000_000_000 <= 9_000_000_000, even though actual exposure is about 7_900_000_000 + 2_000_000_000 > 9_000_000_000.
Why the deficit is real exposure
cover_deficit in treasury.rs#L107-L140 requires real underlying to be transferred into the aToken before the deficit is reduced:
let current_deficit = storage::get_reserve_deficit(&env, &asset);
if current_deficit == 0 {
return Err(KineticRouterError::InvalidAmount);
}
// Cover at most the current deficit
let cover_amount = amount.min(current_deficit);
// Get the reserve's aToken address
let reserve_data = storage::get_reserve_data(&env, &asset)?;
// Transfer underlying tokens from caller to aToken contract (replenishes pool liquidity)
let transfer_args = soroban_sdk::vec![
&env,
caller.to_val(),
reserve_data.a_token_address.to_val(),
IntoVal::into_val(&safe_u128_to_i128(&env, cover_amount), &env),
];
// <-- deficit is only reduced after real underlying is transferred back into the reserve
// ...
// Reduce the tracked deficit
storage::reduce_reserve_deficit(&env, &asset, cover_amount);
This confirms the deficit is not metadata: it is outstanding reserve exposure representing a real cash shortfall in the lending pool.
Root cause
The borrow-cap and debt-ceiling calculation in validate_borrow_cap_after_interest measures exposure as current_debt + amount, where current_debt is the debt token's indexed total supply. Bad-debt liquidation moves unrecovered debt out of that supply and into RESERVE_DEFICIT, so the measured exposure understates the reserve's real exposure by exactly the deficit. The invariant live_debt + reserve_deficit <= borrow_cap is never enforced.
Why existing defences did not stop it, per the report's negative check:
- Access control: the victim, liquidator and later borrower each use their own authorised public entrypoints (
borrow,liquidation_call,borrow). - Reentrancy guard: not applicable, because this is a normal multi-transaction sequence.
- aToken cash check: does not prevent it, because the reserve can still have large LP liquidity after a bad-debt event.
- Health-factor validation: does not prevent it, because the later borrower supplies sufficient collateral. The broken invariant is the reserve-level cap, not borrower solvency.
The report also distinguishes this from known issues:
- It is not the V12 "Deficit treated as available liquidity" issue, which targets interest-rate repricing in
calculate_interest_rates_for_reserveatcalculation.rs#L938-L999. This finding targets the separate borrow-cap/debt-ceiling gate invalidation.rs#L367-L409and shows a hard risk-limit bypass without relying on rate mispricing. - It is not Halborn 7.15, a general cap-enforcement inconsistency; this path depends specifically on post-liquidation
RESERVE_DEFICITbeing excluded after debt-token supply is burned. - It is not a WatchPug duplicate; the listed WatchPug findings cover aToken transfer, liquidation settlement, rounding and min-remaining-debt conflicts, not deficit-aware borrow-cap accounting.
Impact
Borrow caps and debt ceilings are hard risk limits designed to bound the protocol's exposure to any single reserve. Once bad debt is recorded, the protocol can take on additional debt above those limits, increasing supplier and treasury exposure precisely when the reserve is already impaired.
Likelihood: the attack requires a reserve deficit, but deficits are an explicitly supported liquidation outcome rather than an artificial state. Any deep price crash on a collateral asset can trigger this.
Fix
The report's mitigation is to include the tracked reserve deficit in both the borrow-cap and debt-ceiling exposure calculations:
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
let current_deficit = storage::get_reserve_deficit(env, asset); // Fixed: include unrecovered bad debt
let new_total_debt = current_debt
.checked_add(current_deficit)
.ok_or(KineticRouterError::MathOverflow)?
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// Compare this deficit-aware exposure against both borrow_cap and debt_ceiling.
Variants to test
- Debt ceiling only. Configure a reserve with a debt ceiling but no borrow cap and repeat the sequence. A positive result is a borrow that succeeds while
deficit + live_debt + amountexceeds the ceiling. - Partial deficit coverage. Call
cover_deficitfor part of the deficit, then borrow. A positive result is a borrow that passes while the remaining deficit plus new debt exceeds the limit, showing the check ignores the residual. - Multiple bad-debt events. Trigger several liquidations that each add to
RESERVE_DEFICITbefore any borrow. A positive result is a borrow that passes with a deficit far above the cap, confirming the deficit is never accumulated into the check. - Interest accrual interaction. Borrow after interest has accrued on remaining live debt, so
current_debtis non-zero. A positive result is a borrow that passes whilecurrent_debt + deficit + amountexceeds the cap, showing the omission is independent of the supply being near zero. - Other exposure gates. Look for other functions that compare reserve exposure against a configured limit using only debt-token supply (for example liquidation or repay paths that re-check caps). A positive result is any such comparison that omits
get_reserve_deficit.
What happened, in plain words
K2 is a lending protocol: a piece of software that lets people deposit one kind of digital token and borrow another, a bit like a pawn shop where you leave something valuable behind and walk out with cash. It runs on Stellar, using a smart-contract framework called Soroban. A smart contract is a program that lives on a blockchain and runs exactly as written, with nobody able to change it mid-run.
Every lending market needs safety limits. If the protocol lends out too much of one token, a single crash in that token can sink the whole pool. K2 therefore has two per-asset limits, set by the reserve admin (the person or team responsible for that particular pool of funds):
- a borrow cap, the maximum amount of that token the protocol will ever let people borrow in total;
- a debt ceiling, a second, similar upper bound on total debt for that asset.
Both are meant to be hard walls. The report shows that after a particular kind of loss, the wall has a hole in it: new borrowing can push the protocol past the limit without any check stopping it.
The loss in question is bad debt. When someone borrows and their collateral (the valuable thing they left behind) falls so far in price that it no longer covers the loan, a liquidator steps in. A liquidator is a third party who repays part of the bad loan and takes the collateral in return. Sometimes the collateral runs out before the debt is fully repaid. The leftover, unrecoverable part is bad debt.
K2 handles bad debt by burning it: it destroys the record of that debt so the borrower no longer owes it. But the money is still gone from the pool. So K2 writes the lost amount into a separate bookkeeping entry called RESERVE_DEFICIT, meaning "this reserve is short by this much". The protocol itself treats that number as real: the only way to make it go down is a function called cover_deficit, which requires someone to actually transfer real tokens back into the pool.
The bug is simple to state. The function that enforces the borrow cap and debt ceiling adds up only the debt that is still live, plus the new amount being borrowed. It never adds the deficit. So after a bad-debt event, the protocol can lend out more than its own configured limit, exactly when the pool is already weakened.
Background you need first
A few ideas come up repeatedly, so here they are from zero.
Token. A digital unit of value on a blockchain. K2 deals in several, named asset_a, asset_b and so on in the report.
Collateral. Something of value you hand over as security for a loan. If you do not repay, the lender keeps it. In K2 you deposit tokens as collateral and borrow other tokens against them.
Health factor. A number that says whether your loan is safely covered by your collateral. Above a threshold, you are fine. Below it, you are undercollateralised and can be liquidated.
Liquidation. The forced sale of a shaky borrower's collateral to repay their debt. It protects the pool from losses.
Reserve. One pool of one token inside the protocol, with its own settings, its own cap and its own accounting.
aToken. The receipt token you get when you deposit into a reserve. It represents your claim on the pool's cash. When the report says "the aToken still has cash", it means the pool still holds enough deposited tokens to lend out.
Debt token. The internal token that tracks how much has been borrowed from a reserve. Its total supply is, in effect, the protocol's record of live debt.
Burning. Permanently destroying tokens or debt records so they no longer exist. Burning debt makes the borrower's obligation disappear, but it does not bring back the missing money.
Invariant. A rule that should always be true. Here the intended invariant is: live debt plus reserve deficit must never exceed the borrow cap. The code only enforces: live debt plus the new borrow must not exceed the cap.
Proof of concept (PoC). A concrete, step-by-step demonstration that a bug can actually be triggered.
Context
The K2 router contract, the central piece of code that routes every borrow, repay and liquidation, lives under contracts/kinetic-router. It enforces the two risk limits in a single function, validate_borrow_cap_after_interest, which is called from the borrow path in operations.rs. That function compares the debt token's current total supply plus the requested borrow amount against the configured cap and ceiling.
Separately, the protocol has the bad-debt mechanism described above. When a liquidation exhausts a borrower's collateral before the debt is fully repaid, the router burns the remaining debt and records the unrecovered amount in a per-asset RESERVE_DEFICIT. That deficit is treated as real exposure: it can only be cleared through cover_deficit, which requires someone to transfer actual underlying tokens into the aToken contract before the tracked deficit is reduced.
The finding is that the borrow-cap and debt-ceiling gate never adds the stored deficit to the exposure it measures. After a bad-debt liquidation, new borrowing can push reserve_deficit + live_debt above the configured hard limit.
Setup
The report lists four files as relevant:
contracts/kinetic-router/src/liquidation.rs(lines 576 to 610)contracts/kinetic-router/src/validation.rs(lines 367 to 409)contracts/kinetic-router/src/operations.rs(lines 320 to 330)contracts/kinetic-router/src/treasury.rs(lines 107 to 140)
The proof of concept uses the existing K2 C4 test scaffold defaults in tests/c4/src/lib.rs (lines 163 to 169). A test scaffold is a ready-made test environment that ships with the project, so the researcher did not have to build a market from scratch:
ASSET_DECIMALS = 7PRICE_ONE_DOLLAR = 100_000_000_000_000USER_STARTING_BALANCE = 10_000_000_000
ASSET_DECIMALS = 7 means each token is split into 10 million tiny units, the way a pound splits into 100 pence. PRICE_ONE_DOLLAR is how the test price feed represents one dollar, scaled up so the maths stays in whole numbers. USER_STARTING_BALANCE is how many units each test user begins with.
The report states these internal preconditions, meaning conditions inside the protocol that must already hold:
- The debt reserve has a non-zero borrow cap or debt ceiling configured.
- A liquidation has created a non-zero
RESERVE_DEFICITfor that reserve (collateral was exhausted before debt was fully repaid). - The debt token's live total supply was reduced when bad debt was burned.
- The reserve still has enough aToken cash for a later borrow.
- The attacker has enough collateral to pass normal health-factor validation.
And this external precondition, meaning a condition in the outside world: a borrower becomes deeply undercollateralised because a collateral price falls. The PoC uses the test oracle admin to model that market movement. An oracle is the service that feeds prices into the protocol; the test oracle admin is simply the test-only switch that sets those prices. The exploit itself does not require malicious admin behaviour. The report states that no DEX liquidity, frontrunning, callback reentrancy or privileged role cooperation is required once the deficit exists. In plain terms: no market manipulation, no racing other transactions, no tricking the contract into re-entering itself, and no help from an insider.
Finding it
There is an asymmetry between how the protocol accounts for bad debt and how it measures exposure for its risk limits. When bad debt is burned, the debt token's total_supply drops, but the reserve's real exposure does not. The loss is reclassified into RESERVE_DEFICIT, and the protocol's own cover_deficit function confirms that this deficit represents a genuine cash shortfall: it only shrinks after real underlying is transferred back into the reserve.
The borrow gate, however, derives new_total_debt purely from the debt token's indexed total supply plus the requested amount. It never reads storage::get_reserve_deficit(env, asset). The invariant that should hold, live_debt + reserve_deficit <= borrow_cap, is never checked; only live_debt + new_borrow <= borrow_cap is enforced. That means the hard limit can be exceeded exactly when the reserve is already impaired.
Exploitation
Step 1: configure a cap
The reserve admin configures asset_b with a 900-token borrow cap, described in the report as a normal risk-control setting. This is the wall the rest of the sequence is meant to hit.
Step 2: borrow below the cap
A borrower supplies 1,000 asset_a as collateral and borrows 800 asset_b, staying below the 900-token cap. Everything is legitimate at this point: the loan is within limits and the collateral covers it.
Step 3: crash the collateral price
asset_a falls from $1.00 to $0.01. With 7-decimal assets and the test oracle's 14-decimal $1 price, the new price is PRICE_ONE_DOLLAR / 100 = 1_000_000_000_000. The division by 100 is simply a 99 percent drop. The borrower's collateral is now worth almost nothing against an 800-token debt.
Step 4: liquidate and burn bad debt
A liquidator liquidates the borrower. The borrower has only about $10 of collateral against about $800 of debt, so collateral is exhausted. The router burns the unrecoverable remaining debt and records it as an asset_b reserve deficit at liquidation.rs#L609-L610.
The code path that does this is in liquidation.rs#L576-L610:
// Post-burn bad debt socialization.
// When collateral_cap_triggered, ALL remaining debt is unrecoverable (no collateral left
// for another liquidation). Socialize unconditionally — threshold is irrelevant here.
let min_remaining_whole = updated_debt_reserve_data.configuration.get_min_remaining_debt();
if remaining_debt_balance > 0 {
let remaining_debt_u128 = safe_i128_to_u128(env, remaining_debt_balance);
if collateral_cap_triggered {
// All collateral seized — remaining debt is unrecoverable bad debt.
let mut bad_debt_burn_args = Vec::new(env);
bad_debt_burn_args.push_back(IntoVal::into_val(&env.current_contract_address(), env));
bad_debt_burn_args.push_back(user.to_val());
bad_debt_burn_args.push_back(IntoVal::into_val(&remaining_debt_u128, env));
bad_debt_burn_args.push_back(IntoVal::into_val(
&updated_debt_reserve_data.variable_borrow_index,
env,
));
let bad_debt_burn_result = env.try_invoke_contract::<(bool, i128, i128), KineticRouterError>(
&updated_debt_reserve_data.debt_token_address,
&Symbol::new(env, "burn_scaled"),
bad_debt_burn_args,
);
// ...
// Track bad debt as deficit instead of socializing to depositors
storage::add_reserve_deficit(env, &debt_asset, remaining_debt_u128);
// <-- deficit remains real reserve exposure, but is no longer included in debt-token total supply
Line by line, in plain words:
- The comments at the top explain the situation: the borrower's collateral has been fully taken, so whatever debt is left can never be recovered by another liquidation. The protocol calls this "socialising" the loss, meaning the loss is absorbed by the system rather than left on the borrower.
let min_remaining_whole = ...get_min_remaining_debt();reads a configured minimum debt threshold. The comment says the threshold is irrelevant on this path, because the debt is unrecoverable either way.if remaining_debt_balance > 0 {checks there is actually something left to deal with.let remaining_debt_u128 = safe_i128_to_u128(env, remaining_debt_balance);converts the amount into an unsigned number (one that cannot be negative), because a debt amount should never be negative.if collateral_cap_triggered {is the branch for the case where all collateral has been seized.- The
bad_debt_burn_argslines build the list of arguments for the next call: the router's own address, the borrower's address, the remaining debt amount, and the borrow index (a scaling factor used to track interest over time). env.try_invoke_contract::<...>(...)calls another contract, the debt token, and asks it to run a function namedburn_scaled. That is the step that destroys the debt record.storage::add_reserve_deficit(env, &debt_asset, remaining_debt_u128);is the crucial line. It writes the same amount into the deficit ledger.- The trailing comment spells out the bug's origin: the deficit is still real exposure, but it is no longer part of the debt token's total supply.
After this path, the debt token's total supply is reduced by the burned amount, and the same amount is recorded as deficit. The exposure has been reclassified, not removed. Think of moving a debt from one column of a spreadsheet to another: the total owed has not changed, but anyone reading only the first column will think it has.
Step 5: observe the state
Because the remaining debt was burned, the debt token's total supply for asset_b is now near zero, but get_reserve_deficit(asset_b) is roughly 790 tokens. The pool is short about 790 tokens, yet its live-debt counter says almost nothing is owed.
Step 6: borrow again, above the real limit
A second attacker supplies 500 asset_b as collateral and borrows 200 asset_b. The borrow should be rejected because deficit + new_live_debt ≈ 790 + 200 = 990, which exceeds the 900-token cap.
The borrow succeeds because validate_borrow_cap_after_interest checks only current_debt + amount at validation.rs#L386-L390, where current_debt is the live debt-token total after the bad debt was burned.
The gate itself, from validation.rs#L367-L409:
pub fn validate_borrow_cap_after_interest(
env: &Env,
amount: u128,
reserve_data: &k2_shared::ReserveData,
asset: &Address,
variable_borrow_index: u128,
) -> Result<(), KineticRouterError> {
let borrow_cap = reserve_data.configuration.get_borrow_cap();
let debt_ceiling = storage::get_reserve_debt_ceiling(env, asset);
// F-14
if borrow_cap > 0 || debt_ceiling > 0 {
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
// <-- only live debt-token supply is counted; reserve_deficit is excluded
let decimals = reserve_data.configuration.get_decimals();
let multiplier = 10u128
.checked_pow(decimals as u32)
.ok_or(KineticRouterError::MathOverflow)?;
let new_total_debt = current_debt
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// <-- cap/ceiling compare against current_debt + amount, not current_debt + deficit + amount
if borrow_cap > 0 {
let cap_in_smallest_units = borrow_cap
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > cap_in_smallest_units {
return Err(KineticRouterError::BorrowCapExceeded);
}
}
if debt_ceiling > 0 {
let ceiling_in_smallest_units = debt_ceiling
.checked_mul(multiplier)
.ok_or(KineticRouterError::MathOverflow)?;
if new_total_debt > ceiling_in_smallest_units {
return Err(KineticRouterError::DebtCeilingExceeded);
}
}
}
Line by line:
pub fn validate_borrow_cap_after_interest(starts the function. It takes the environment (env), the amount being borrowed, the reserve's data, the asset address and the borrow index.let borrow_cap = ...get_borrow_cap();andlet debt_ceiling = ...get_reserve_debt_ceiling(...)fetch the two configured limits.if borrow_cap > 0 || debt_ceiling > 0 {means the checks only run if at least one limit is set. A zero means "no limit".let current_debt = calculation::get_total_supply_with_index(...)reads the debt token's total supply, adjusted for accrued interest. This is the live-debt figure, and the comment marks the flaw: the reserve deficit is not included.- The
decimalsandmultiplierlines work out how many smallest units make one whole token, so the human-readable cap can be compared with raw on-chain amounts. let new_total_debt = current_debt.checked_add(amount)adds the requested borrow to live debt.checked_addmeans "add, but refuse and report an error if the result would overflow", a safety habit in smart contracts.- The second comment states the bug outright: the comparison uses
current_debt + amount, notcurrent_debt + deficit + amount. - The
if borrow_cap > 0block converts the cap into smallest units and returnsBorrowCapExceededif the new total is larger. - The
if debt_ceiling > 0block does the same for the ceiling, returningDebtCeilingExceeded.
Notice what is missing: nowhere does the function call get_reserve_deficit. The 790-token hole is invisible to it.
Step 7: confirm the gate is the only one
The borrow path in operations.rs#L320-L330 calls this validation before the health-factor and liquidity checks, and it is the sole borrow-cap/debt-ceiling gate:
if on_behalf_of == updated_reserve_data.debt_token_address {
panic_with_error!(&env, OperationError::RecipientIsDebtToken);
}
// Re-validate cap after interest accrual (interest increases total debt)
validation::validate_borrow_cap_after_interest(
&env, amount, &updated_reserve_data, &asset,
updated_reserve_data.variable_borrow_index)?;
// <-- this is the only borrow-cap/debt-ceiling gate, and it ignores stored reserve deficit
let oracle_config = crate::price::get_oracle_config(&env)?;
let oracle_to_wad = calculate_oracle_to_wad_factor(oracle_config.price_precision);
validation::validate_user_can_borrow(
&env, &on_behalf_of, &asset, amount, &updated_reserve_data, oracle_to_wad)?;
Line by line:
- The first
ifblocks a borrow where the recipient is the debt token itself, an odd case the protocol refuses outright. - The comment explains why the cap is checked here, after interest has been applied: interest makes the debt grow, so the check must run on the up-to-date figure.
- The
validation::validate_borrow_cap_after_interest(...)call is the gate from Step 6. The trailing comment records that it is the only such gate and that it ignores the stored deficit. - The
oracle_configandoracle_to_wadlines fetch the price feed settings and work out a conversion factor, so prices can be compared on a common scale. validation::validate_user_can_borrow(...)then checks the borrower's health factor and the pool's available cash.
If the borrower has enough collateral and the aToken still has cash, the borrow succeeds even when total reserve exposure already exceeds the configured cap once the deficit is included. This is the only borrow-cap and debt-ceiling gate on the borrow path.
Worked example with realistic parameters
Using the scaffold defaults, a 900-token cap is 900 * 10^7 = 9_000_000_000 units. After the bad-debt liquidation, a deficit of about 7_900_000_000 units remains. A new 2_000_000_000 unit borrow passes because the cap check sees only 0 + 2_000_000_000 <= 9_000_000_000, even though actual exposure is about 7_900_000_000 + 2_000_000_000 > 9_000_000_000.
In everyday terms: the rule says you may owe at most 900. You already have an unpaid 790 that the rulebook has filed in a different drawer. You ask to borrow 200 more. The clerk checks the first drawer, sees 0, adds 200, and says yes. The real total is 990.
Why the deficit is real exposure
cover_deficit in treasury.rs#L107-L140 requires real underlying to be transferred into the aToken before the deficit is reduced:
let current_deficit = storage::get_reserve_deficit(&env, &asset);
if current_deficit == 0 {
return Err(KineticRouterError::InvalidAmount);
}
// Cover at most the current deficit
let cover_amount = amount.min(current_deficit);
// Get the reserve's aToken address
let reserve_data = storage::get_reserve_data(&env, &asset)?;
// Transfer underlying tokens from caller to aToken contract (replenishes pool liquidity)
let transfer_args = soroban_sdk::vec![
&env,
caller.to_val(),
reserve_data.a_token_address.to_val(),
IntoVal::into_val(&safe_u128_to_i128(&env, cover_amount), &env),
];
// <-- deficit is only reduced after real underlying is transferred back into the reserve
// ...
// Reduce the tracked deficit
storage::reduce_reserve_deficit(&env, &asset, cover_amount);
Line by line:
let current_deficit = storage::get_reserve_deficit(&env, &asset);reads how short the reserve currently is.if current_deficit == 0 { return Err(...InvalidAmount); }refuses the call if there is nothing to cover.let cover_amount = amount.min(current_deficit);caps the payment at the size of the hole, so nobody can overpay.let reserve_data = storage::get_reserve_data(&env, &asset)?;loads the reserve's details, including its aToken address.- The
transfer_argsblock builds the arguments for a token transfer from the caller to the aToken contract. The comment says this replenishes pool liquidity. - The comment
// <-- deficit is only reduced after real underlying is transferred back into the reserveis the proof that the deficit is not a cosmetic number. storage::reduce_reserve_deficit(&env, &asset, cover_amount);finally lowers the deficit, and only after the money has arrived.
This confirms the deficit is not metadata: it is outstanding reserve exposure representing a real cash shortfall in the lending pool.
Root cause
The borrow-cap and debt-ceiling calculation in validate_borrow_cap_after_interest measures exposure as current_debt + amount, where current_debt is the debt token's indexed total supply. Bad-debt liquidation moves unrecovered debt out of that supply and into RESERVE_DEFICIT, so the measured exposure understates the reserve's real exposure by exactly the deficit. The invariant live_debt + reserve_deficit <= borrow_cap is never enforced.
Why existing defences did not stop it, per the report's negative check (a section where the researcher rules out the obvious objections):
- Access control: the victim, liquidator and later borrower each use their own authorised public entrypoints (
borrow,liquidation_call,borrow). Access control means the rules about who may call what. Nobody here calls anything they are not allowed to call. - Reentrancy guard: not applicable, because this is a normal multi-transaction sequence. A reentrancy guard stops a contract being called again while it is still running; this attack simply does one normal thing, then another, in separate transactions.
- aToken cash check: does not prevent it, because the reserve can still have large LP liquidity after a bad-debt event. LP liquidity here means the pool still holds plenty of deposited tokens.
- Health-factor validation: does not prevent it, because the later borrower supplies sufficient collateral. The broken invariant is the reserve-level cap, not borrower solvency.
The report also distinguishes this from known issues:
- It is not the V12 "Deficit treated as available liquidity" issue, which targets interest-rate repricing in
calculate_interest_rates_for_reserveatcalculation.rs#L938-L999. This finding targets the separate borrow-cap/debt-ceiling gate invalidation.rs#L367-L409and shows a hard risk-limit bypass without relying on rate mispricing. - It is not Halborn 7.15, a general cap-enforcement inconsistency; this path depends specifically on post-liquidation
RESERVE_DEFICITbeing excluded after debt-token supply is burned. - It is not a WatchPug duplicate; the listed WatchPug findings cover aToken transfer, liquidation settlement, rounding and min-remaining-debt conflicts, not deficit-aware borrow-cap accounting.
Impact
Borrow caps and debt ceilings are hard risk limits designed to bound the protocol's exposure to any single reserve. Once bad debt is recorded, the protocol can take on additional debt above those limits, increasing supplier and treasury exposure precisely when the reserve is already impaired. Suppliers are the people who deposited tokens into the pool; the treasury is the protocol's own pot of funds.
Likelihood: the attack requires a reserve deficit, but deficits are an explicitly supported liquidation outcome rather than an artificial state. Any deep price crash on a collateral asset can trigger this.
Fix
The report's mitigation is to include the tracked reserve deficit in both the borrow-cap and debt-ceiling exposure calculations:
let current_debt = calculation::get_total_supply_with_index(
env,
&reserve_data.debt_token_address,
variable_borrow_index,
)?;
let current_deficit = storage::get_reserve_deficit(env, asset); // Fixed: include unrecovered bad debt
let new_total_debt = current_debt
.checked_add(current_deficit)
.ok_or(KineticRouterError::MathOverflow)?
.checked_add(amount)
.ok_or(KineticRouterError::MathOverflow)?;
// Compare this deficit-aware exposure against both borrow_cap and debt_ceiling.
Line by line:
- The first statement still reads live debt, as before.
let current_deficit = storage::get_reserve_deficit(env, asset);is the new line: it fetches the hole in the reserve.new_total_debtis now built by adding live debt, then the deficit, then the requested amount, with overflow checks at each step.- The final comment says the resulting figure should be compared against both limits.
With this change, the worked example's exposure would include the deficit alongside the new borrow.
Variants to test
Follow-up cases worth trying, each a way to confirm the same omission from a different angle:
- Debt ceiling only. Configure a reserve with a debt ceiling but no borrow cap and repeat the sequence. A positive result is a borrow that succeeds while
deficit + live_debt + amountexceeds the ceiling. - Partial deficit coverage. Call
cover_deficitfor part of the deficit, then borrow. A positive result is a borrow that passes while the remaining deficit plus new debt exceeds the limit, showing the check ignores the residual. - Multiple bad-debt events. Trigger several liquidations that each add to
RESERVE_DEFICITbefore any borrow. A positive result is a borrow that passes with a deficit far above the cap, confirming the deficit is never accumulated into the check. - Interest accrual interaction. Borrow after interest has accrued on remaining live debt, so
current_debtis non-zero. A positive result is a borrow that passes whilecurrent_debt + deficit + amountexceeds the cap, showing the omission is independent of the supply being near zero. - Other exposure gates. Look for other functions that compare reserve exposure against a configured limit using only debt-token supply (for example liquidation or repay paths that re-check caps). A positive result is any such comparison that omits
get_reserve_deficit.
Glossary
- aToken: the receipt token you receive when you deposit into a K2 reserve; it represents your claim on the pool's cash.
- Access control: the rules deciding who is allowed to call which function.
- Bad debt: borrowed money that can no longer be recovered because the borrower's collateral ran out.
- Borrow cap: a configured maximum on how much of one asset the protocol will let people borrow in total.
- Burning: permanently destroying tokens or debt records.
- Checked arithmetic: arithmetic that refuses to continue and returns an error if a number would overflow or underflow.
- Collateral: an asset deposited as security for a loan.
- Debt ceiling: a second configured upper bound on total debt for one asset.
- Debt token: the internal token whose total supply tracks how much has been borrowed from a reserve.
- Decimals: how many smallest units make up one whole token.
- Deficit: the recorded amount by which a reserve is short after unrecoverable debt is written off.
- DEX: a decentralised exchange, a marketplace for swapping tokens.
- Frontrunning: racing ahead of someone else's transaction to profit from it.
- Health factor: a number expressing how safely a loan is covered by its collateral.
- Invariant: a rule that should always hold true.
- Liquidation: the forced seizure and sale of a shaky borrower's collateral to repay their debt.
- Liquidator: the third party who performs a liquidation and earns a fee for it.
- LP liquidity: tokens deposited into a pool by suppliers, available to be lent out.
- Oracle: the service that supplies asset prices to the protocol.
- Overflow: when a number grows beyond what its storage type can hold.
- Proof of concept (PoC): a concrete demonstration that a bug can be triggered.
- Reentrancy: a contract being called again while it is still executing; a reentrancy guard blocks this.
- Reserve: one pool of one token inside the protocol, with its own settings and accounting.
- Reserve admin: the party responsible for configuring a reserve's settings, including its limits.
- Router: the central contract that routes borrows, repays and liquidations.
- Smart contract: a program on a blockchain that runs exactly as written.
- Solvency: whether a borrower's assets cover their debts.
- Soroban: the smart-contract framework used on the Stellar blockchain.
- Stellar: the blockchain K2 runs on.
- Test scaffold: a ready-made test environment shipped with a project.
- Treasury: the protocol's own pot of funds.
- Underlying token: the real asset held by a reserve, as opposed to the receipt or debt tokens that represent it.