Crypto winter
English

Unbounded loops and gas limits

An operation over a growing list can become uncallable once its worst-case cost exceeds the block gas budget.

Risk assessment

An operation over a growing list can become uncallable once its worst-case cost exceeds the block gas budget.

Mitigation

Use bounded batches or claim-based withdrawals. Preserve progress across transactions and keep failures isolated.

Solidity mitigation excerpt

require(limit > 0 && limit <= MAX_BATCH, InvalidBatch());
uint256 end = cursor + Math.min(limit, items.length - cursor);

Foundry · Regression check

Test batches at the maximum supported size, assert that progress resumes at the next cursor and no item is processed twice.

Mitigation

Related topics

What should I verify first?

Test batches at the maximum supported size, assert that progress resumes at the next cursor and no item is processed twice.

Primary reference