Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Preamble
Simple Summary
Instead of throwing opaque string reverts, 3.0 contracts will instead throw custom, ABI-encoded "rich" revert types augmented with much more useful parameters.
Motivation
Reverting with expressive error data will enable developers to create more robust applications built on top of the 0x protocol.
Additionally, this is a critical step towards our goal of becoming a language-agnostic protocol, wherein applications can rely more on the contracts themselves and less on off-chain tooling to validate and debug interactions.
Specification
Encoding
Standard string reverts (à la Soldity's
require()
andrevert()
builtins) are ABI-encoded as a function call with signatureError(string)
.For example, a
revert("foobar")
would encode as:Our rich reverts follow the same encoding rules but with varying function signatures.
For example, the rich revert
SignatureError
has the signature:If we construct it with the following values:
The resulting encoding will be:
Decoding
Nodes will only return revert data for
eth_call
operations, though it is possible (but not foolproof) to replay a failed transaction usingeth_call
and a block number.Furthermore, with geth there is an issue where the JSON-RPC response for a successful
eth_call
is indistinguishable from a revert. For this reason, (at minimum) we need to check the leading 4 bytes of the return data against a mapping of known error selectors to detect that a revert actually occurred. This is a little inelegant, but with roughly 4 billion combinations of leading 4 bytes, combined with more rigorous conformance checks, false positives should be extremely rare.Once the exact error type is detected, ABI decoding tools can be used to extract individual parameter values.
For environments where ABI decoding tools are not exposed/available, we will also be deploying a helper contract that decomposes encoded error bytes into its constituent fields.
Copyright
Copyright and related rights waived via CC0.