solidity/test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol

35 lines
1.2 KiB
Solidity
Raw Normal View History

interface Identity {
function selectorAndAppendValue(uint value) external pure returns (uint);
}
2021-10-28 10:35:06 +00:00
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) {
2021-10-28 10:35:06 +00:00
// Works because the extcodesize check is skipped
// and the precompiled contract returns actual data.
i.selectorAndAppendValue(5);
return true;
}
2021-10-28 10:35:06 +00:00
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
2021-10-28 10:35:06 +00:00
// testHighLevel2() -> FAILURE