Skip to content
low Best Practice No SWC entry CWE-547

Hardcoded Address / Magic Constant

SAFE-0259 Best Practice Checked automatically by the scanner
1

What goes wrong

A critical dependency (router, token, treasury) is hardcoded as a literal address, or key parameters are unexplained magic numbers. Hardcoded addresses break on other chains/forks and can point to a wrong or attacker contract if mistyped.

2

The vulnerable pattern

proof of concept — how it is exploited
// address constant ROUTER = 0x7a25...; // mainnet Uniswap
// deployed to an L2 where that address is empty/an attacker contract
// -> swaps call into the wrong code.
3

How to fix it

the pattern that is safe
// inject addresses via constructor/initializer and validate them
constructor(address _router) { require(_router != address(0)); router = _router; }
Configure addresses; document constants.
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-0259 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