Pair.add
function can lose users token due to lack of calculation of amount to deposit. Also open opportunities for MEV bots
#288
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-376
edited-by-warden
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-L96
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L417-L428
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L285
Vulnerability details
Description
Current function assure as that we will at least receive minLpTokenAmount amount of LP. However, this function assumes that the input parameter
baseTokenAmount
andfractionalTokenAmount
will adjust to the LP amount calculated to deposit.Impact
A user whose input parameters
baseTokenAmount
orfractionalTokenAmount
does not adjust to the correspondinglpTokenAmount
calculated inside the function can make the user lose funds, or even open frontrunning opportunities for MEV bots.POC
Add this file to test folder, then run
forge test --match-test testUserLoseOfFunds -vvv
to check the next output.This shows that a user calling this function can accidentally give tokens to current LP holders.
A derivate consequence is that it opens a windows to MEV bots, they can include in the same block a transaction to:
This last scenario means that user funds are in risk.
Mitigation steps
Calculates amount of tokens/ETH to transfer to the Pair contract in fact and use these values to execute the transfer function and/or to return ETH. I would suggest to add this calculations inside the
addQuote
function. Then the return values can be even used in the front end to suggest user amount to send in order to the slippage they set.The text was updated successfully, but these errors were encountered: