05 - RevertWithSelectorPlusArgs
Goal: Revert with a custom error that includes argument data.
The idea is the same as previous level and this one is easier: the argument x
is a static type instead of dynamic type, so we don’t worry about ABI encoding (offset + length + data format).
Explanation:
We obtain a pointer to free memory via
mload(0x40)
.The error selector for
RevertData(uint256)
is0xae412287
. We shift it left by 224 bits (32 bytes - 4 bytes = 28 bytes; 28 * 8 = 224 bits) so that it occupies the high-order 4 bytes of a 32-byte word.The parameter
x
is stored immediately after the selector, at memory locationptr + 4
.Finally, we call
revert(ptr, 36)
to trigger a revert with 36 bytes of error data (4 bytes of selector + 32 bytes for the encoded uint256).
Run test:
Last updated