-
Notifications
You must be signed in to change notification settings - Fork 614
CustomRevertDecoder #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CustomRevertDecoder #470
Conversation
gretzke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to not only be able to decode bytes4 for the additional context but also bytes for selectors with arguments. We don't use them in v4-core but I think it would be helpful to make it general purpose
| // Decode the additional context | ||
| ptr := mload(0x40) | ||
| additionalContextReason := ptr | ||
| mstore(additionalContextReason, sizeAdditionalContext) | ||
|
|
||
| w := not(0x1f) | ||
|
|
||
| for { let s := and(add(sizeAdditionalContext, 0x20), w) } 1 {} { | ||
| mstore(add(additionalContextReason, s), mload(add(err, add(offsetAdditionalContext, add(0x24, s))))) | ||
| s := add(s, w) | ||
| if iszero(s) { break } | ||
| } | ||
|
|
||
| mstore(0x40, add(ptr, add(0x20, sizeAdditionalContext))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clemlak I added support for arbitrary bytes in additionalContext for reverts of the following format:
bytes memory data = abi.encodeWithSelector(
wrappedErrorSelector,
revertingContract,
revertingFunctionSelector,
abi.encodeWithSelector(revertReasonSelector, reasonData),
abi.encodeWithSelector(additionalContextSelector, additionalContextData) // <-- additionalContextData
);I'm reusing your size / looping logic -- is re-using mload(0x40) safe? what about the 0x24 magic-offset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you encode the additional context data you have to make sure it's encoded properly. Because you can't just use abi.encodeWithSelector(selector,abi.encode(uint256,bytes)) for example, as the encoded result of abi.encodeWithSelector(selector,uint256,bytes) would be different.
Related Issue
Developers are reporting that CustomRevert wrapping can be frustrating to use, given that it produces an arbitrary concatenated byte string
Description of changes
Introduce
CustomRevertDecoderwhich slices out the data into descriptive variables