Skip to content

Memory Corruption in Assembly

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

What goes wrong

Assembly writes past allocated memory or mismanages the free-memory pointer (0x40), overwriting adjacent data structures and producing exploitable corruption.

2

How to fix it

the pattern that is safe
assembly {
    let p := mload(0x40)
    mstore(p, val)
    mstore(0x40, add(p, 0x20))   // advance free pointer
}
Respect Solidity memory layout in assembly.
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-0032 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