Skip to content

Inline Assembly Not Marked memory-safe

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

What goes wrong

Inline assembly that touches memory is not annotated ('memory-safe'), or violates the memory model. Under the via-IR pipeline the optimiser may reorder memory operations, producing subtly wrong results that pass simple tests.

2

The vulnerable pattern

proof of concept — how it is exploited
// assembly { mstore(0x40, x) } writes the free-memory pointer region
// without respecting allocation; under via-IR the optimiser assumes
// memory-safety and mis-schedules, corrupting a later abi.encode.
3

How to fix it

the pattern that is safe
assembly ("memory-safe") {
  // only touch scratch space / properly allocated memory
}
Annotate and respect the memory model in assembly.
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-0235 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