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

1 stars 0 forks source link

calculateBaseTokenQty will revert if the exact amount of desired tokens is returned #127

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

harleythedog

Vulnerability details

Impact

When a user is trading base tokens for quote tokens, they can specify _minQuoteTokenQty, which is the minimum number of quote tokens that should be returned. Later on in calculateQuoteTokenQty, there is the following require statement:

require(
    quoteTokenQty > _quoteTokenQtyMin,
    "MathLib: INSUFFICIENT_QUOTE_TOKEN_QTY"
);

This will revert if the exact number of tokens is correct, which is contradictory to the logic in the rest of the Math library. Often a user will know the exact amount of tokens that they want to receive, and in the case that they get this exact amount, their transaction will revert unnecessarily and this will cost the user all of the failed transaction's gas (which could be quite a bit).

Proof of Concept

See referenced code here.

Tools Used

Inspection.

Recommended Mitigation Steps

Change the > to a >= so that the require statement is:

require(
    quoteTokenQty >= _quoteTokenQtyMin,
    "MathLib: INSUFFICIENT_QUOTE_TOKEN_QTY"
);
0xean commented 2 years ago

dupe of #175