7

From what I understand, the idea of having to pay Gas for executing contracts is to prevent a malicious (or even non-malicious) contract from getting stuck in an infinite loop and consuming the resources of the network. When the Gas runs out, the contract stops executing.

But what if I load up my infinitely looping contract with enough Gas to keep it looping for a significant length of time? Are there any other failsafes in the network that could shut the contract down?

6

For an extended period of time No, for a temporary period Maybe. An infinitely loop will quickly hit the block gas limit and then halt with an out of gas exception: the attacker would lose funds. Miners would also have to continually choose this DoS transaction which specifies a gas amount near the block size limit, and even now, legitimate contracts which take near the block gas limit for their initial deployment, are not given priority by miners (see Note below).

Now assuming that miners were choosing this DoS transaction, non-attackers would increase their gas price. Miners generally prioritize those transactions with higher gas prices since they get more ether. So to continue the attack, the attacker would have to specify higher gas prices and thus their funds will get depleted faster.

Note: Miners actually prefer many more "small gas" transactions to include in a block, instead of a single transaction that consumes the block gas limit. This is because that single transaction may in fact only consume a small amount of gas: it's only the small amount that the miner would get and all the remaining would be refunded back to the transaction's sender. Recall that as long as there's no out of gas exception, the sender gets all the remaining gas back.

1

No, because there is a gas limit of 3.14mil (π mil) per block at this moment. Because there is a maximum per given block, it's not possible to transact a contract method that uses more gas than that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.