The transfer function contains a logic flaw where self-transfers (transferring tokens to one's own address) result in the recipient balance being incorrectly updated. Instead of maintaining the same balance, the function effectively doubles the transfer amount added to the balance due to improper handling of memory slots when from and to addresses are identical.
The bug occurs because:
The function loads from balance (e.g., 100)
Loads to balance (same as from, 100)
Subtracts amount from from (100 - 10 = 90)
Adds amount to to (90 + 10 = 110, overwriting the previous subtraction)
Offending pattern (conceptual):
Reproduction commands:
Expected behavior: balanceOf(alice) remains 100 ether after a self-transfer of 10 ether (no net change).
Actual behavior: balanceOf(alice) becomes 110 ether.
Attackers can repeatedly self-transfer to inflate balances (practically mint tokens).
Total supply and accounting are corrupted, enabling exploitation of liquidity pools, governance, and other systems.
Short-term: short-circuit self-transfers to avoid double writes and still emit Transfer for compliance:
Long-term: refactor to use combined updates or use OpenZeppelin's audited ERC20 implementation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.