Grep-Fu - show all signatures for custom errors

Posted on Tue 07 March 2023 in tech


Custom errors are a feature of Solidity that allow you to display error messages to the user in a convenient and gas-efficient way. They are declared in the head of the contract and called after a revert statement.

error Unauthorized();
if (msg.sender != owner()) {
  revert Unauthorized();

However, a challenge of working with contracts on chain is they may revert without decoding which error message you are seeing. Leaving you with an exaustive search to find which error occurred.

Example of this issue is below:

$ cast send 0x62Ee89399824fCf1978C0675E2d720644B4Dd0B1 "startVote(uint256)" --private-key ${ETH_DEV_PRIVATE} --rpc-url  ${DEVNET_RPC_URL} 1
(code: 3, message: execution reverted, data: Some(String("0x82b429000000000000000000000000000000000000000000000000000000000000000001")))

To show all signatures in a project, use RipGrep and cast as follows:

$ rg --no-line-number --no-filename error **/*/*.sol | sed -e "s/error //g" - | sed -e "s/;//g" - | xargs -I {} cast sig {}

Now it is easy to confirm that the revert topic was generated by the above error.