Skip to content
Smart contracts Audit finding Intermediate

ERC20 tokens with no return value will fail to transfer

The contract uses the standard ERC20 transfer function, which expects a boolean return value. Many tokens, including USDT, do not return a value, so the transfer call reverts even when the transfer would succeed, causing the contract to fail to transfer those tokens.

ych18 Follow

Originally disclosed on Code4rena

Submitted by ych18, also found by wuwe1

https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L43-L46

https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L51-L57

Vulnerability details

Although the ERC20 standard suggests that a transfer should return true on success, many tokens are non-compliant in this regard (including high profile, like USDT) . In that case, the .transfer() call here will revert even if the transfer is successful, because solidity will check that the RETURNDATASIZE matches the ERC20 interface.

Recommendation

Consider using OpenZeppelin’s SafeERC20

sofianeOuafir (Joyn) confirmed and commented:

duplicate of #52

deluca-mike (judge) commented:

Actually not a duplicate of #52, since it pertains to return data size handling causing an issue, rather than failure to handle a true/false return at all. Still, same solution (use SafeERC20).


The original report as published on Code4rena, by ych18. 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 calls the ERC20 transfer function directly, which assumes the token returns a boolean, but many tokens do not return any data, causing the call to revert.

Impact

The contract cannot transfer tokens that do not return a boolean, so any functionality relying on such transfers will fail.

What the attacker needed

Contract holds or handles non-standard ERC20 tokens

The fix

The contract should use OpenZeppelin's SafeERC20 library, which handles tokens that do not return a boolean.

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 (like USDT) don't follow the full ERC20 standard: when you ask them to transfer, they don't send back a 'yes' or 'no' answer. The contract here expects that answer, so it treats the missing answer as an error and cancels the transfer. This means the contract can't handle those tokens at all.

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 ych18

View all

3 more disclosed reports, best first.

More from Joyn 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.