Skip to content
medium Access Control No SWC entry CWE-284

extcodesize == 0 Used as EOA Check (Bypassable)

SAFE-0213 Access Control Checked automatically by the scanner
1

What goes wrong

The contract gates a function on 'caller is an EOA' via extcodesize(caller) == 0 or address.code.length == 0. This is bypassable: during a contract's own constructor its code size is still zero, so an attacker calls the gated function from a constructor.

2

The vulnerable pattern

proof of concept — how it is exploited
// require(addr.code.length == 0); // 'must be EOA'
// attacker: contract A { constructor(){ Victim.protectedMint(); } }
// during A's constructor, A.code.length == 0 -> check passes.
3

How to fix it

the pattern that is safe
// there is no reliable on-chain EOA check; use tx.origin == msg.sender
// only with full awareness, or redesign to not require it
require(msg.sender == tx.origin, "no contracts"); // still imperfect
code.length / extcodesize is not a robust human check.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0213 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs