Skip to content
Business logic Audit finding Intermediate

Sending tokens close to the maximum will fail and user will lose tokens

The deposit function checks the amount against a maximum limit without including the reward, while the sendFundsToUser function checks the amount plus reward against the same limit. If a user deposits an amount just below the limit, the reward can push the total over the limit, causing the executor's transaction to revert and the user to lose their funds.

pedroais Follow

Originally disclosed on Code4rena

Submitted by pedroais, also found by WatchPug

LiquidityPool.sol#L171 LiquidityPool.sol#L273

When a user calls the deposit function the reward amount is calculated and an event is emited with amount+reward as the transfer amount. The function checks amount is smaller than the max amount.

An executor then listens to this event and calls sendFundsToUser with rewards + amount as the amount parameter. This function checks amount+reward is smaller than max amount.

This is a problem because the amount transferred may be in the limit but amount + reward could pass the limit and the executor won’t be able to send the transaction. The user will lose the funds. Both checks should be made with the reward or without the reward but the checks should be the same for this not to happen.

Step by step : Max transfer is set to 50 for token A Bob transfers 49 tokens, this will pass since 49<50. The reward is calculated in 2 tokens. The executor then calls sendFundsToUser with 52. This transaction will revert and user will lose their tokens.

This value of amount includes rewards but the previous check didn’t include rewards: LiquidityPool.sol#L273.

Recommended Mitigation Steps

Both checks should be made over the same amount = amount + rewards

ankurdubey521 (Biconomy) disputed and commented:

We handle this issue by setting a slightly larger limit in the transfer config of each token on the destination chain.

pauliax (judge) decreased severity to Medium and commented:

Even though the sponsor is already aware of and mitigates this issue, it could still be fixed algorithmically to prevent accidental loss of funds. I am leaving this as of medium severity.


The original report as published on Code4rena, by pedroais. 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

The deposit function checks only the amount against the maximum, while sendFundsToUser checks amount plus reward against the same maximum, creating an inconsistency that can cause the second check to fail.

Impact

A user could lose their tokens if the reward pushes the total over the maximum limit, causing the transfer to fail.

What the attacker needed

User deposits an amount close to the maximum limit; Reward calculation pushes total over the limit

The fix

Both checks should be made over the same amount, which is amount plus reward.

How it was found

  1. Set the maximum transfer limit to 50 for token A.
  2. Bob transfers 49 tokens, which passes because 49 is less than 50.
  3. The reward is calculated as 2 tokens.
  4. The executor calls sendFundsToUser with 52, which reverts because it exceeds the limit.
  5. Bob loses his tokens.

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 user sends tokens to a service. The service adds a reward, but the check for the maximum allowed amount is done differently at two steps. If the user sends almost the maximum, the reward makes the total exceed the limit, so the transfer fails and the user's tokens are stuck.

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 pedroais

View all

6 more disclosed reports, best first.

More from Biconomy - Smart Contract Wallet contest

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.