Phoenix-Protocol-Group / phoenix-contracts

Source code of the smart contracts of the Phoenix DeFi hub DEX protocol
GNU General Public License v3.0
10 stars 6 forks source link

PHOAM-002: First liquidity provider can inflate the value of shares #317

Open gangov opened 2 weeks ago

gangov commented 2 weeks ago

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.