code-423n4 / 2021-09-wildcredit-findings

0 stars 0 forks source link

Check _returnToken and call _convertTokenValues() only when needed can save gas #33

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L660-L684

_convertTokenValues is unnecessary when _fromToken and _toToken are the same, change to amountA and amountB can save gas.

Recommendation

Consider changing to:

uint supplyA = _returnToken == tokenA ?
    amountA
    : _convertTokenValues(tokenA, _returnToken, amountA, _priceA, _priceB);
uint supplyB = _returnToken == tokenB ? 
    amountB;
    : _convertTokenValues(tokenB, _returnToken, amountB, _priceB,  _priceA);
talegift commented 2 years ago

_fromToken and _toToken can never be the same since Uniswap pairs are not allowed to have duplicate tokens in the same pair.

ghoul-sol commented 2 years ago

per sponsor comment, invalid