Skip to content
Business logic Audit finding Advanced

Approved spender exceed nominal allowance by splitting aToken transfers into dust chunks

The aToken contract's transfer_from function checks and deducts allowance using the nominal amount, but the actual balance movement rounds up the scaled share amount. An approved spender can split a transfer into many dust-sized calls, each consuming minimal allowance but moving a full scaled share, allowing them to transfer more value than the allowance intended.

johnyfwesh Follow with 0xepley, Agontuk and 8 others

Originally disclosed on Code4rena

Submitted by johnyfwesh, also found by 0xepley, Agontuk, Benji687, cht1206, coinsspor, khaye26, odeili, p4y4b13, qed, and TheCodeReaper

  • contracts/a-token/src/contract.rs #L83-L119

ATokenContract::transfer_from() treats allowance as a nominal accounting value. It checks that the spender’s allowance is at least the caller supplied amount, then subtracts exactly that nominal amount from allowance.

The actual balance movement happens later in ATokenContract::transfer_internal(). That function converts the same nominal amount into scaled aToken shares with ray_div_up(amount, liquidity_index). Because this conversion rounds up, a small dust transfer can move one whole scaled share even when the nominal allowance consumed by the call is only one minimal unit.

When the liquidity index is greater than RAY, one scaled share represents more than one nominal unit of redeemable value. A spender can therefore split an approved transfer into many dust-sized transfer_from() calls. Each call consumes only the dust nominal amount from allowance, but each call credits a rounded-up scaled share to the recipient. After enough calls, the recipient can hold scaled shares worth more redeemable underlying than the nominal allowance the holder granted.

The issue does not mint protocol value out of thin air. The excess value is debited from the approving holder’s scaled balance and credited to the recipient. The broken boundary is the holder’s approval limit: an approved spender can move more redeemable aToken value than the approval amount was intended to authorize.

This causes real user fund loss from addresses that granted allowance.

Affected code

let current_allowance = Self::allowance(env.clone(), from.clone(), spender.clone());

if current_allowance < amount {
    return Err(TokenError::InsufficientAllowance);
}

if let Some(mut allowance_data) = storage::get_allowance(&env, &from, &spender) {
    allowance_data.amount = current_allowance.checked_sub(amount)
        .ok_or(TokenError::InsufficientAllowance)?;
    storage::set_allowance(&env, &from, &spender, &allowance_data);
}

transfer_from() validates and decrements allowance by the nominal amount parameter. It does not account for the rounded scaled amount that will actually be debited from the holder and credited to the recipient.

let amount_u128 = safe_i128_to_u128(&env, amount);
let scaled_u128 = ray_div_up(&env, amount_u128, liquidity_index).map_err(|_| TokenError::InvalidIndex)?;
let scaled_amount = safe_u128_to_i128(&env, scaled_u128);
let from_scaled_balance = storage::get_scaled_balance(&env, &from);

if from_scaled_balance < scaled_amount {
    return Err(TokenError::InsufficientBalance);
}

let new_from_balance = from_scaled_balance.checked_sub(scaled_amount)
    .ok_or(TokenError::InsufficientBalance)?;
let to_scaled_balance = storage::get_scaled_balance(&env, &to);
let new_to_balance = to_scaled_balance.checked_add(scaled_amount)
    .ok_or(TokenError::TransferFailed)?;

transfer_internal() rounds the scaled share amount upward and applies that rounded amount to balances.

