1

In Solidity's 0.4.9 release:

Internal exceptions are now thrown by using an invalid opcode (0xfe), manual exceptions still use an invalid jump.

and

Code generator: Internal errors (array out of bounds, etc.) now cause a reversion by using an invalid instruction (0xfe - EIP141) instead of an invalid jump. Invalid jump is still kept for explicit throws.

Why the difference? Is there an advantage to using an invalid jump destination rather than the 0xfe opcode for explicit throws?

1

the whole idea behind using the invalid jump is burning the whole gas and therefore punishing the user for trying to do something he wasn't allowed to. First all exceptions used an invalid jump, but this can also lead to users being punished in an unfair way: If a user causes an array out of bounds without any bad intentions, all his gas was automatically burned. This was replaced with the invalid opcode, whereas devs still can punish users with a manual throw.

  • An invalid opcode also burns all gas. So a throw can use invalid opcode instead of an invalid jump. Can you clarify why in one case "This was replaced with the invalid opcode", and in the manual throw case, invalid jump was not replaced with invalid opcode? – eth May 22 '17 at 9:27
  • Yes, I got that wrong, the invalid opcode indeed burns al gas, too. But invalid opcodes for programmatical errors allow fo easier / more differentiated error reporting:It's easier to tell if the code or a manual throw is the reason for the failure of a transaction. E.g. did I call for an array value I wasn't supposed to, or did I simply jump out of bounds ? – Nikita Fuchs May 22 '17 at 15:15

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.