Custom Error Explained in Detail
Custom errors are declared with error and used with revert. They return a selector and encoded arguments, similar to function-call data.
They are usually cheaper than revert strings and make tests more precise.
Smart contract example
error NotOwner(address caller);
if (msg.sender != owner) revert NotOwner(msg.sender);
Tests can check the exact error selector and arguments.
Custom Error in Auditing
Custom errors document expected failure paths. Precise errors also help tests prove that a function failed for the intended reason, not because of an unrelated revert.
Auditors use them to understand control flow and authorization failures.
Red flags in code
-
Different failure cases use the same vague error.
-
Access-control failures emit the wrong error.
-
Sensitive data is included in error arguments.
-
Low-level callers ignore or mis-handle revert data.
-
Tests only expect any revert instead of the intended error.
How to test or review it
-
Assert exact custom errors for important failure paths.
-
Check error arguments match the failed condition.
-
Review low-level call wrappers that bubble errors.
-
Ensure errors support debugging without leaking sensitive data.
-
Use errors to distinguish authorization, validation, and state failures.
Keep learning this topic
Function Selector
A function selector is the first 4 bytes of calldata that tells an EVM contract which function should handle a call.
External Call
An external call is an interaction where one smart contract calls another address, creating a trust boundary and possible control-flow risk.
Unchecked Return Value
An unchecked return value bug happens when code ignores whether a low-level call or token operation succeeded.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Custom Error into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.