Since there is no validation that the proportion between token1 and token2 remains the same when a liquidity provider adds more liquidity to the pool, there is a chance of losing funds for some liquidity providers. #122
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#L63-L99
Vulnerability details
Since there is no validation that the proportion between token1 and token2 remains the same when a liquidity provider adds more liquidity to the pool, there is a chance of losing funds for some liquidity providers.
The contract
Pair.sol
intends to function such as a normal ERC20 liquidity pool. However, if you look at other LP implementations you will find that there is no validations related to the tokens proportion added to the pool on this specific implementation. A liquidity provider could add any arbitriary amount of token1 and token2 calling the functonadd()
.As a liquidity provider, is expected that, if I add X amount of liquidity to the pool I should be able to get that same liquidity back if there is no changes on the pool (if there is no trades) minus the required fees if any.
However, on the current implementation where any arbitriary amount of pair tokens could be added to the pool without any validation, a second liquidity provider could add more liquidity in a different proportion (let's say that this second liquidity provider adds the same amount of token1 but half of token2) changing the underlying value of the lp token and losing funds if
remove()
is immediately called by this second provider.Proof of concept:
1 - User1 adds 900 token1s and 900 tokens2s to the empty pool, getting their LP tokens.
2 - User2 adds 900 token1s and 900 toekn2s to the pool, getting their LP tokens.
3 - User2 calls
remove()
immediately reediming their LP tokens, but now their balance will be 600 token1s and 900 token2s. Losing 300 of their token1's initial balance.4 - User1 calls
remove()
after this, getting their balance back, plus the lost token1 from user2, stealing their tokens.Mitigation steps
It's important to add to the LP new tokens the tokens keeping the right proportion between them. If a lp provider tries to add liquidity in a different proportion, it's necessary to get just the right amount of the tokens and refund the remaining to the liquidity provider.
The text was updated successfully, but these errors were encountered: