Skip to content
Smart contracts Audit finding Intermediate

Unchecked ERC20 transfer calls

The DutchAuctionLiquidator contract calls ERC20 transfer without checking the return value, so a token that returns false on failure would be treated as a successful transfer. This could allow a failed transfer to be considered valid, and with USDT the transfer would always revert.

loop Follow

Originally disclosed on Code4rena

Submitted by loop, also found by cmichel, defsec, gzeon, leastwood, nikitastupin, pants, and WatchPug

ERC20 transfer and transferFrom calls normally return true on a succesful transfer. In DutchAuctionLiquidator the call asset.transfer(msg.sender, _collateral); is made. asset refers to whichever ERC20 asset is used for the vault of that auction. If asset is an ERC20 token which does not comply with the EIP-20 standard it might return false on a failed transaction rather than revert. In this case it would count as a valid transaction even though it is not. If a vault would be making use of USDT the transfer call would always revert as USDT returns void on transfers.

There are a few more transfer(From) calls which are unchecked, these are however all on a predetermined asset (mochi, usdM and crv) and unlikely to cause problems.

Proof of Concept

See issue page for referenced code.

Tools Used

Slither

Recommended Mitigation Steps

In other contracts the functions cheapTransfer and cheapTransferFrom are used which are part of the mochifi cheapERC20 library. These functions do check for a return value and could be used rather than transfer and transferFrom.

Comments:

ryuheimat (Mochi) confirmed:

transferFrom and transfer functions are used for mochi and usdm tokens which are standard EIP-20 tokens.

The original report as published on Code4rena, by loop. 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 does not check the boolean return value of ERC20 transfer calls, so a false return is ignored.

Impact

A failed transfer could be treated as successful, potentially causing incorrect state; with USDT the transfer would always revert.

What the attacker needed

Vault uses a non-standard ERC20 token

The fix

Use the library's cheapTransfer and cheapTransferFrom functions, which check the return value, instead of transfer and transferFrom.

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 do not follow the usual rule of stopping with an error when a transfer fails; instead they just return false. If the contract does not check that returned value, it may think the transfer worked when it did not. This can lead to incorrect accounting or lost funds.

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 loop

View all

1 more disclosed report, best first.

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