Gas: Conditional flow optimization in Exchange.sol:removeLiquidity()
#28
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
Dravee
Vulnerability details
Impact
It's possible to save gas by optimizing conditional flows to avoid some unnecessary opcodes
Proof of Concept
In
Exchange.sol:removeLiquidity()
, the code is as follows:However, this can be optimized :
>
) are more expensive than non-strict ones (>=
). This is due to some supplementary checks (ISZERO, 3 gas)quoteTokenQtyToReturn == internalBalances.quoteTokenReserveQty
:internalBalances.quoteTokenReserveQty = 0
should be usedThe code would become:
Tools Used
VS Code
Recommended Mitigation Steps
Use the non-strict greater-than operator in this particular case
The text was updated successfully, but these errors were encountered: