Skip to content

Shadowed State / Local Variable

SAFE-0257 Best Practice Checked automatically by the scanner
1

What goes wrong

A local variable, parameter, or inherited member shares a name with a state variable. Reads/writes silently hit the wrong one, a classic source of 'the value never changed' bugs and access-control mistakes.

2

The vulnerable pattern

proof of concept — how it is exploited
// function init(address owner) public { owner = owner; } // self-assign
// the parameter shadows the state var; state `owner` is never set.
3

How to fix it

the pattern that is safe
// rename to avoid shadowing (e.g. _owner param vs owner state)
function setOwner(address _owner) external { owner = _owner; }
Avoid name shadowing; enable the compiler warning.
4

Where this has happened

Largest recorded losses in the same failure class — related, not the same bug:

Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0257 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