supportsInterface Explained in Detail
supportsInterface(bytes4 interfaceId) returns true or false for an interface ID. It is the main function defined by ERC165.
A good implementation is predictable, cheap to call, and honest about what the contract can actually do.
Smart contract example
return interfaceId == type(IERC721).interfaceId || super.supportsInterface(interfaceId);
The super call matters when the contract inherits support from parent contracts.
supportsInterface in Auditing
Contracts and off-chain systems may use supportsInterface before choosing how to interact with a target. A false answer can make integrations skip safety logic or call the wrong path.
Auditors check both the function and the behavior behind each claimed interface.
Red flags in code
-
The function returns true for every input.
-
It forgets inherited interfaces.
-
It depends on
msg.senderor mutable caller context. -
It claims ERC721 or ERC1155 support while missing required functions.
-
It is tested directly on the implementation but not through the proxy.
How to test or review it
-
Assert every expected interface ID explicitly.
-
Assert
0xffffffffreturns false. -
Test random unknown IDs.
-
Check interface support after upgrades.
-
Verify the advertised interface functions exist and behave correctly.
Keep learning this topic
ERC165
ERC165 is the Ethereum standard for interface detection through supportsInterface(bytes4).
Selector Collision
A selector collision happens when two function signatures share the same 4-byte selector or when routing code maps a selector to the wrong function.
Upgradeable Proxy
An upgradeable proxy is a smart contract pattern where users call a stable proxy address while execution is delegated to replaceable implementation logic.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like supportsInterface into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.