In this track: Smart contract security foundations
advanced · 4 MIN READ

Arithmetic checks and unchecked blocks

Removing overflow checks requires a proved bound.

LET’S PICTURE IT

Skipping a safety stop is reasonable only when the route cannot reach the dangerous boundary.

SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
Watch a stack machine execute a tiny programProgram→ PUSH1 0x02PUSH1 0x03ADD · STOPStackEmptyPC = 0A fixed local model; not a complete EVM implementationPUSH1 0x02Push immediate 2Next PC = 2Stack · top first2PUSH1 occupies one opcode byte plus one immediate bytePUSH1 0x03Push immediate 3Next PC = 4Stack · top first32The first value is below the most recently pushed valueADD3 + 2 = 5Next: STOP at PC 5Stack5No automatic SSTOREStack, memory and persistent storage are different locations

The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Know the language behavior

Modern Solidity normally checks integer overflow and underflow. An unchecked block changes applicable arithmetic overflow behavior, not every possible runtime failure.

State the bound explicitly

A loop increment may be safe under a particular condition, while a balance subtraction may depend on earlier checks. Write the argument instead of assuming small usual inputs.

Keep division behavior separate

Unchecked arithmetic does not make division by zero valid. Precision loss and rounding also remain even when no overflow occurs.

Test boundary values

Exercise zero, maximum values and values immediately around the proved bound. A handful of normal examples cannot establish the full arithmetic property.

Reason about the scenario

before unchecked subtraction:
prove amount <= balance
then verify the proof still holds after all reachable interactions

Pseudocode or a simplified scenario for local reasoning. This is not a production contract or a completed security review.

QUICK CHECK · NO PRESSURE

Does unchecked make division by zero safe?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.