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: 65/103
Findings: 1
Award: $40.26
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Jeiwan
Also found by: 0xxm, 9svR6w, BAHOZ, Bobface, CRYP70, Chom, HE1M, Junnon, RaymondFam, UNCHAIN, __141345__, bytehat, carlitox477, caventa, cccz, chaduke, hansfriese, hihen, koxuan, mauricio1802, minhquanym, minhtrng, nicobevi, obront, shung, unforgiven, wait
40.2564 USDC - $40.26
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L63-L99 https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L417-L428
Add liquidity may pull tokens from the user more than necessary. These extra tokens pulled become profit to previous LP holders.
// *** Effects *** // // transfer fractional tokens in _transferFrom(msg.sender, address(this), fractionalTokenAmount); // *** Interactions *** // // mint lp tokens to sender lpToken.mint(msg.sender, lpTokenAmount); // transfer base tokens in if the base token is not ETH if (baseToken != address(0)) { // transfer base tokens in ERC20(baseToken).safeTransferFrom(msg.sender, address(this), baseTokenAmount); }
Assume price is 1:1 and you input baseTokenAmount = 100, fractionalTokenAmount = 1
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); } }
addQuote will return fractionalTokenShare, which represents the share of 1 fractional token : 1 base token
ERC20(baseToken).safeTransferFrom(msg.sender, address(this), baseTokenAmount);
But 100 base token has been pulled. This resulted in the loss of 99 base tokens as LP minted only represented 1 base token.
Return actual base token and fractional token amount from the addQuote
function and only pull what necessary.
#0 - c4-judge
2022-12-28T12:40:35Z
berndartmueller marked the issue as duplicate of #376
#1 - c4-judge
2023-01-10T09:01:55Z
berndartmueller changed the severity to 3 (High Risk)
#2 - c4-judge
2023-01-10T09:01:59Z
berndartmueller marked the issue as satisfactory