Skip to content
Business logic Audit finding Intermediate

Wrong formula when add fee incentivePool can lead to loss of funds.

The getAmountToTransfer function in LiquidityPool incorrectly divides the entire incentivePool balance by BASE_DIVISOR when adding a fee, causing the pool to shrink rapidly to zero. This locks the accumulated tokens in the contract, leading to loss of funds.

minhquanym Follow

Originally disclosed on Code4rena

Submitted by minhquanym, also found by cmichel, hickuphh3, and WatchPug

LiquidityPool.sol#L319-L322

The getAmountToTransfer function of LiquidityPool updates incentivePool[tokenAddress] by adding some fee to it but the formula is wrong and the value of incentivePool[tokenAddress] will be divided by BASE_DIVISOR (10000000000) each time. After just a few time, the value of incentivePool[tokenAddress] will become zero and that amount of tokenAddress token will be locked in contract.

Proof of concept

Line 319-322

incentivePool[tokenAddress] = (incentivePool[tokenAddress] + (amount * (transferFeePerc - tokenManager.getTokensInfo(tokenAddress).equilibriumFee))) / BASE_DIVISOR;

Let x = incentivePool[tokenAddress], y = amount, z = transferFeePerc and t = tokenManager.getTokensInfo(tokenAddress).equilibriumFee. Then that be written as

x = (x + (y * (z - t))) / BASE_DIVISOR;
x = x / BASE_DIVISOR + (y * (z - t)) / BASE_DIVISOR;

Recommended Mitigation Steps

Fix the bug by changing lines 319-322 to:

incentivePool[tokenAddress] += (amount * (transferFeePerc - tokenManager.getTokensInfo(tokenAddress).equilibriumFee)) / BASE_DIVISOR;

ankurdubey521 (Biconomy) confirmed

pauliax (judge) commented:

Great find, the wrong order of arithmetic operations deserves a severity of high as it would have serious negative consequences.


The original report as published on Code4rena, by minhquanym. 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 arithmetic expression incorrectly applies division to the entire sum instead of only the new fee amount, due to wrong operator precedence.

Impact

The incentive pool balance is repeatedly divided, quickly becoming zero, and the accumulated tokens are locked in the contract, causing loss of funds.

What the attacker needed

None

The fix

The code should be changed to add the divided fee to the existing pool balance, not divide the whole sum.

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 smart contract keeps a pool of fees. Each time a fee is added, the code mistakenly divides the whole pool by a huge number, so the pool shrinks to nothing. That means the fees are stuck forever and users lose money.

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 minhquanym

View all

28 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.