@@ -22,9 +22,9 @@ library ERC165Checker {
2222 function supportsERC165 (address account ) internal view returns (bool ) {
2323 // Any contract that implements ERC-165 must explicitly indicate support of
2424 // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
25- return
26- supportsERC165InterfaceUnchecked (account, type ( IERC165 ).interfaceId) &&
27- ! supportsERC165InterfaceUnchecked (account, INTERFACE_ID_INVALID) ;
25+ if ( ! supportsERC165InterfaceUnchecked (account, type ( IERC165 ).interfaceId)) return false ;
26+ ( bool success , bool supported ) = trySupportsInterface (account, INTERFACE_ID_INVALID);
27+ return success && ! supported ;
2828 }
2929
3030 /**
@@ -106,19 +106,32 @@ library ERC165Checker {
106106 * Interface identification is specified in ERC-165.
107107 */
108108 function supportsERC165InterfaceUnchecked (address account , bytes4 interfaceId ) internal view returns (bool ) {
109- // prepare call
110- bytes memory encodedParams = abi.encodeCall (IERC165 .supportsInterface, (interfaceId));
109+ (bool success , bool supported ) = trySupportsInterface (account, interfaceId);
110+ return success && supported;
111+ }
111112
112- // perform static call
113- bool success;
113+ /**
114+ * @dev Attempts to call `supportsInterface` on a contract and returns both the call
115+ * success status and the interface support result.
116+ *
117+ * This function performs a low-level static call to the contract's `supportsInterface`
118+ * function. It returns:
119+ *
120+ * * `success`: true if the call didn't revert, false if it did
121+ * * `supported`: true if the call succeeded AND returned data indicating the interface is supported
122+ */
123+ function trySupportsInterface (
124+ address account ,
125+ bytes4 interfaceId
126+ ) internal view returns (bool success , bool supported ) {
114127 uint256 returnSize;
115128 uint256 returnValue;
129+ bytes memory encodedParams = abi.encodeCall (IERC165 .supportsInterface, (interfaceId));
116130 assembly ("memory-safe" ) {
117131 success := staticcall (30000 , account, add (encodedParams, 0x20 ), mload (encodedParams), 0x00 , 0x20 )
118132 returnSize := returndatasize ()
119133 returnValue := mload (0x00 )
120134 }
121-
122- return success && returnSize >= 0x20 && returnValue > 0 ;
135+ return (success, returnSize >= 0x20 && returnValue > 0 );
123136 }
124137}
0 commit comments