Conversation
gretzke
left a comment
There was a problem hiding this comment.
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.
@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.
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