The Myth and Reality of DoS Attacks via Unbounded Loops in Smart Contracts

Jun 2
10
min of reading

A frequently discussed vulnerability is thepotential for denial-of-service (DoS) attacks caused by unbounded loops. Theseattacks can theoretically occur when a contract function runs out of gas due toiterating over excessively large datasets, thus preventing the execution of thefunction. At first glance, this seems like a critical issue that could plagueany smart contract. But how much of a threat is it really in the day-to-dayoperations on Ethereum and similar blockchains?

Understanding Gas Limits

Ethereum and other blockchains like BSCoperate under a gas limit system. This system is designed to limit the amountof gas a block can consume, thereby preventing spam and ensuring networkstability. As example, Ethereum's block gas limit sits around 30 million, whileBSC has an even higher limit of 140 million. If these numbers are incorrect,please correct me.

The Practical Perspective

Given these gas limits, one might wonderhow often contracts actually hit these limits due to unbounded loops. Inpractice, the instances are less common than one might expect.

The reason is twofold:

Smart Contract Design: Developers aregenerally aware of the potential pitfalls of unbounded loops and design theircontracts to avoid them. This includes using patterns that limit the number ofiterations in a loop or opting for alternative architectural choices thatminimize on-chain computation.

Gas Limit Awareness:

The high block gas limits provide asubstantial buffer for transaction execution. While it's theoretically possibleto craft a transaction that hits these limits, practical constraints (includingtransaction costs and the inherent limitations of what needs to be computedon-chain) often keep operations well within safe bounds. Usually operationswon't run out of gas, even after the contract being in an un-updated state foryears.

Despite the theoretical nature of DoSattacks via unbounded loops, it remains essential for auditors to reportpotential vulnerabilities. The landscape of blockchain technology isever-evolving, and what may seem impractical today could become a significantthreat tomorrow. Vigilance and proactive security practices are key tomaintaining the integrity and trustworthiness of smart contracts.

The threat of DoS attacks through unboundedloops, while theoretically plausible, is mitigated in practice by therelatively high gas limits of blockchains. However, this does not diminish theimportance of diligent security practices.

Read the original article

Related articles