First LP can manipulate the pricing #121
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/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L417-L428
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L63-L99
Vulnerability details
Impact
The first LP can impact the pricing formula used in
addQuote
function . It will make the pricing ofbaseTokenShare
andfractionalTokenShare
favourable to the second LP.Proof of Concept
Example:
The
add
function ofPair
takesbaseTokenAmount
andfractionalTokenAmount
as parameter.The first LP front runs the Pair and sets
baseTokenAmount
= 1;fractionalTokenAmount
=1;Now see the
addQuote
functionHere,
as
lpTokenSupply
==0 , it will return 1 ;Now lpTokenSupply will return 1 for second LP.
Second LP calls the
add
function again ,In the
addQuote
function ,baseTokenShare
will be equal to thebaseTokenAmount
and similarly ,fractionalTokenShare
=fractionalTokenAmount
This phenomenon , ignores the other 2 variables in the formula(
lpTokenSupply
andbaseTokenReserves
,fractionalTokenReserves
) , as they are 1 in value .Thus, it will be more advantageous for the second LP to mint the tokens, which will put , the rest of the future LPs at a disadvantage.
Tools Used
Manual
Recommended Mitigation Steps
addQuote
function, whenlpTokenSupply
==0 , enforce a require statement , to make the user deposit a minimum amount ofbaseTokenAmount
that will make the calculation more robust to manipulation.The text was updated successfully, but these errors were encountered: