Skip to content
Smart contracts Audit finding Intermediate

ERC20 return values not checked

The contract does not check the boolean return value of ERC20 transfer and transferFrom calls. Tokens that return false instead of reverting could leave tokens stuck in the contract, potentially allowing someone else to steal them.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by defsec, JMukesh, p4st13r4, and WatchPug

The ERC20.transfer() and ERC20.transferFrom() functions return a boolean value indicating success. This parameter needs to be checked for success. Some tokens do not revert if the transfer failed but return false instead.

See:

  • SingleNativeTokenExitV2.exit’s outputToken.transfer(msg.sender, outputTokenBalance);
  • PieFactoryContract.bakePie’s pie.transfer(msg.sender, _initialSupply);

Impact

Tokens that don’t actually perform the transfer and return false are still counted as a correct transfer and the tokens remain in the SingleNativeTokenExitV2 contract and could potentially be stolen by someone else.

Recommended Mitigation Steps

We recommend using OpenZeppelin’s SafeERC20 versions with the safeTransfer and safeTransferFrom functions that handle the return value check as well as non-standard-compliant tokens.

0xleastwood (Judge) commented:

Nice find! I think this is valid considering the extent basket tokens are used. It is more than likely that non-standard tokens will be utilised.

The original report as published on Code4rena, by cmichel. 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 ERC20 transfer functions without checking their boolean return value, so a false return is treated as success.

What the attacker needed

Non-standard ERC20 token that returns false

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 tokens signal a failed transfer by returning false instead of stopping with an error. If the contract ignores that false value, it thinks the transfer worked when it did not, so the tokens stay in the contract and may be taken by someone else.

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 cmichel

View all

196 more disclosed reports, best first.

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