0

Are state changes reversed if the contract "crashes" during execution?

I know that state changes are reversed, if the contract runs out of gas during execution.

However, are state changes also reversed if the contract crashes by execution an invalid instruction?

If the contract chrashes, how much gas is consumed? The gasLimit or gas consumed up until that point?

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

1

If you attempt to execute an invalid opcode, the transaction fails, all gas (up to the gas limit) is consumed, and the transaction is aborted. (No changes are persisted.)

  • Does the same happens if a transaction tries to transfer more ether value than it has? – Shuzheng Dec 29 '17 at 15:01
  • There are multiple ways to transfer ether. If you use send, the call will just return false. If you use transfer, it will revert on failure, which means the remaining gas is returned, but the transaction is still aborted. – user19510 Dec 29 '17 at 15:11
  • What if you don’t use Solidity? – Shuzheng Dec 29 '17 at 15:45
  • I believe that the underlying CALL opcode just returns 0. It's up to you to decide what to do with that failure (e.g. REVERT). – user19510 Dec 29 '17 at 15:57

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.