Skip to content

delegatecall Inside a Loop

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

What goes wrong

A delegatecall executes inside a loop, often over caller-supplied targets or calldata (multicall/batch). Each iteration runs foreign code in this contract's storage context; one malicious entry can overwrite owner/critical slots or brick the batch.

2

The vulnerable pattern

proof of concept — how it is exploited
// for (uint i; i < calls.length; i++) { impl.delegatecall(calls[i]); }
// one crafted element calls a function that sets owner = attacker in THIS
// contract's storage — full takeover mid-batch.
3

How to fix it

the pattern that is safe
// avoid delegatecall in loops; if batching, delegatecall only to a fixed,
// trusted, immutable implementation and validate every element first.
delegatecall in a loop multiplies the blast radius.
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-0302 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