Closed c4-bot-1 closed 3 months ago
The fee is included in the slippage parameter here, and even more so we know for a fact that the fee won't be zero since Gnosis team has confirmed for Mainnet and we deploy custom ones for every L2.
Additionally, the violation check is for a different reason here, the prices already include all the necessary slippage and price protection with min buys etc. What the violation is trying to check for is for an invariant in EasyAuction itself that it abides by the trade parameters.
Similar to #29
thereksfour marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/mixins/TradeLib.sol#L76-L80 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/plugins/trading/GnosisTrade.sol#L114-L120
Vulnerability details
Impact
When we sell tokens to buy other tokens in a
trade
, we determine theminimum buy amount
based on thesell amount
. This means that if we receive less than thisminimum amount
, thetrade
will fail. Normally, we consider a worst-case scenario where we sell tokens at alower price
and buy tokens at ahigher price
. If we don’t meet theminimum buy amount
, thetrade
should fail.However, in
Gnosis trading
, afee
is applied, which means the actualsell amount
is less than theinput amount
. Despite this, theminimum buy amount
is still calculated using theinput amount
, not the actualsell amount
. As a result, atrade
that could have succeeded might fail due to this discrepancy.Proof of Concept
The
minimum buy amount
is calculated based on thesell amount
as follows:The numerical expression is as follow.
These amounts are then passed to the
Gnosis Trade
(lines 91-92
).However, the actual
sell amount
decreases due to thefee
in theGnosis Trade
(lines 114-120
). This reducedsell amount
is what gets passed to theGnosis contract
(line 149~150
).In the
Gnosis contract
, the originalsell amount
is transferred, with the excess being handled asfees
.As a result, when tokens are sold at a
lower price
and bought at ahigher price
—as we expected in the worst-case scenario—we may not achieve the calculatedminimum buy amount
from the actualsell amount
. This could cause thetrade
to fail.Tools Used
Recommended Mitigation Steps
Recalculate the
minimum buy amount
based on the actualsell amount
.Assessed type
Math