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.
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.
/// @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
IndexPoolof 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.
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
- Alice, the first liquidity provider, transfers 1e18 WBTC and 1e18 USDT to mint 100e18 of liquidity.
- 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.