A malicious early actor can cause a Partial DoS for adding liquidity by enforcing a minimum deposit amount #235
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
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L63-L99
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L77
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L421
Vulnerability details
Impact
A first depositer can deposit minimum amount of baseToken and fractionalToken then manipulate the baseToken reserves by sending a big amount directly to the Pair contract. Thus, inflating LPToken price. Any further deposits with smaller (but reasonable) amount will result in zero share of LPToken.
This occurs due to the the lp token shares calculation that use baseToken reserves as a denominator.
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L77
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L421
Proof of Concept
forge test --match-path test/Pair/unit/AddVul.t.sol -vv
Tools Used
Manual analysis
Recommended Mitigation Steps
The issue can be mitigated similiary to how Uniswap does, by permanently locking the first MINIMUM_LIQUIDITY tokens (which is 10**3)
Please check:
Page 8 in the whitepaper (3.4 Initialization of liquidity token supply):
https://uniswap.org/whitepaper.pdf
Uniswap source code:
https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Pair.sol#L121
Additionally, make sure the minLpTokenAmount passed is not zero. as you can see in the PoC above. it is allowed to pass zero as a value which shouldn't be a desired result by the user.
The text was updated successfully, but these errors were encountered: