Skip to content
Business logic Audit finding Intermediate

Small deposits could prevent users from withdrawing their funds

The deposit function scales the amount by a factor of 100, so deposits below 100 result in zero tokens transferred but the internal balance is still increased by the original amount. An attacker can repeatedly make tiny deposits on behalf of any user, inflating their internal balance and creating a mismatch with the contract's real token balance, which can prevent legitimate withdrawals.

gln Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#46892 [SC-High] small deposits could prevent users from withdrawing their funds

Submitted on Jun 5th 2025 at 23:20:32 UTC by @gln for IOP | Paradex

Description

Brief/Intro

Small deposits could be used to introduce inconsistency between real balance and internal balance of Paradex contract.

Vulnerability Details

Let's look at the code from paraclear.cairo:

     fn deposit(
            ref self: ContractState, token_address: ContractAddress, amount: felt252,
        ) -> felt252 {
            assert!(token_address.is_non_zero(), "Deposit: token_address is zero");
            let recipient = get_caller_address();
            self.account._add_new_account_if_not_exists(recipient);
            self.token._deposit(recipient, recipient, token_address, amount)
        }

Implementation of _deposit function from token.cairo:

 fn _deposit(
            ref self: ComponentState<TContractState>,
            sender: ContractAddress,
            recipient: ContractAddress,
            token_address: ContractAddress,
            amount: felt252,
        ) -> felt252 {
            let token_dispatcher = ERC20ABIDispatcher { contract_address: token_address };
            let decimals = token_dispatcher.decimals();

            let contract_address = get_contract_address();
1)            let amount_scaled: u256 = amount.into() / self._scale_factor(decimals);

            let allowance_amount: u256 = token_dispatcher.allowance(sender, contract_address);
            assert!(
                allowance_amount >= amount_scaled,
                "Deposit: Insufficient allowance {allowance_amount}, amount_scaled: {amount_scaled}",
            );

            self._detect_transfer_restriction(sender, recipient, token_address, amount_scaled);

2)            let is_transfer_successful = token_dispatcher
                .transferFrom(sender, contract_address, amount_scaled);
            assert!(is_transfer_successful, "Deposit: Transfer failed");

3)            let updated_balance_amount = self
                .upsert_asset_balance(
                    account: recipient,
                    token_address: token_address,
                    balance_change: amount.try_into().unwrap(),
                );
            self.emit(Deposit { account: recipient, token_address, amount });
            updated_balance_amount.into()
        }

  1. scale factor is 100, so if 'amount' is less than 100, amount_scaled will be set to 0
  2. transferFrom() does not transfer USDC, as amount_scaled is zero
  3. upsert_asset_balance() will change internal balance of account, note it uses original 'amount' value

The accounts' balances stored in Paraclear_token_asset_balance Map.

If a malicious user will deposit a huge number of small deposits, difference between real USDC balance and balance stored in Paraclear_token_asset_balance map will increase.

As a result, some users may not be able to withdraw their funds or their liquidation may fail.

Impact Details

User may not be able to withdraw their funds from contract.

The attack can be executed against any user by using deposit_on_behalf_of() function.

Attacker may increase internal balance of any user (stored in Paraclear_token_asset_balance map) arbitrarily.

It will introduce inconsistency between real funds stored in USDC contract and internal balance stored in Paradex contract.

Proof of Concept

Proof of Concept

Attack works like this:

  1. Alice deposits some amount of funds to contract
  2. Bob executes attack and withdraws some small amount from contract
  3. Now Alice will not be able to withdraw her funds

PoC reproduction:

  1. apply patch (see gist link - https://gist.github.com/gln7/f790708c867cfb13c93f3d9899a914a5 )
  2. copy mock_erc20.cairo to paraclear/src directory
  3. run poc
$ cd src/paraclear
$ snforge test test_small_deposit_issue
...
Running 1 test(s) from tests/
XXXXKE Alice after deposit 100000 balance 199999000
XXXXKE Bob balance 450
XXXXKE Alice tries to withdraw, balance before 199999000, account value 100000
[FAIL] paradex_paraclear::paraclear::tests::test_paraclear::test_small_deposit_issue

Failure data:
    0x496e73756666696369656e742062616c616e6365 ('Insufficient balance')

As you can see, Alice tries to withdraw her funds and transaction reverts.

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

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 deposit function scales the amount for the token transfer but uses the unscaled amount to update the internal balance, causing a mismatch when the scaled amount rounds to zero.

Impact

Users may be unable to withdraw their funds, and liquidations may fail, because the internal balance no longer matches the real token balance.

What the attacker needed

Attacker can call deposit_on_behalf_of; victim has funds in the contract

The fix

The deposit function should update the internal balance using the scaled amount (amount_scaled) rather than the original amount, or reject deposits that round down to zero.

How it was found

  1. Alice deposits some funds into the contract.
  2. Bob performs many small deposits on behalf of Alice using deposit_on_behalf_of, each below the scaling threshold.
  3. Bob withdraws a small amount from the contract.
  4. Alice attempts to withdraw her funds but the transaction reverts due to insufficient balance.

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.

The smart contract keeps its own record of how much each user has deposited, but it also holds real tokens. When someone deposits a very small amount, the contract rounds down the actual tokens transferred to zero, yet still adds the full amount to the user's internal balance. By doing this many times for a victim, the attacker makes the internal balance much larger than the real tokens, so when the victim tries to withdraw, the contract cannot pay and the withdrawal fails.

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 gln

View all

15 more disclosed reports, best first.

More from Paradex

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.