0

when making an ERC20 transfer it is a standard practice to wrap it in require statement so if it fails the tx will revert like this:

require(token.transfer(...));

What if I'm calling an external contract that doesn't return a boolean and the transaction fails.

Is it possible that the tx will fail(not revert) but the contract that called that function will think that it was successful?

Thanks. If the question isn't clear I'm happy to provide more context.

2
  • The best practice is to use safe transfer function like the one implemented by openZeppelin and even better is u ask for balance before and after the function
    – Majd TL
    May 3, 2022 at 17:19
  • Okay I get that but is it possible that if these things are not implemented it will fail but the calling contract will think it was successful?
    – Kuly14
    May 3, 2022 at 17:23

1 Answer 1

0

Yes it's definitely possible for the token to not follow standards (or be malicious). The general best practice is to get around this (if you need to allow any token in your protocol) is to force the return via safeTransfer

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol.

bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
    // Return data is optional
    require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}

But also know that tokens can be upgradeable (become malicious) or just be malicious from the start and return true even the transfer doesn't happen, so at some point you just have to let people decide if they want to interact with that token.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.