20,000 USDC
View results
Submission Details
Severity: medium

Use safeTransfer and safeTransferFrom instead of transfer and transferFrom

Summary

Tokens not compliant with the ERC20 specification could return false from the transfer function call to indicate the transfer fails, while the calling contract would not notice the failure if the return value is not checked. Checking the return value is a requirement, as written in the EIP-20 specification:

Callers MUST handle false from returns (bool success). Callers MUST NOT assume that false is never returned!

Vulnerability Details

It is a good idea to add a require() statement that checks the return value of ERC20 token transfers or to use something like OpenZeppelin’s safeTransfer()/safeTransferFrom() unless one is sure the given token reverts in case of a failure. Failure to do so will cause silent failures of transfers and affect token accounting in contract.

However, using require() to check transfer return values could lead to issues with non-compliant ERC20 tokens which do not return a boolean value. Therefore, it's highly advised to use OpenZeppelin’s safeTransfer()/safeTransferFrom().

Impact

Failure to do so might cause silent failures of transfers and affect token accounting in contract.

Tools Used

VSCode

Recommendations

Use safeTransfer and safeTransferFrom instead of transfer and transferFrom, in all the instances (code snippets) attached to this submission.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.