Skip to content

Dirty Higher-Order Bits / Unsafe Assembly Math

SAFE-0031 Low-Level / Assembly Checked automatically by the scanner
1

What goes wrong

Inline assembly manipulates values without cleaning higher-order bits or without overflow checks, so masked types (address, bool, small uints) carry garbage bits that corrupt comparisons and storage.

2

How to fix it

the pattern that is safe
assembly {
    let a := and(calldataload(4), 0xffffffffffffffffffffffffffffffffffffffff)
}
Clean bits and check overflow in assembly; document invariants.
3

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-0031 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