Skip to content
Smart contracts Audit finding Beginner

Use safeTransfer instead of transfer

The contract called the ERC20 transfer function without checking its return value, so a token that returns false on failure would not be detected. An attacker could exploit this to make transfers appear successful when they actually failed, potentially causing loss of funds or incorrect accounting.

shw Follow

Originally disclosed on Code4rena

Submitted by shw

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!

See ERC20Rewards.sol L175.

Recommend using the SafeERC20 library implementation from OpenZeppelin and calling safeTransfer or safeTransferFrom when transferring ERC20 tokens.

alcueca (Yield) confirmed and patched:

Fix

The original report as published on Code4rena, by shw. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The contract did not check the boolean return value of the ERC20 transfer call, violating the EIP-20 requirement to handle false returns.

Impact

A token that returns false on transfer failure could cause the contract to not notice the failure, potentially leading to incorrect state or loss of funds.

What the attacker needed

None

The fix

The fix was to use OpenZeppelin's SafeERC20 library and call safeTransfer or safeTransferFrom instead of transfer.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Some digital tokens (ERC20 tokens) have a transfer function that returns a true or false value to say if the transfer worked. If a smart contract ignores that returned value, it might think a transfer succeeded even when it failed. This can lead to problems like the contract losing track of funds or allowing someone to take advantage.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by shw

View all

22 more disclosed reports, best first.

More from Yield Witch v2 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.