Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using ERC165 check for one supported interface directly #3339

Merged
merged 8 commits into from
Jun 27, 2022
12 changes: 6 additions & 6 deletions contracts/utils/introspection/ERC165Checker.sol
Expand Up @@ -23,8 +23,8 @@ library ERC165Checker {
// Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return
_supportsERC165Interface(account, type(IERC165).interfaceId) &&
!_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
supportsERC165InterfaceRaw(account, type(IERC165).interfaceId) &&
!supportsERC165InterfaceRaw(account, _INTERFACE_ID_INVALID);
}

/**
Expand All @@ -35,7 +35,7 @@ library ERC165Checker {
*/
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
// query support of both ERC165 as per the spec and support of _interfaceId
return supportsERC165(account) && _supportsERC165Interface(account, interfaceId);
return supportsERC165(account) && supportsERC165InterfaceRaw(account, interfaceId);
}

/**
Expand All @@ -60,7 +60,7 @@ library ERC165Checker {
if (supportsERC165(account)) {
// query support of each interface in interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);
interfaceIdsSupported[i] = supportsERC165InterfaceRaw(account, interfaceIds[i]);
}
}

Expand All @@ -84,7 +84,7 @@ library ERC165Checker {

// query support of each interface in _interfaceIds
for (uint256 i = 0; i < interfaceIds.length; i++) {
if (!_supportsERC165Interface(account, interfaceIds[i])) {
if (!supportsERC165InterfaceRaw(account, interfaceIds[i])) {
return false;
}
}
Expand All @@ -104,7 +104,7 @@ library ERC165Checker {
* with {supportsERC165}.
* Interface identification is specified in ERC-165.
*/
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
function supportsERC165InterfaceRaw(address account, bytes4 interfaceId) internal view returns (bool) {
bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
(bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams);
if (result.length < 32) return false;
Expand Down