code-423n4 / 2021-04-marginswap-findings

1 stars 0 forks source link

sortTokens can be simplified #7

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Vulnerability details

this is a minor suggestion:

The function sortTokens UniswapStyleLib.sol returns 2 values, but only the first return value is used: MarginRouter.sol: (address token0, ) = UniswapStyleLib.sortTokens... UniswapStyleLib.sol: (address token0, ) = sortTokens.. In both cases the used return value is compared to the first parameter of the function call. Conclusion: the function is only used to determine the smaller of the two tokens, not really to sort tokens.

Handle

gpersoon

Email address

mail@gpersoon.com

Eth address

gpersoon.eth

Impact

The code is somewhat more difficult to read and a bit longer than neccesary.

Recommended mitigation steps

simplify the code: function ASmallerThanB(address tokenA, address tokenB) internal pure returns (bool) { require(tokenA != tokenB, "Identical address!"); require(tokenA != address(0), "Zero address!"); require(tokenB != address(0), "Zero address!"); return tokenA < tokenB; }