Skip to content
Business logic Audit finding Intermediate

IndexPool.mint The first liquidity provider is forced to supply assets in the same amount, which may cause a significant amount of fund loss

When an IndexPool has no reserves yet, the mint function forces the first liquidity provider to deposit the same raw amount of every token, ignoring each token's weight, decimals and price. An attacker could then swap cheap tokens for the valuable ones and take most of the first provider's value.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by broccoli

When reserve == 0, amountIn for all the tokens will be set to the same amount: ratio, regardless of the weights, decimals and market prices of the assets.

The first liquidity provider may not be aware of this so that it may create an arbitrage opportunity for flashbots to take a significant portion of the value of The first liquidity provider’s liquidity.

IndexPool.sol#L93 L105

/// @dev Mints LP tokens - should be called via the router after transferring `bento` tokens.
/// The router must ensure that sufficient LP tokens are minted by using the return value.
function mint(bytes calldata data) public override lock returns (uint256 liquidity) {
    (address recipient, uint256 toMint) = abi.decode(data, (address, uint256));

    uint120 ratio = uint120(_div(toMint, totalSupply));

    for (uint256 i = 0; i < tokens.length; i++) {
        address tokenIn = tokens[i];
        uint120 reserve = records[tokenIn].reserve;
        // @dev If token balance is '0', initialize with `ratio`.
        uint120 amountIn = reserve != 0 ? uint120(_mul(ratio, reserve)) : ratio;
        require(amountIn >= MIN_BALANCE, "MIN_BALANCE");
        // @dev Check Trident router has sent `amountIn` for skim into pool.
        unchecked {
            // @dev This is safe from overflow - only logged amounts handled.
            require(_balance(tokenIn) >= amountIn + reserve, "NOT_RECEIVED");
            records[tokenIn].reserve += amountIn;
        }
        emit Mint(msg.sender, tokenIn, amountIn, recipient);
    }
    _mint(recipient, toMint);
    liquidity = toMint;
}

Proof of Concept

Given:

  • A IndexPool of 99% USDT and 1% WBTC;
  • Alice is the first liquidity provider.
  • Alice transfers 1e18 WBTC and 1e18 USDT to mint 100e18 of liquidity;
  • Bob can use 100e18 USDT (~$100) to swap out most of the balance of WBTC.

Impact

A significant portion (>90% in the case above) of the user’s funds can be lost due to arbitrage.

Recommendation

Consider allowing the first liquidity provider to use custom amountIn values for each token or always takes the MIN_BALANCE of each token.

The original report as published on Code4rena, by WatchPug. 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 initial mint path uses a single ratio value for every token instead of deriving each token's amount from its weight, decimals and price.

Impact

A significant portion, over 90% in the example, of the first provider's funds could be lost to arbitrage.

What the attacker needed

Attacker can trade against the pool; pool has no reserves yet; first provider deposits equal raw amounts

The fix

The first liquidity provider should be allowed to set a custom amount for each token, or the pool should always take the minimum balance of each token.

How it was found

  1. Alice, the first liquidity provider, transfers 1e18 WBTC and 1e18 USDT to mint 100e18 of liquidity.
  2. Bob uses 100e18 USDT to swap out most of the pool's WBTC balance.

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 shared pot of two or more tokens that people trade against. The first person to fill the pot is meant to add tokens in the proportions the pool advertises, but here the code asks for an equal number of each token, so a cheap token and an expensive one go in side by side. Anyone can then trade the cheap token for the expensive one and walk away with most of the first person's 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 WatchPug

View all

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