Users can bypass the first deposit check
The first-supply check in the router relied on the user's scaled token balance being zero, so anyone could send a victim a tiny amount of aToken to make that balance non-zero and skip the minimum first deposit, the oracle price check and the collateral flag. This let a user supply into an unpriced reserve, earn yield while health-factor maths reverted, and potentially open a share inflation attack.
Kalogerone Follow with abdelhaq16, DemoreX and 8 others
Originally disclosed on Code4rena
Submitted by Kalogerone, also found by abdelhaq16, DemoreX, marcioj, mustapha, oziajibogu, Peter3144, ProngsDev, Quintus, samuraii77, and TheCodeReaper
These are the fist supply checks:
pub fn supply(
env: Env,
caller: Address,
asset: Address,
amount: u128,
on_behalf_of: Address,
_referral_code: u32,
) -> Result<(), KineticRouterError> {
// ...
// M-04: Enforce minimum first deposit to prevent share inflation attacks
if is_first_supply && amount < k2_shared::MIN_FIRST_DEPOSIT {
return Err(KineticRouterError::InvalidAmount);
}
// Update user configuration only if first time using this reserve
// Preserve user's existing collateral preference for subsequent supplies
if is_first_supply {
let mut user_config = storage::get_user_configuration(&env, &on_behalf_of);
let reserve_id = k2_shared::safe_reserve_id(&env, updated_reserve_data.id);
// Check if this is a new reserve position (not already using as collateral)
if !user_config.is_using_as_collateral(reserve_id) {
let active_count = user_config.count_active_reserves();
if active_count >= storage::MAX_USER_RESERVES {
panic_with_error!(&env, UserReserveError::MaxUserReservesExceeded);
}
}
crate::price::verify_oracle_price_exists_and_nonzero(&env, &asset)?;
user_config.set_using_as_collateral(reserve_id, true);
storage::set_user_configuration(&env, &on_behalf_of, &user_config);
}
// ...
}
Τhis can be bypassed. Imagine a user who has never supplied and has 0 ATokens. Someone transfers this user just 1 Wei of AToken setting his scaled balance > 0. In the mint_scaled called his scaled balance is checked and because it is > 0, it returns is_first_supply as false.
pub fn mint_scaled(
env: Env,
caller: Address,
on_behalf_of: Address,
amount: u128,
index: u128,
) -> Result<(bool, i128, i128), TokenError> {
// ...
// M-14
let scaled_u128 = ray_div_down(&env, amount, index).map_err(|_| TokenError::InvalidIndex)?;
let amount_scaled = safe_u128_to_i128(&env, scaled_u128);
let current_scaled_balance = storage::get_scaled_balance(&env, &on_behalf_of);
let is_first_supply = current_scaled_balance == 0;
// ...
}
A user is able to supply into a reserve without checking if the oracle is valid (crate::price::verify_oracle_price_exists_and_nonzero(&env, &asset)). The user supplies into a reserve that can’t be priced. They earn yield but their HF math reverts thereafter, so withdrawal-with-debt and liquidation both break.
Additionally, his supply doesn’t enable the collateral bit (user_config.set_using_as_collateral(reserve_id, true)) requiring the user to go through additional transactions to do it.
Lastly, the user bypasses the MIN_FIRST_DEPOSIT amount and it’s possible that an inflation attack can now take place as the comment suggests:
// M-04: Enforce minimum first deposit to prevent share inflation attacks
if is_first_supply && amount < k2_shared::MIN_FIRST_DEPOSIT {
return Err(KineticRouterError::InvalidAmount);
}
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 first-supply determination uses the scaled balance, which any third party can make non-zero by transferring a minimal amount of aToken, rather than tracking whether the user has actually supplied to that reserve.
Impact
The user could supply into a reserve that cannot be priced, earn yield while health-factor calculations revert so withdrawal-with-debt and liquidation break, skip the minimum first deposit, and possibly enable a share inflation attack.
What the attacker needed
Attacker can transfer aToken to victim; victim has not supplied before
The fix
The first-supply state should be tracked explicitly per user and reserve rather than inferred from a transferable token balance.
How it was found
- A user has never supplied and holds zero aTokens.
- An attacker transfers one wei of aToken to that user, making their scaled balance greater than zero.
- The user then supplies to the reserve and the contract treats it as not a first supply.
- The minimum first deposit, oracle price check and collateral flag are all skipped.
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 contract decides whether a deposit is someone's first by looking at their token balance. If a stranger sends that person even a tiny amount of the token first, the contract thinks they have deposited before and skips several safety checks. Those checks normally stop very small first deposits, confirm the asset has a valid price, and mark the deposit as usable 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.