Skip to content
Business logic Audit finding Intermediate

Possible frontrun on deposits on LiquidityPool

The liquidity pool reward calculation lacks time-weighted checks, allowing a malicious user to front-run a victim's deposit with a higher-fee transaction, then deposit again after the victim's transaction, collecting rewards twice. This sandwich attack lets the attacker double-dip rewards by manipulating the pool state before and after the victim's deposit.

Cantor_Dust Follow

Originally disclosed on Code4rena

Submitted by Cantor_Dust, also found by WatchPug

Rewards are given to a user for depositing either ERC20 tokens or their native token into the LiquidityPool. This reward is used to incentivize users to deposit funds into the liquidity pool when the pool is not in an equilibrium state.

For regular users, this liquidity pool state fluctuates based on the frequency and amount of deposits made to the liquidity pool. If a malicious user can control the state of the liquidity pool before a victim deposits tokens into the liquidity pool, they can gain double rewards.

To gain these double rewards, a malicious user can watch the mempool for transactions that will receive a reward when the deposit occurs. When a malicious user sees that victim deposit, the malicious user can attach a higher fee to their transaction and initiate a deposit. This will allow the malicious user’s transaction to front-run before the victim’s transaction.

Once the malicious user’s deposit is complete, the liquidity pool state will be in a near equilibrium state. Then, the victim’s deposit will occur which causes the liquidity pool state to no longer be in equilibrium.

Finally, the malicious user will make a final deposit gaining yet another reward for bringing the liquidity pool state back to equilibrium.

To sum up, a malicious user can create a sandwich attack where they deposit their own tokens before and after a victim’s transaction. This will allow the malicious user to double dip and gain rewards twice due to victim’s deposit.

Proof of Concept

Let’s look at the depositNative function which is the simpler of the two deposit functions.

The key component in the depositNative function is the getRewardAmount which can be found here. The getRewardAmount calculates how much available vs supplied liquidity exists in the liquidity pool. Here there are no time-weighted checks to calculate the available vs. supplied liquidity. With a lack of checks for time-weight and that there are no frontrun checks against deposits, it’s trivial to front-run deposits and control the liquidity of the liquidity such that the reward amount can be double-dipped.

Recommended Mitigation Steps

  1. By allowing each deposit to manipulate the liquidity pool state from either a deficient or excessive state, malicious users can double dip on rewards.
  2. Alternative approaches to calculating rewards is possible, for example a dutch auction style deposit system where rewards are distributed evenly could reduce an impact of a frontrun attack.
  3. A simpler approach is to record liquidity states at specific block timestamps and check against the timestamp for the current block state.

ankurdubey521 (Biconomy) acknowledged

pauliax (judge) commented:

Great find, mempool lurking monsters could definitely use this opportunity.


The original report as published on Code4rena, by Cantor_Dust. 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 reward calculation does not use time-weighted checks and there are no front-running protections on deposits, so an attacker can manipulate the pool state within the same block or adjacent blocks to claim rewards multiple times.

Impact

A malicious user could gain double rewards by sandwiching a victim's deposit, potentially draining reward funds from the pool.

What the attacker needed

Ability to monitor mempool; ability to submit transactions with higher fees; victim makes a deposit

The fix

The reward calculation should incorporate time-weighted checks and record liquidity states at specific block timestamps to prevent front-running, or use an alternative reward distribution method such as a Dutch auction style deposit system.

How it was found

  1. Attacker monitors the mempool for a victim's deposit transaction that will receive a reward.
  2. Attacker submits a deposit transaction with a higher fee to front-run the victim's deposit.
  3. Victim's deposit executes, moving the pool out of equilibrium.
  4. Attacker makes a second deposit to bring the pool back to equilibrium, earning another reward.

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 liquidity pool is a smart contract where users deposit tokens and earn rewards for helping balance it. The report shows that someone can watch pending transactions, pay a higher fee to get their deposit processed first, then deposit again after the victim's transaction, earning rewards twice. This is unfair because the attacker takes extra rewards without providing lasting liquidity.

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