Skip to content
Business logic Audit finding Beginner

Double transfer in the transferAndCall function of ERC677

The transferAndCall function in the ERC677 contract implementation transfers the specified token amount twice instead of once. An attacker could call this function to send tokens to a recipient and have double the amount deducted from their balance, potentially causing unintended token loss or manipulation.

shw Follow

Originally disclosed on Code4rena

Submitted by shw, also found by cccz, danb, and wuwe1

The implementation of the transferAndCall function in ERC677 is incorrect. It transfers the _value amount of tokens twice instead of once. Since the Flan contract inherits ERC667, anyone calling the transferAndCall function on Flan is affected by this double-transfer bug.

Proof of Concept

Below is the implementation of transferAndCall:

function transferAndCall(
  address _to,
  uint256 _value,
  bytes memory _data
) public returns (bool success) {
  super.transfer(_to, _value);
  _transfer(msg.sender, _to, _value);
  if (isContract(_to)) {
      contractFallback(_to, _value, _data);
  }
  return true;
}

We can see that super.transfer(_to, _value); and _transfer(msg.sender, _to, _value); are doing the same thing - transfering _value of tokens from msg.sender to _to.

Referenced code: ERC677/ERC677.sol#L28-L29

Recommended Mitigation Steps

Remove _transfer(msg.sender, _to, _value); in the transferAndCall function.

gititGoro (Behodler) confirmed and commented:

Fix Behodler/limbo#3


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 function calls two different transfer methods that both perform the same token transfer, resulting in a double deduction.

Impact

Anyone calling the transferAndCall function on the Flan contract would have twice the intended amount of tokens transferred from their balance, potentially leading to significant token loss.

What the attacker needed

None

The fix

The fix is to remove the redundant `_transfer` call from the `transferAndCall` function.

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.

This is a bug in a smart contract function that is supposed to send tokens from one person to another. Instead of sending the tokens once, it sends them twice, so the sender loses twice as many tokens as they intended. Anyone using this function would be affected.

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 shw

View all

22 more disclosed reports, best first.

More from Behodler contest

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.