DoS using loops
Like every Turing-complete programming language, solidity supports different types of loops to perform repeated tasks. Loops can be straightforward, but there are some situations where this can cause unexpected DoS.
In this recipe, you will learn to avoid a few accidental bugs that can occur even in the absence of an external attack.
Getting ready
It's expected that you have a basic understanding of the Ethereum blockchain and solidity before stepping through this recipe.
The Remix IDE (https://remix.ethereum.org) can help you quickly test and deploy the contract. Also, you can use any Ethereum client (geth
, parity
, and so on) and the solc
compiler to run this contract.
How to do it...
- Loops can be very tricky when it comes to solidty. There aretwovery common mistakes that anyone can easily overlook while writing smart contracts.
- Create a function that uses a for loop to iterate through an array of addresses and transfer the payout:
pragma solidity ^0.4.24; contract Payout { ...