14

As gas cost can only be estimated until the transaction is executed against the actual contract state at the time of execution on the blockchain, what happens if transaction runs out of gas before the transaction is completed?

Presumably the contract rolls back as if the transaction never happened.

If this is the case, then what prevents malicious users from spamming Ethereum nodes with complex transactions that do not carry sufficient funds?

14

Correct, it rolls back. Except for one thing: it gives the miner all the gas, you don't get that back. That's what keeps attackers from spamming, and it's fair anyway because the miner still had to do the computation you did pay for, even though you didn't include enough gas to finish.

  • Thanks for the answer! Are you sure that the write to the contact's key/value store will be rolled back as well? – Helin Wang Feb 7 '18 at 18:33
  • Yep definitely. – Dennis Peterson Feb 9 '18 at 1:34

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.