code-423n4 / 2022-01-elasticswap-findings

1 stars 0 forks source link

using unchecked to save gas #90

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

OriDabush

Vulnerability details

Exchange.sol (removeLiquidity())

In Exchange.sol, in the removeLiquidity() function, you can use unchecked in order to save the gas wasting on overflow checks (you did the needed checks before).

New code suggestion:

unchecked {
    if (quoteTokenQtyToReturn > internalBalances.quoteTokenReserveQty) {
        internalBalances.quoteTokenReserveQty = 0;
    } else {
        internalBalances.quoteTokenReserveQty -= quoteTokenQtyToReturn;
    }
}
0xean commented 2 years ago

dupe of #177