My question is regarding the second condition. Why would you want to confirm the support of a given interface if its just the interface of the IERC165 by OZ which only has a single function namely supportInterface()
Each contract that implements the ERC-165 standard (or some other standard that extends it, e.g. ERC-721), should return true for supportsInterface(0x01ffc9a7) and false for supportsInterface(0xffffffff).
It is a sign that your contract really implements this specific standard, and that it's not just a coincidence in naming the function.
Hey thanks for the reply. In our case we use it to validate that an address we pass to a function implements a specific interface ( Not just the ERC165 interface). Just implementing the ERC165 interface would not be enough and should not pass the validation
Is our use case maybe not the standard way of using ERC165 standard?
I don't think I understand your motivation behind that. But if you want to implement the rest of the standard without showing that you implement the standard (i.e. not fully implementing it), then sure, you can technically do that by not calling the parent method.
Exactly as you mentioned in your question:
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
// purposely omitting the parent method call
return interfaceId == type(MyInterface).interfaceId;
}
The reason is that we have a registry contract that registers addresses that comply with a given MyInterface. If they comply they get registered in the registry contract. A contract that only implements ERC165 but not my interface should not be registered. Maybe in our case we should not inherit ther ERC165 OZ contract at all and just write our own method without an override:
function supportsInterface(bytes4 interfaceId) public view returns (bool) {
// purposely omitting the parent method call
return interfaceId == type(MyInterface).interfaceId;
}
I see thanks for clarifying. Its not for some strange reason i guess we just want to validate contracts that get passed into a function to support a specific interface. So we should never have used the ERC165 standard i suppose. Btw by any other interface you mean not any but those you have specified as MyInterface right?
The reason for ERC165 asking for 0x01ffc9a7 to return true ... is that if someone "just" look for your interface, and doesn't get the value it expects, its not sure if its because the interface is not supported, of because ERC165 is not supported or not working correctly. That is why one should check 0x01ffc9a7 first, if that that returns the expected value, then do the real query.
To detect cases where supportsInterface(bytes4) is not implemented, and there is a fallback function that returns some value. This value would possibly be interpreted as true.
By checking that 0x01ffc9a7 returns true and 0xffffffff returns false, you have some good reason to assume the function that answered is EIP-165 compliant.