pub fn ray_div_up(env: &Env, a: u128, b: u128) -> Result<u128, crate::KineticRouterError> {
    if b == 0 {
        return Err(crate::KineticRouterError::MathOverflow);
    }

    let a_u256 = U256::from_u128(env, a);
    let b_u256 = U256::from_u128(env, b);
    let ray_u256 = U256::from_u128(env, RAY);
    let one = U256::from_u128(env, 1u128);

    // Ceiling division: (a * RAY + b - 1) / b
    let numerator = a_u256.mul(&ray_u256).add(&b_u256).sub(&one);
    let result = numerator.div(&b_u256);

This is the ceiling division responsible for converting dust transfers into one full scaled share when the exact scaled result is fractional.

pub fn balance_of_with_index(env: &Env, id: &Address, liquidity_index: u128) -> i128 {
    let scaled_balance = storage::get_scaled_balance(env, id);
    // S-04
    let scaled_balance_u128 = safe_i128_to_u128(env, scaled_balance);
    let result = ray_mul(env, scaled_balance_u128, liquidity_index)
        .unwrap_or_else(|_| {
            soroban_sdk::panic_with_error!(env, KineticRouterError::MathOverflow)
        });

The recipient’s scaled shares are later presented as nominal aToken balance by multiplying by the liquidity index.

let scaled_u128 = ray_div_up(&env, amount, index).map_err(|_| TokenError::InvalidIndex)?;
let mut amount_scaled = safe_u128_to_i128(&env, scaled_u128);
let current_scaled_balance = storage::get_scaled_balance(&env, &on_behalf_of);

...

let actual_amount = ray_mul_down(&env, safe_i128_to_u128(&env, amount_scaled), index)
    .map_err(|_| TokenError::InvalidIndex)?;
let actual_amount = actual_amount.min(amount);

The burn-and-transfer path shows that accumulated scaled shares can be converted into underlying value.

Impact

Approved spender can overuse an allowance

A holder may grant a spender an allowance of N nominal aToken units. The spender can split that allowance into N one-unit transfers when the liquidity index is above RAY. Each call spends one nominal allowance unit, but each call can move one scaled share. If the index is 2 * RAY, those N scaled shares are worth 2N nominal units.

The loss is charged to the approving holder

This is not protocol-wide inflation. The rounded-up scaled shares are debited from the holder’s scaled balance. The holder loses more redeemable aToken value than the allowance amount implied, and the recipient receives the corresponding extra shares.

Realistic attacker requirements

  • The attacker does not need admin or governance privileges.
  • The attacker must be an approved spender for the victim, or control an address/contract that the victim approved.
  • The victim must have enough scaled balance to cover the rounded-up transfers.

Recommended mitigation steps

  1. Make allowance accounting consume the same unit of value that balances consume. For delegated transfers, compute scaled_amount first and charge allowance based on the nominal value represented by that scaled amount at the current index.
  2. Alternatively, reject delegated transfers where ray_div_up(amount, index) would represent more nominal value than amount, unless the allowance is charged for the rounded-up represented value.
  3. Consider storing aToken allowances in scaled units, or store both nominal and scaled allowance with a clearly defined conversion rule, so repeated rounding cannot be farmed across many calls.

Proof of Concept

See original finding for full Proof of Concept

The original report as published on Code4rena, by johnyfwesh. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 allowance is deducted in nominal units while the balance transfer uses a rounded-up scaled share amount, creating a mismatch that can be exploited through repeated small transfers.

Impact

An approved spender can transfer more redeemable aToken value than the allowance intended, causing fund loss to the approving holder; the excess is debited from the holder's scaled balance, not minted.

What the attacker needed

Victim has approved the attacker as spender; liquidity index is greater than RAY; victim has sufficient scaled balance

The fix

The allowance should be charged based on the scaled amount actually moved, or the contract should reject transfers where rounding would move more value than the nominal amount.

How it was found

  1. The victim approves a spender for a nominal allowance.
  2. The spender calls transfer_from many times with a dust amount (e.g., 1 unit).
  3. Each call deducts only the dust amount from allowance but credits a rounded-up scaled share to the recipient.
  4. After enough calls, the recipient holds scaled shares worth more than the original allowance.

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.

This is a smart contract bug in a token that uses an interest-bearing balance system. When you approve someone to spend your tokens, the contract checks the allowance in normal token units, but the actual transfer moves shares that represent a larger value due to rounding up. By making many tiny transfers, the approved person can take more than you allowed.

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.

More by johnyfwesh

View all

8 more disclosed reports, best first.

More from K2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.