Closed sherlock-admin3 closed 8 months ago
The details regarding the claim are vague. If I considered values provided by the hunter :-
Kbefore = 30 * 60 => 1800
Kafter = 55 * 35 => 1925
Since Kafter >= Kbefore
I don't see any issue here.
escalate sorry, I think I have mistake. but kbefore = 4060 = 2400, kafter = 6535 = 2275, how do you think about it?
FastTiger
medium
An attacker can use the
swap
function to receive more tokens with a smaller amount of ETH.Summary
An attacker can receive more tokens with a smaller amount of ETH by directly calling the
GoatV1Pair.sol#swap
function. Therefore, the protocol suffers a loss of funds.Vulnerability Detail
The
GoatV1Pair.sol#swap
function is as follows.As you can see on the right, if you set the parameters in the
GoatV1Pair.sol#swap
function toamountTokenOut = a
andamountWethOut = 0
,swapVars.isBuy = true
. Also, before this, the attacker sendsb + swapVars.initialReserveEth+_pendingLiquidityFees + _pendingProtocolFees
wei directly to this contract. At this time, sinceswapVars.amountWethIn = b
, it continues to be executed in the_handleFees
function. Next, there is the conditional statement below.Here, the attacker carefully considers the quantity relationship to avoid reverting. Let's look at a simple example.
swapVars.virtualEthReserveBefore = 60
,swapVars.virtualTokenReserveBefore = 30
anda = 5
,b = 5
. Since(60 * 30 <= 55 * 35)
, it is not reverted.Impact
The attacker determines the exact quantity relationship and profits from it. Therefore, the protocol suffers a loss of funds. Since this is easily possible, I mark it as medium.
Code Snippet
https://github.com/sherlock-audit/2024-03-goat-trading/blob/main/goat-trading/contracts/exchange/GoatV1Pair.sol#L242-L331
Tool used
Manual Review
Recommendation
There are several ways, but the simplest way is to prevent the
swap
function from being called directly from outside.