solidity/test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol
2021-11-08 14:58:09 +01:00

35 lines
1.2 KiB
Solidity

interface Identity {
function selectorAndAppendValue(uint value) external pure returns (uint);
}
interface ReturnMoreData {
function f(uint value) external pure returns (uint, uint, uint);
}
contract C {
Identity constant i = Identity(address(0x0004));
function testHighLevel() external pure returns (bool) {
// Works because the extcodesize check is skipped
// and the precompiled contract returns actual data.
i.selectorAndAppendValue(5);
return true;
}
function testHighLevel2() external pure returns (uint, uint, uint) {
// Fails because the identity contract does not return enough data.
return ReturnMoreData(address(4)).f(2);
}
function testLowLevel() external view returns (uint value) {
(bool success, bytes memory ret) =
address(4).staticcall(
abi.encodeWithSelector(Identity.selectorAndAppendValue.selector, uint(5))
);
value = abi.decode(ret, (uint));
}
}
// ====
// compileViaYul: also
// EVMVersion: >=constantinople
// ----
// testHighLevel() -> FAILURE
// testLowLevel() -> 0xc76596d400000000000000000000000000000000000000000000000000000000
// testHighLevel2() -> FAILURE