Skip to content

unchecked{} Block Hiding Over/Underflow

SAFE-0121 Arithmetic Checked automatically by the scanner
1

What goes wrong

Arithmetic inside an unchecked { } block bypasses Solidity 0.8 overflow protection. If a subtraction or addition there can be driven past its bounds by input, it silently wraps — e.g. a balance underflows to a near-max value.

2

The vulnerable pattern

proof of concept — how it is exploited
// unchecked { balances[msg.sender] -= amount; }
// call with amount > balance -> wraps to ~2**256
// attacker now shows a colossal balance and drains the pool.
3

How to fix it

the pattern that is safe
// keep only proven-safe math unchecked; validate first
require(balance >= amount, "underflow");
unchecked { balance -= amount; }   // safe only after the check
Only wrap math you have already bounded.
Check your own contract for this

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