IndexPool’s INIT_POOL_SUPPLY is not fair.
The IndexPool contract mints a fixed initial supply of LP tokens to the zero address in its constructor, and the amount of value effectively burned depends on the size of the first liquidity provider's deposit. A first depositor choosing a non-optimal initial amount causes a large number of tokens to be burned, reducing the profit available to all liquidity providers in the pool.
Submitted by broccoli, also found by WatchPug
Impact
The indexPool mint INIT_POOL_SUPPLY to address 0 in the constructor. However, the value of the burned lp is decided by the first lp provider. According to the formula in IndexPool.sol L106.
AmountIn = first_lp_amount / INIT_POOL_SUPPLY and the burned lp worth = AmountIn * (INIT_POOL_SUPPLY) / (first_lp_amount + INIT_POOL_SUPPLY). If a pool is not initialized with optimal parameters, it would be a great number of tokens been burn. All lp providers in the pool would receive less profit.
The optimal parameter is 10**8. It’s likely no one would initialize with 10**8 wei in most pools. I consider this is a high-risk issue.
Proof of concept
There are two scenarios that the first lp provider can do. The lp provider provides the same amount of token in both cases. However, in the first scenario, he gets about 10 ** 18 * 10**18 lp while in the other scenario he gets 100 * 10**18 lp.
deposit_amount = 10**18
bento.functions.transfer(link.address, admin, pool.address, deposit_amount).transact()
bento.functions.transfer(dai.address, admin, pool.address, deposit_amount).transact()
pool.functions.mint(encode_abi(
['address', 'uint256'],
[admin, 10**8] # minimum
)).transact()
pool.functions.mint(encode_abi(
['address', 'uint256'],
[admin, 10000000000009999 * 10** 20]
)).transact()
deposit_amount = 10**18
bento.functions.transfer(link.address, admin, pool.address, deposit_amount).transact()
bento.functions.transfer(dai.address, admin, pool.address, deposit_amount).transact()
pool.functions.mint(encode_abi(
['address', 'uint256'],
[admin, deposit_amount * 100]
)).transact()
Recommended Mitigation Steps
Recommend to handle INIT_POOL_SUPPLY in uniswap-v2’s way. Determine an optimized parameter for the user would be a better UX design.
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 a fixed INIT_POOL_SUPPLY to address zero, so the value of the burned shares scales inversely with the first depositor's amount rather than being handled proportionally as in Uniswap v2.
Impact
All liquidity providers in a pool initialised with a non-optimal first deposit would receive less profit because a large number of tokens is burned.
What the attacker needed
First liquidity provider controls initial deposit; pool not yet initialised
The fix
INIT_POOL_SUPPLY should be handled the way Uniswap v2 does it, and an optimised parameter should be chosen for the user.
How it was found
- Transfer equal amounts of two tokens into the pool from the admin account.
- Call mint with a very small initial amount (the minimum) as the first liquidity provider.
- Call mint again with a much larger amount.
- Compare the LP tokens received against a second scenario where the first deposit is a normal-sized amount.
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 tokens that people add to and earn fees from. This pool burns a fixed number of its own share tokens when it is created, and how much real value those burned shares represent depends on how big the very first deposit is. If the first person deposits a normal-sized amount, the burned shares end up being worth a lot, so everyone in the pool earns less.
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.