Skip to content
Business logic Audit finding Intermediate

Code does not handle ERC20 tokens with special `transfer` implementation

The contract calls ERC20 transfer without checking the return value, so tokens that return false instead of reverting can cause silent failures. This could leave tokens stuck in the contract after shares are burned.

pashov Follow with cryptphi

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-sense-judging/issues/10

Found by

pashov, cryptphi

Summary

Calls to ERC20::transfer method should always be checked

Vulnerability Detail

Some ERC20 tokens do not revert on failure in transfer but instead return false as a return value (for example ZRX). Because of this it has become a common practice to use OpenZeppelin's SafeERC20 to handle such weird tokens. If transfer fails, but does not revert it can leave tokens stuck in the contract - for example in eject in AutoRoller we have such a non-checked transfer, but if it failed the tokens would get stuck, before the shares used for eject were already burned.

Impact

The impact is potentially permanently lost (stuck) value for users of the protocol, but it needs a special ERC20 token to be used as underlying or to be sent in contract by mistake, hence Medium severity.

Code Snippet

https://github.com/sherlock-audit/2022-11-sense/blob/main/contracts/src/AutoRoller.sol#L656 https://github.com/sherlock-audit/2022-11-sense/blob/main/contracts/src/AutoRoller.sol#L659 https://github.com/sherlock-audit/2022-11-sense/blob/main/contracts/src/AutoRoller.sol#L715

Tool used

Manual Review

Recommendation

Use OpenZeppelin's SafeERC20 library to handle such tokens

Discussion

jparklev

We will add the safe transfer functions to the remaining locations

jparklev

Fix: https://github.com/sense-finance/auto-roller/pull/16

aktech297

The fix is using safeTransfer from solmate/utils/SafeTransferLib.sol (asset, coin) As a suggestion, following transfer also can be updated with safeTransfer Line - 654,656.

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

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 uses ERC20 transfer without checking its return value, so tokens that return false on failure are not handled.

Impact

Tokens could become permanently stuck for users, but only if a special ERC20 token is used as underlying or sent by mistake, hence Medium severity.

What the attacker needed

Special ERC20 token as underlying; or tokens sent by mistake

The fix

The fix was to use safeTransfer from solmate's SafeTransferLib for the affected transfers.

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 don't stop with an error when a transfer fails; they just quietly return 'false'. If the code ignores that 'false', it thinks the transfer worked when it didn't, and tokens can get stuck. The fix is to always check the result or use a safe transfer helper.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by pashov

View all

7 more disclosed reports, best first.

More from Sense Update #1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.