Skip to content

DoS via Unbounded Loop / Gas Exhaustion

SAFE-0038 Denial of Service Checked automatically by the scanner
1

What goes wrong

A loop iterates over an unbounded, user-growable array. As the array grows, the gas cost exceeds the block limit and the function becomes permanently uncallable.

2

How to fix it

the pattern that is safe
// Maintain a running aggregate, or process in bounded batches:
function process(uint start, uint end) external { require(end-start<=100); /*...*/ }
Bound or paginate all unbounded loops.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0038 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