Surplus token after adding liquidity is not refunded to liquidity providers. LP might suffer front-running attack and lose funds. #444
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-376
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L77
Vulnerability details
Impact
Function
Pair.add()
receives base token and fractional token from liquidity providers and mint equivalent amount of LP token for them.The amount of LP token be minted is calculate in function
addQuote()
As we can see, it takes the min value between
baseTokenShare
andfractionalTokenShare
as the return value. However, the surplus token is not returned to sender but lock in the liquidity pool and become assets of all LPs, which means sender is losing funds.Proof of Concept
Consider the scenario
100 USDC - 100 FracToken
. Total supply of LP token is100
.50 USDC - 50 FracToken
. She should get33.33%
of total supply of LP token, which is50 LP token
.90 USDC - 111.11 FracToken
.45
instead of50
LP token.There is
55.55 - 45 = 10.55
surplus base token share. It should be return to Alice.Tools Used
Manual Review
Recommended Mitigation Steps
The text was updated successfully, but these errors were encountered: