Wrong token amount is transferred when calling add() of contract Pair #388
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#L85
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L93-L96
Vulnerability details
Impact
Users calling Pair.sol#add() will cost more tokens than needed.
It also makes Pair.sol#add() and Pair.sol#nftAdd() vulnerable to sandwich attacks.
Proof of Concept
It is incorrect that the token amounts transferred in function Pair.sol#add is derived from input parameters (
baseTokenAmount
,fractionalTokenAmount
) rather than recalculate the amounts from thelpTokenAmount
to mint:For example, if a pair contains 10 ETH and 1000 FT(fractional token), the following three users will get the same amount of lp tokens:
All of them will get the same number of lp tokens, which means user2 costs 100 FT more and user3 costs 10 ETH more.
Tools Used
Manual
Recommended Mitigation Steps
transferFrom
based on thelpTokenAmount
transferFrom
based on thelpTokenAmount
lpTokenAmount
and return the excess ETH to user.The text was updated successfully, but these errors were encountered: