Skip to content
Business logic Audit finding Intermediate

IndexPool initial LP supply computation is wrong

The IndexPool contract mints initial LP tokens to the zero address, causing the first mint to require an amount of each token that is independent of its decimals and value. This makes initial liquidity provision economically unjustifiable for pools with tokens of different values or decimals, and allows a second LP to pay less for the same LP tokens.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The IndexPool.constructor function already mints INIT_POOL_SUPPLY = 100 * 1e18 = 1e20 LP tokens to the zero address.

When trying to use the pool, someone has to provide the actual initial reserve tokens in mint. On the first mint, the pool reserves are zero and the token amount required to mint is just this ratio itself: uint120 amountIn = reserve != 0 ? uint120(_mul(ratio, reserve)) : ratio;

Note that the amountIn is independent of the token which does not make much sense. This implies that all tokens must be provided in equal “raw amounts”, regardless of their decimals and value.

POC

Issue 1

Imagine I want to create a DAI/WBTC pool. If I want to initialize the pool with 100$ of DAI, amountIn = ratio needs to be 100*1e18=1e20 as DAI has 18 decimals. However, I now also need to supply 1e20 of WBTC (which has 8 decimals) and I’d need to pay 1e20/1e8 * priceOfBTC, over a quadrillion dollars to match it with the 100$ of DAI.

Issue 2

Even in a pool where all tokens have the same decimals and the same value, like USDC <> USDT, it leads to issues:

  • Initial minter calls mint with toMint = 1e20 which sets ratio = 1e20 * 1e18 / 1e20 = 1e18 and thus amountIn = 1e18 as well. The total supply increases to 2e20.
  • Second minter needs to pay less tokens to receive the same amount of 1e18 LP tokens as the first minter. This should never be the case. toMint = 1e20 => ratio = 1e20 * 1e18 / 2e20 = 0.5e18. Then amountIn = ratio * reserve / 1e18 = 0.5*reserve = 0.5e18. They only pay half of what the first LP provider had to pay.

Impact

It’s unclear why it’s assumed that the pool’s tokens are all in equal value - this is not a StableSwap-like pool.

Any pool that uses tokens that don’t have the same value and share the same decimals cannot be used because initial liquidity cannot be provided in an economically justifiable way.

It also leads to issues where the second LP supplier has to pay less tokens to receive the exact same amount of LP tokens that the initial minter receives. They can steal from the initial LP provider by burning these tokens again.

Recommended Mitigation Steps

Do not mint the initial token supply to the zero address in the constructor.

Do it like Uniswap/Balancer and let the first liquidity provider provide arbitrary token amounts, then mint the initial pool supply. If reserve == 0, amountIn should just take the pool balances that were transferred to this account.

In case the initial mint to the zero address in the constructor was done to prevent the “Uniswap-attack” where the price of a single wei of LP token can be very high and price out LPs, send a small fraction of this initial LP supply (~1000) to the zero address after it was minted to the first supplier in mint.

maxsam4 (Sushi) confirmed

The original report as published on Code4rena, by cmichel. 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 constructor mints initial LP supply to the zero address, and the first mint calculates amountIn as the ratio itself, independent of token decimals and value.

Impact

Pools with tokens of different values or decimals cannot be initialised economically, and in equal-decimal pools the second LP can pay less for the same LP tokens, potentially stealing from the first LP.

What the attacker needed

Access to the IndexPool contract; Tokens with different decimals or values; Ability to call mint function

The fix

The constructor should not mint initial LP supply to the zero address; instead, the first liquidity provider should provide arbitrary token amounts and receive the initial pool supply, with a small fraction sent to the zero address after minting to prevent the Uniswap attack.

How it was found

  1. Deploy or use an IndexPool with tokens of different decimals or values.
  2. Attempt to provide initial liquidity by calling mint with a desired amount of LP tokens.
  3. Observe that the required amount of each token is the same raw number, leading to excessive cost for tokens with fewer decimals or higher value.
  4. Alternatively, for a pool with equal-decimal tokens, the first minter pays a certain amount, and the second minter pays half for the same LP 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 liquidity pool is a smart contract where users deposit tokens to enable trading. When you deposit, you get LP tokens representing your share. The bug is that the pool forces the first depositor to put in the same raw number of each token, ignoring that tokens have different values and decimal places. This makes it impossible to start a pool with tokens like DAI and WBTC without paying an absurd amount.

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 cmichel

View all

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