Skip to content

Commit

Permalink
refactor(ERC165Checker) replaced assembly code with staticcall() (#1829)
Browse files Browse the repository at this point in the history
* refactor(ERC165Checker) replaced assembly code with function

* returned false if result.length==0

* trigger ci

* updated ERC165Checker to return false if result.length < 32
  • Loading branch information
yopereir authored and frangio committed Sep 11, 2019
1 parent b33b906 commit 5ab6b99
Showing 1 changed file with 5 additions and 22 deletions.
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)));
}
}

0 comments on commit 5ab6b99

Please sign in to comment.