Skip to content
Smart contracts Audit finding Intermediate

Return values of ERC20 transfer and transferFrom are unchecked

The contracts BadgerYieldSource and SushiYieldSource do not check the return value of ERC20 transfer and transferFrom calls. If the token is non-compliant and returns false on failure, the transfer fails silently, potentially causing incorrect balances and lost funds.

shw Follow

Originally disclosed on Code4rena

Submitted by shw, gpersoon, JMukesh, also found by adelamo and cmichel_

In the contracts BadgerYieldSource and SushiYieldSource, the return values of ERC20 transfer and transferFrom are not checked to be true, which could be false if the transferred tokens are not ERC20-compliant (e.g., BADGER). In that case, the transfer fails without being noticed by the calling contract.

If warden’s understanding of the BadgerYieldSource is correct, the badger variable should be the BADGER token at address 0x3472a5a71965499acd81997a54bba8d852c6e53d. However, this implementation of BADGER is not ERC20-compliant, which returns false when the sender does not have enough token to transfer (both for transfer and transferFrom). See the source code on Etherscan (at line 226) for more details.

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

kamescg (PoolTogether) confirmed and patched:

Sushi

Badger

dmvt (judge) commented:

Sponsor has repeatedly stated in duplicate issues that: “It’s more of a 1 (Low Risk) because the subsequent deposit calls will fail. There is no advantage to be gained; the logic is simply poor.”

I disagree with this assessment. The function(s) in question do not immediately call deposit or another function that would cause a revert. In fact the balances are updated:

  balances[msg.sender] = balances[msg.sender].sub(requiredSharesBalance);
  badger.transfer(msg.sender, badgerBalanceDiff);
  return (badgerBalanceDiff);

The impact that this would have on the rest of the system is substantial, including causing incorrect balances to be returned and potentially lost funds.

That said, I do not think this is very likely and so high severity seems excessive here. Im adjusting all of these reports to Medium Risk given that lower likelihood.

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 contracts call ERC20 transfer and transferFrom without verifying that they return true, so a false return from a non-compliant token is ignored.

Impact

This could cause incorrect balances to be returned and potentially lost funds, though the likelihood is considered low.

What the attacker needed

Non-ERC20-compliant token; token transfer returns false

The fix

The contracts were patched to use OpenZeppelin's SafeERC20 library and call safeTransfer or safeTransferFrom.

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 standard exactly: when a transfer fails, they return false instead of stopping the program with an error. The contracts here ignore that false value, so they think the transfer worked when it did not. This can lead to wrong balances and lost money.

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 PoolTogether

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.