feat(zevm): add ret bytes to error when zEVM contract call reverts #753
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.
closes #742
This PR adds return code of a zEVM contract if it's called from external chains and reverts. The return code carries the "REVERT" opcode and its parameters, from which revert error messages can be reconstructed (perhaps with help of contract ABI if it's a typed error instead of a string).
Here's an example contract that always reverts:
when called from external chains, the CCTX aborts with error message:
The ret code can be interpreted:
Let's break it down and interpret the different parts:
The first four bytes,
0x08c379a0
is the keccak256 hash of type "Error(string)". This indicates the revert() was called with a string, rather than a typed error.The rest of the data,
00000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a686579207468697320697320616e206572726f72206d6573736167652066726f6d20726576657274282900000000000000000000000000000000000000000000
, represents the encoded error parameters. Let's decode it further:The first 32 bytes (
0000000000000000000000000000000000000000000000000000000000000000
) represent the length of the error string, which is zero in this case.The next 32 bytes (
0000000000000000000000000000000000000000000000000000000000000002
) represent the length of the array containing two elements.Following that, we have the two array elements:
The first array element is
0x686579207468697320697320616e206572726f72206d6573736167652066726f6d207265766572742829
. This is the hexadecimal representation of the string "hey this is an error message from revert()".The second array element is
0x0000000000000000000000000000000000000000000000000000000000000000
, indicating the end of the array.Therefore, the reason string for the revert is "hey this is an error message from revert()".
Please note that this interpretation assumes the error parameters are encoded using the standard Ethereum ABI encoding.