From 7683442ce27c083c5f51484ba9322c0678339406 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Mon, 1 Nov 2021 10:24:08 +0100 Subject: [PATCH] Semantic test for high level call to precompiles. Because of the extcodesize check, the high level call will fail. Even though the low level call can succeed and return data. --- .../precompile_extcodesize_check.sol | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol diff --git a/test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol b/test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol new file mode 100644 index 000000000..7a9025e26 --- /dev/null +++ b/test/libsolidity/semanticTests/functionCall/precompile_extcodesize_check.sol @@ -0,0 +1,25 @@ +interface Identity { + function selectorAndAppendValue(uint value) external pure returns (uint); +} +contract C { + Identity constant i = Identity(address(0x0004)); + function testHighLevel() external pure returns (bool) { + // Should fail because `extcodesize(4) = 0` + i.selectorAndAppendValue(5); + return true; + } + 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