Platform: Code4rena
Start Date: 12/12/2022
Pot Size: $36,500 USDC
Total HM: 8
Participants: 103
Period: 7 days
Judge: berndartmueller
Id: 193
League: ETH
Rank: 93/103
Findings: 1
Award: $6.99
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: minhquanym
Also found by: 0x52, 0xDecorativePineapple, Apocalypto, BAHOZ, ElKu, Franfran, HE1M, Jeiwan, KingNFT, Koolex, SamGMK, Tointer, Tricko, UNCHAIN, __141345__, ak1, aviggiano, bytehat, carrotsmuggler, cccz, chaduke, cozzetti, dipp, eyexploit, fs0c, haku, hansfriese, hihen, immeas, izhelyazkov, koxuan, ladboy233, lumoswiz, rajatbeladiya, rjs, rvierdiiev, seyni, supernova, unforgiven, yixxas
6.9881 USDC - $6.99
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
The first LP can impact the pricing formula used in addQuote
function . It will make the pricing of baseTokenShare
and fractionalTokenShare
favourable to the second LP.
The add
function of Pair
takes baseTokenAmount
and fractionalTokenAmount
as parameter.
The first LP front runs the Pair and sets
baseTokenAmount
= 1;
fractionalTokenAmount
=1;
Now see the addQuote
function
function addQuote(uint256 baseTokenAmount, uint256 fractionalTokenAmount) public view returns (uint256) { uint256 lpTokenSupply = lpToken.totalSupply(); if (lpTokenSupply > 0) { // calculate amount of lp tokens as a fraction of existing reserves uint256 baseTokenShare = (baseTokenAmount * lpTokenSupply) / baseTokenReserves(); uint256 fractionalTokenShare = (fractionalTokenAmount * lpTokenSupply) / fractionalTokenReserves(); return Math.min(baseTokenShare, fractionalTokenShare); } else { // if there is no liquidity then init return Math.sqrt(baseTokenAmount * fractionalTokenAmount); } }
Here,
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 the baseTokenAmount
and similarly , fractionalTokenShare
= fractionalTokenAmount
This phenomenon , ignores the other 2 variables in the formula( lpTokenSupply
and baseTokenReserves
,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.
Manual
addQuote
function, when lpTokenSupply
==0 , enforce a require statement , to make the user deposit a minimum amount of baseTokenAmount
that will make the calculation more robust to manipulation.#0 - c4-judge
2022-12-20T14:35:00Z
berndartmueller marked the issue as duplicate of #442
#1 - c4-judge
2023-01-10T09:13:57Z
berndartmueller marked the issue as satisfactory