The TokenHandler.transfer should handle the if (token.tokenType == TokenType.Ether) case first, as if the token type is Ether but netTransferExternal <= 0 it treats the token as an ERC20 token and tries to call ERC20 functions on it.
Impact
Luckily, trying to call ERC20 functions on the invalid token address will revert which is the desired behavior.
Recommended Mitigation Steps
We still recommend reordering the branches and adding a netTransferExternal <= 0 check. The code becomes cleaner and it's more obvious that the transaction will fail.
Handle
cmichel
Vulnerability details
Vulnerability Details
The
TokenHandler.transfer
should handle theif (token.tokenType == TokenType.Ether)
case first, as if the token type isEther
butnetTransferExternal <= 0
it treats the token as anERC20
token and tries to callERC20
functions on it.Impact
Luckily, trying to call ERC20 functions on the invalid token address will revert which is the desired behavior.
Recommended Mitigation Steps
We still recommend reordering the branches and adding a
netTransferExternal <= 0
check. The code becomes cleaner and it's more obvious that the transaction will fail.