v2-periphery icon indicating copy to clipboard operation
v2-periphery copied to clipboard

Unreachable Code

Open fubuloubu opened this issue 5 years ago • 3 comments

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'); 

fubuloubu avatar Aug 24 '20 15:08 fubuloubu

require(amounts[0] Trust wallet

redditblog avatar Sep 20 '20 11:09 redditblog

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.

deluca-mike avatar Apr 05 '21 04:04 deluca-mike

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.

fubuloubu avatar Apr 05 '21 13:04 fubuloubu