In this track: Smart contract security foundations
advanced · 4 MIN READ

Denial of service in loops

Unbounded work can make a required operation impossible to complete.

LET’S PICTURE IT

A clerk required to process the entire growing queue in one sitting can eventually never finish.

SEE IT FOR YOURSELF
Calculate and split a manual execution feeStep 1 / 4
Calculate and split a manual execution feeGas used21,000A resource quantityGas used and gas limit are different quantitiesBase10 GweiEffective tip2 GweiTotal rate12 Gwei / gasAssumed total cap: 20 Gwei; no live prices are fetchedWork × rate21,000 × 12252,000 GweiExecution fee0.000252 ETHExact unit conversionThis calculation excludes blob and layer 2 data feesBase component0.00021 ETHBurned by protocolPriority component0.000042 ETHTo fee recipientComponents sum to the supplied 0.000252 ETH example

This example supplies twenty-one thousand gas used. It is a simple teaching input, not a live estimate of a contract call.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Locate required global loops

A function iterating over every participant can become too costly as the collection grows. The risk matters most when no alternate progress path exists.

Include failing recipients

One recipient that rejects a push payment can block a batch if the whole loop reverts. This is a separate issue from the number of iterations.

Design bounded progress

Pagination, pull-based claims or other bounded work can let the system advance without processing every user at once. Each design still needs consistent accounting.

Test worst-case growth

Measure maximum supported batch sizes and hostile recipient behavior. A test with three friendly participants does not establish long-term liveness.

Reason about the scenario

required task: pay every registered user in one call
risks: growing list + one rejecting recipient
review: bounded batches or independent claims

Pseudocode or a simplified scenario for local reasoning. This is not a production contract or a completed security review.

QUICK CHECK · NO PRESSURE

Can one reverting recipient block an all-or-nothing payout loop?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.