TSender

Cyfrin
DeFiFoundry
15,000 USDC
View results
Submission Details
Severity: medium
Invalid

Unhandled return value of transferFrom could lead to fund loss for recipients

Consistency in ERC20 implementations is a major concern for smart contract developers.

The Problem:

The ERC20 standard defines functions like transfer and transferFrom for token transfers. However, the standard doesn't mandate how these functions should handle failures.
Some ERC20 token implementations might choose to simply return false if a transfer fails, while others might revert the entire transaction.
This inconsistency creates a challenge for smart contract developers who interact with various ERC20 tokens.
The Risk:

If a smart contract relies solely on the return value of transfer or transferFrom without checking for reverts, it might miss potential failures.
A failed transfer could lead to unexpected behavior or security vulnerabilities within the smart contract.
The Solution:

There are two main approaches to mitigate this risk:

require() Statements:

Developers can wrap ERC20 token transfers (like transfer and transferFrom) within require statements.
Inside the require statement, you can check if the return value of the transfer function is true. This ensures that the transfer succeeded before proceeding further in the code.

// Example using require()
bool success = token.transfer(recipient, amount);
require(success, "ERC20 transfer failed");

Safe Wrapper Functions:

Utilize libraries like OpenZeppelin's SafeERC20 library.
These libraries provide wrapper functions for ERC20 token interactions that handle both return values and reverts.
The wrapper functions automatically revert the transaction if the transfer fails.
Using safe wrapper functions simplifies code and ensures consistent behavior regardless of the underlying ERC20 token implementation.
Benefits of Safe Practices:

By using require statements or safe wrapper functions, smart contracts become more robust and resilient to unexpected failures during ERC20 token interactions.
This reduces the risk of bugs and vulnerabilities arising from inconsistent ERC20 token implementations.
The Reference:

The provided link (https://consensys.io/diligence/audits/2020/09/aave-protocol-v2/) refers to a Consensys Diligence Audit of Aave Protocol V2. This audit likely identified instances where the protocol didn't handle ERC20 transfer return values appropriately. The finding is classified as "medium severity," highlighting the importance of addressing this issue for secure smart contract development.

Conclusion:

By understanding the inconsistency in ERC20 token implementations and using appropriate safeguards like require statements or safe wrapper functions, smart contract developers can build more reliable and secure interactions with various ERC20 tokens.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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