Reproduced Exploit

Behodler — Double transfer in ERC677 `transferAndCall`

transferAndCall calls super.transfer and then _transfer again for the same _value, so the sender is debited twice and the receiver is credited twice.

Jan 2022Otheruntagged2 min read

Chain

Other

Category

untagged

Date

Jan 2022

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 42454-h-03-double-transfer-in-the-transferandcall-function-of-erc6. Standalone Foundry PoC and full write-up: 42454-h-03-double-transfer-in-the-transferandcall-function-of-erc6_exp in the evm-hack-registry mirror.


Vulnerability classes: wrong-condition · direct-drain

Reproduction: self-contained Foundry PoC with only forge-std — no fork. Full trace: output.txt.


Key info#

ImpactHIGH — callers lose 2× the intended amount on every transferAndCall
ProtocolBehodler — Flan / ERC677
Vulnerable codeERC677.transferAndCall — dual transfer
FindingCode4rena — Behodler, 2022-01 · #42454 · [H-03]
Reportcode4rena.com/reports/2022-01-behodler
SourceAuditVault
Compiler^0.8.24 (PoC)

TL;DR#

transferAndCall calls super.transfer and then _transfer again for the same _value, so the sender is debited twice and the receiver is credited twice.

The vulnerable code#

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

Root cause#

Redundant transfer after the ERC20 base transfer already moved the tokens. Flan inherits ERC677, so all transferAndCall users are affected.

Diagrams#

flowchart LR A[Caller balance 1000] --> B["transferAndCall(to, 100)"] B --> C[super.transfer: -100] C --> D["_transfer again: -100"] D --> E[Caller -200 / Receiver +200]

Impact#

Direct double debit on every Flan transferAndCall.

Sources#

Taxonomy: [[wrong-condition]] · [[direct-drain]] · severity/high · sector/dex


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.