Description
The first liquidity provider is able to inflate the share price with a donation attack, considerably increasing the minimum amount of tokens users have to supply in subsequent deposits. This is enabled by the following else path, which allows minting a single share during the first deposit to the pool.
An attacker can first deposit one tokenA and one tokenB, then transfer (donate) a small amount of tokenA to break the pool equilibrium which effectively inflates the minimum required deposit amount (so the execution does not revert). This happens because the total supply of shares can be exactly one single share, which allows having a high number of tokens backed by such share.
To prevent this scenario from occurring, UniswapV2 mints 1000 LP shares to a burn address (out of everybody's reach) to increase the starting total share supply.
The section Initialization of liquidity token supply of their whitepaper provides additional information.
Additionally, when the share balance is not zero, the calculated number of shares to mint could be zero because of this donation attack.
Recommendation
When there are no shares in circulation, mint 1000 LP tokens to a burn address.
Also, check that the amount of shares to mint is non-zero.
Description The first liquidity provider is able to inflate the share price with a donation attack, considerably increasing the minimum amount of tokens users have to supply in subsequent deposits. This is enabled by the following else path, which allows minting a single share during the first deposit to the pool.
An attacker can first deposit one tokenA and one tokenB, then transfer (donate) a small amount of tokenA to break the pool equilibrium which effectively inflates the minimum required deposit amount (so the execution does not revert). This happens because the total supply of shares can be exactly one single share, which allows having a high number of tokens backed by such share. To prevent this scenario from occurring, UniswapV2 mints 1000 LP shares to a burn address (out of everybody's reach) to increase the starting total share supply. The section Initialization of liquidity token supply of their whitepaper provides additional information. Additionally, when the share balance is not zero, the calculated number of shares to mint could be zero because of this donation attack.
Recommendation When there are no shares in circulation, mint 1000 LP tokens to a burn address. Also, check that the amount of shares to mint is non-zero.