refactor(ERC165Checker) replaced assembly code with staticcall() (#1829)
* refactor(ERC165Checker) replaced assembly code with function * returned false if result.length==0 * trigger ci * updated ERC165Checker to return false if result.length < 32
This commit is contained in:
committed by
Francisco Giordano
parent
b33b906b6e
commit
5ab6b99607
@ -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}.
|
||||
@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user