v2-periphery
v2-periphery copied to clipboard
Unreachable Code
This line will always skip the refund code:
https://github.com/Uniswap/uniswap-v2-periphery/blob/4123f93278b60bcf617130629c69d4016f9e7584/contracts/UniswapV2Router01.sol#L258
because of this precondition:
https://github.com/Uniswap/uniswap-v2-periphery/blob/4123f93278b60bcf617130629c69d4016f9e7584/contracts/UniswapV2Router01.sol#L254
I think that the precondition is actually incorrect, and should check that a minimum amount of ETH is provided to complete the trade. Currently, this requires sending the exact amount of ETH to conduct the trade. To fix:
- require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
+ require(amounts[0] >= msg.value, 'UniswapV2Router: INSUFFICIENT_INPUT_AMOUNT');
require(amounts[0] Trust wallet
Just a bump on this. Can confirm, swapETHForExactTokenscannot do what the docs suggest (Leftover ETH, if any, is returned to msg.sender.) because of this.
Probably unlikely that this will be fixed, but for future users of this code it might be good to bear this in mind as a patch fix.