Skip to content
Business logic Audit finding Intermediate

ConstantProductPool & HybridPool : Adding and removing unbalanced liquidity yields slightly more tokens than swap

The mint fee for unbalanced liquidity is also given to the minter, effectively acting as a rebate. This makes adding and removing liquidity slightly more profitable than swapping directly.

GreyArt Follow

Originally disclosed on Code4rena

Submitted by GreyArt, also found by broccoli

Impact

A mint fee is applied whenever unbalanced liquidity is added, because it is akin to swapping the excess token amount for the other token.

However, the current implementation distributes the minted fee to the minter as well (when he should be excluded). It therefore acts as a rebate of sorts.

As a result, it makes adding and removing liquidity as opposed to swapping directly (negligibly) more desirable. An example is given below using the Constant Product Pool to illustrate this point. The Hybrid pool exhibits similar behaviour.

Proof of Concept

  1. Initialize the pool with ETH-USDC sushi pool amounts. As of the time of writing, there is roughly 53586.556 ETH and 165143020.5295 USDC.
  2. Mint unbalanced LP with 5 ETH (& 0 USDC). This gives the user 138573488720892 / 1e18 LP tokens.
  3. Burn the minted LP tokens, giving the user 2.4963 ETH and 7692.40 USDC. This is therefore equivalent to swapping 5 - 2.4963 = 2.5037 ETH for 7692.4044 USDC.
  4. If the user were to swap the 2.5037 ETH directly, he would receive 7692.369221 (0.03 USDC lesser).

Recommended Mitigation Steps

The mint fee should be distributed to existing LPs first, by incrementing _reserve0 and _reserve1 with the fee amounts. The rest of the calculations follow after.

ConstantProductPool

(uint256 fee0, uint256 fee1) = _nonOptimalMintFee(amount0, amount1, _reserve0, _reserve1);
// increment reserve amounts with fees
_reserve0 += uint112(fee0);
_reserve1 += uint112(fee1);
unchecked {
    _totalSupply += _mintFee(_reserve0, _reserve1, _totalSupply);
}
uint256 computed = TridentMath.sqrt(balance0 * balance1);
...
kLast = computed;

HybridPool

(uint256 fee0, uint256 fee1) = _nonOptimalMintFee(amount0, amount1, _reserve0, _reserve1);
// increment reserve amounts with fees
_reserve0 += uint112(fee0);
_reserve1 += uint112(fee1);
uint256 newLiq = _computeLiquidity(balance0, balance1);
...

maxsam4 (Sushi) confirmed

The original report as published on Code4rena, by GreyArt. 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 mint fee is not properly excluded from the minter's share, so the minter receives a portion of the fee they paid.

Impact

Adding and removing liquidity yields slightly more tokens than swapping directly, but the difference is negligible.

What the attacker needed

Access to the pool; ability to add and remove liquidity

The fix

The mint fee should be distributed to existing LPs first, by incrementing the reserves with the fee amounts before calculating new liquidity.

How it was found

  1. Initialize the pool with ETH-USDC sushi pool amounts.
  2. Mint unbalanced LP with 5 ETH (& 0 USDC).
  3. Burn the minted LP tokens, giving the user 2.4963 ETH and 7692.40 USDC.
  4. Compare with swapping the 2.5037 ETH directly, which yields 0.03 USDC less.

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.

When you add liquidity to a pool in an unbalanced way, the protocol charges a fee because it's like swapping the excess token. The bug is that this fee is given back to the person who added liquidity, so they get a small discount. This means you can get slightly more tokens by adding and removing liquidity than by doing a normal swap.

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 GreyArt

View all

12 more disclosed reports, best first.

More from Sushi Trident contest phase 1

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.