1

I stumbled on this EIP which describes the revert opcode that looks like it allows you to "throw" more specific errors by passing a memory pointer with the opcode (also described briefly in the docs). Note in the docs that return and revert receive the same input format.

So far, I have this function as an example:

function throwError(bytes _error) constant returns (bytes32) {
    assembly {
        calldatacopy(0xff, 0, calldatasize)
        return(add(0xff, 68), 32)
    }
}

It works as expected, copying the string passed as function parameter and returning it. However, when I change return to revert like this:

function throwError(bytes _error) constant returns (bytes32) {
    assembly {
        calldatacopy(0xff, 0, calldatasize)
        revert(add(0xff, 68), 32)
    }
}

All I get back is a normal invalid opcode error from web3, truffle, and remix when testing with testrpc. I don't see any reason why this wouldn't work; is there something I'm missing here?

1

revert is not yet implemented in the EVM so it does indeed currently result in an invalid opcode (it's genuinely an invalid op-code in this case, not a proxy for throw). It will be part of the Metropolis update.

  • The feature is listed in release 0.4.10: Inline assembly: Support revert (EIP140) as an opcode. – emm Aug 3 '17 at 21:25
  • Yes, the correct revert opcode is inserted by the compiler, 0xfd, but the EVM doesn't recognise it yet, so it barfs and will continue to do so until the first Metropolis fork. – benjaminion Aug 3 '17 at 21:43
  • Ohh that's interesting. Thanks for that clarification or I would've been trying to debug this for hours! – emm Aug 3 '17 at 21:49
  • is there any updated on this issue? does opcode revert exist with full capabilities? – Ilan Dshare Mar 28 '18 at 13:12
  • Yes, REVERT was implemented in the Byzantium fork and works fine. However, current Solidity does not implement the ability to handle the data returned by Revert (the revert reason). This should be available Real Soon Now (maybe even is as an experimental feature. I'm too lazy to check). – benjaminion Mar 31 '18 at 18:06

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.