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

refactor(ERC165Checker) replaced assembly code with staticcall() #1829

Merged
merged 8 commits into from
Sep 11, 2019
27 changes: 5 additions & 22 deletions contracts/introspection/ERC165Checker.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.5.10;

/**
* @dev Library used to query support of an interface declared via {IERC165}.
Expand Down Expand Up @@ -94,28 +94,11 @@ library ERC165Checker {
function _callERC165SupportsInterface(address account, bytes4 interfaceId)
private
view
returns (bool success, bool result)
returns (bool, bool)
{
bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId);

// solhint-disable-next-line no-inline-assembly
assembly {
let encodedParams_data := add(0x20, encodedParams)
let encodedParams_size := mload(encodedParams)

let output := mload(0x40) // Find empty storage location using "free memory pointer"
mstore(output, 0x0)

success := staticcall(
30000, // 30k gas
account, // To addr
encodedParams_data,
encodedParams_size,
output,
0x20 // Outputs are 32 bytes long
)

result := mload(output) // Load the result
}
(bool success, bytes memory result) = account.staticcall.gas(30000)(encodedParams);
if (result.length < 32) return (false, false);
return (success, abi.decode(result, (bool)));
yopereir marked this conversation as resolved.
Show resolved Hide resolved
}
}