First depositor can break minting of shares #128
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-442
satisfactory
satisfies C4 submission criteria; eligible for awards
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L421
Vulnerability details
Impact
This is a common vulnerability. The token supply can be manipulated to prevent users from gaining a "normal" number of shares. See Section 3.4 Uniswap does this by burning the first 1000
lpTokens
to significantly increase the cost of this attack.Proof of Concept
First depositor to liquidity pool can deposit a small amount, i.e.
1 wei
to mint 1 LP token. They can then donate a large number ofbaseToken
to the protocol and make it difficult for small liquidity providers from minting any LP tokens.baseTokenShare
is calculated asbaseTokenAmount * lpTokenSupply / baseTokenReserves()
. Because iflpTokenSupply
is 1, and if a malicious user donates100000e18 baseToken
, the next depositors need to provide at least100000e18 baseToken
to mint 1lpToken
. If user deposits say150000e18
, they will still only mint 1lpToken
due to the large rounding error.Tools Used
Manual Review
Recommended Mitigation Steps
We can do what Uniswap does, by sending the first 1000
lptoken
to the 0 address when liquidity is first initiated.The text was updated successfully, but these errors were encountered: