From 67e9776418e155a663dd5076d41829249f5b64f2 Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Fri, 20 Mar 2020 18:32:30 -0500 Subject: [PATCH 1/2] Extract 45 tests from SolidityEndToEndTest.cpp --- test/libsolidity/SolidityEndToEndTest.cpp | 1268 ----------------- .../extracted/abi_decode_calldata.sol | 11 + .../extracted/abi_decode_simple.sol | 7 + .../extracted/abi_decode_simple_storage.sol | 10 + .../extracted/abi_encode_empty_string.sol | 11 + .../arrays_complex_from_and_to_storage.sol | 18 + .../arrays_complex_memory_index_access.sol | 13 + ...signment_to_const_var_involving_keccak.sol | 9 + .../bitwise_shifting_constantinople.sol | 34 + ...twise_shifting_constantinople_combined.sol | 122 ++ ...wise_shifting_constants_constantinople.sol | 83 ++ .../extracted/bool_conversion.sol | 23 + .../extracted/bool_conversion_v2.sol | 24 + .../extracted/bytes_memory_index_access.sol | 13 + .../calldata_array_dynamic_bytes.sol | 74 + .../calldata_bytes_array_to_memory.sol | 18 + .../extracted/calldata_string_array.sol | 15 + .../extracted/calldata_struct_cleaning.sol | 22 + .../extracted/cleanup_address_types.sol | 17 + .../extracted/cleanup_address_types_v2.sol | 18 + .../extracted/cleanup_bytes_types.sol | 13 + .../extracted/cleanup_bytes_types_v2.sol | 14 + .../extracted/delegatecall_return_value.sol | 37 + ...elegatecall_return_value_pre_byzantium.sol | 39 + .../extracted/fixed_arrays_in_storage.sol | 45 + .../extracted/fixed_bytes_index_access.sol | 17 + .../extracted/function_types_sig.sol | 26 + .../iterated_keccak256_with_bytes.sol | 12 + .../keccak256_multiple_arguments.sol | 7 + ...ltiple_arguments_with_numeric_literals.sol | 7 + ...ultiple_arguments_with_string_literals.sol | 12 + ...mory_arrays_dynamic_index_access_write.sol | 19 + .../memory_arrays_index_access_write.sol | 14 + .../extracted/memory_structs_nested_load.sol | 69 + .../semanticTests/extracted/msg_sig.sol | 9 + .../msg_sig_after_internal_call_is_same.sol | 13 + .../extracted/multi_modifiers.sol | 23 + .../extracted/reusing_memory.sol | 26 + .../extracted/shift_right_garbled.sol | 14 + .../extracted/shift_right_garbled_signed.sol | 30 + .../shift_right_garbled_signed_v2.sol | 31 + .../extracted/shift_right_garbled_v2.sol | 15 + ...right_negative_lvalue_signextend_int16.sol | 13 + ...ht_negative_lvalue_signextend_int16_v2.sol | 14 + ...right_negative_lvalue_signextend_int32.sol | 13 + ...ht_negative_lvalue_signextend_int32_v2.sol | 14 + ..._right_negative_lvalue_signextend_int8.sol | 13 + ...ght_negative_lvalue_signextend_int8_v2.sol | 14 + .../staticcall_for_view_and_pure.sol | 39 + ...iccall_for_view_and_pure_pre_byzantium.sol | 39 + .../extracted/string_allocation_bug.sol | 20 + .../extracted/string_bytes_conversion.sol | 17 + .../extracted/strings_in_struct.sol | 35 + .../extracted/struct_constructor_nested.sol | 30 + 54 files changed, 1295 insertions(+), 1268 deletions(-) create mode 100644 test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol create mode 100644 test/libsolidity/semanticTests/extracted/abi_decode_simple.sol create mode 100644 test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol create mode 100644 test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol create mode 100644 test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol create mode 100644 test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol create mode 100644 test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol create mode 100644 test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol create mode 100644 test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol create mode 100644 test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol create mode 100644 test/libsolidity/semanticTests/extracted/bool_conversion.sol create mode 100644 test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol create mode 100644 test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol create mode 100644 test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol create mode 100644 test/libsolidity/semanticTests/extracted/calldata_string_array.sol create mode 100644 test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol create mode 100644 test/libsolidity/semanticTests/extracted/cleanup_address_types.sol create mode 100644 test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol create mode 100644 test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol create mode 100644 test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol create mode 100644 test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol create mode 100644 test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol create mode 100644 test/libsolidity/semanticTests/extracted/function_types_sig.sol create mode 100644 test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol create mode 100644 test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol create mode 100644 test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol create mode 100644 test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol create mode 100644 test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol create mode 100644 test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol create mode 100644 test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol create mode 100644 test/libsolidity/semanticTests/extracted/msg_sig.sol create mode 100644 test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol create mode 100644 test/libsolidity/semanticTests/extracted/multi_modifiers.sol create mode 100644 test/libsolidity/semanticTests/extracted/reusing_memory.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_garbled.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol create mode 100644 test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol create mode 100644 test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol create mode 100644 test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol create mode 100644 test/libsolidity/semanticTests/extracted/string_allocation_bug.sol create mode 100644 test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol create mode 100644 test/libsolidity/semanticTests/extracted/strings_in_struct.sol create mode 100644 test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ae39bec0e..69e645494 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1024,39 +1024,6 @@ BOOST_AUTO_TEST_CASE(blockchain) ABI_CHECK(callContractFunctionWithValue("someInfo()", 28), encodeArgs(28, u256("0x1212121212121212121212121212121212121212"), 7)); } -BOOST_AUTO_TEST_CASE(msg_sig) -{ - char const* sourceCode = R"( - contract test { - function foo(uint256 a) public returns (bytes4 value) { - return msg.sig; - } - } - )"; - ALSO_VIA_YUL( - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("foo(uint256)", 0), encodeArgs(asString(FixedHash<4>(util::keccak256("foo(uint256)")).asBytes()))); - ) -} - -BOOST_AUTO_TEST_CASE(msg_sig_after_internal_call_is_same) -{ - char const* sourceCode = R"( - contract test { - function boo() public returns (bytes4 value) { - return msg.sig; - } - function foo(uint256 a) public returns (bytes4 value) { - return boo(); - } - } - )"; - ALSO_VIA_YUL( - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("foo(uint256)", 0), encodeArgs(asString(FixedHash<4>(util::keccak256("foo(uint256)")).asBytes()))); - ) -} - BOOST_AUTO_TEST_CASE(now) { char const* sourceCode = R"( @@ -2403,96 +2370,6 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) ) } -BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments) -{ - char const* sourceCode = R"( - contract c { - function foo(uint a, uint b, uint c) public returns (bytes32 d) - { - d = keccak256(abi.encodePacked(a, b, c)); - } - } - )"; - compileAndRun(sourceCode); - - ABI_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13), encodeArgs( - util::keccak256( - toBigEndian(u256(10)) + - toBigEndian(u256(12)) + - toBigEndian(u256(13)) - ) - )); -} - -BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals) -{ - char const* sourceCode = R"( - contract c { - function foo(uint a, uint16 b) public returns (bytes32 d) - { - d = keccak256(abi.encodePacked(a, b, uint8(145))); - } - } - )"; - compileAndRun(sourceCode); - - ABI_CHECK(callContractFunction("foo(uint256,uint16)", 10, 12), encodeArgs( - util::keccak256( - toBigEndian(u256(10)) + - bytes{0x0, 0xc} + - bytes(1, 0x91) - ) - )); -} - -BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals) -{ - char const* sourceCode = R"( - contract c { - function foo() public returns (bytes32 d) - { - d = keccak256("foo"); - } - function bar(uint a, uint16 b) public returns (bytes32 d) - { - d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); - } - } - )"; - compileAndRun(sourceCode); - - ABI_CHECK(callContractFunction("foo()"), encodeArgs(util::keccak256("foo"))); - - ABI_CHECK(callContractFunction("bar(uint256,uint16)", 10, 12), encodeArgs( - util::keccak256( - toBigEndian(u256(10)) + - bytes{0x0, 0xc} + - bytes(1, 0x91) + - bytes{0x66, 0x6f, 0x6f} - ) - )); -} - -BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes) -{ - char const* sourceCode = R"ABC( - contract c { - bytes data; - function foo() public returns (bytes32) - { - data.push("x"); - data.push("y"); - data.push("z"); - return keccak256(abi.encodePacked("b", keccak256(data), "a")); - } - } - )ABC"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("foo()"), encodeArgs( - u256(util::keccak256(bytes{'b'} + util::keccak256("xyz").asBytes() + bytes{'a'})) - )); -} - BOOST_AUTO_TEST_CASE(generic_call) { char const* sourceCode = R"**( @@ -3095,33 +2972,6 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments) ); } -BOOST_AUTO_TEST_CASE(fixed_arrays_in_storage) -{ - char const* sourceCode = R"( - contract c { - struct Data { uint x; uint y; } - Data[2**10] data; - uint[2**10 + 3] ids; - function setIDStatic(uint id) public { ids[2] = id; } - function setID(uint index, uint id) public { ids[index] = id; } - function setData(uint index, uint x, uint y) public { data[index].x = x; data[index].y = y; } - function getID(uint index) public returns (uint) { return ids[index]; } - function getData(uint index) public returns (uint x, uint y) { x = data[index].x; y = data[index].y; } - function getLengths() public returns (uint l1, uint l2) { l1 = data.length; l2 = ids.length; } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("setIDStatic(uint256)", 11), bytes()); - ABI_CHECK(callContractFunction("getID(uint256)", 2), encodeArgs(11)); - ABI_CHECK(callContractFunction("setID(uint256,uint256)", 7, 8), bytes()); - ABI_CHECK(callContractFunction("getID(uint256)", 7), encodeArgs(8)); - ABI_CHECK(callContractFunction("setData(uint256,uint256,uint256)", 7, 8, 9), bytes()); - ABI_CHECK(callContractFunction("setData(uint256,uint256,uint256)", 8, 10, 11), bytes()); - ABI_CHECK(callContractFunction("getData(uint256)", 7), encodeArgs(8, 9)); - ABI_CHECK(callContractFunction("getData(uint256)", 8), encodeArgs(10, 11)); - ABI_CHECK(callContractFunction("getLengths()"), encodeArgs(u256(1) << 10, (u256(1) << 10) + 3)); -} - BOOST_AUTO_TEST_CASE(fixed_array_cleanup) { char const* sourceCode = R"( @@ -3662,19 +3512,6 @@ BOOST_AUTO_TEST_CASE(array_copy_including_mapping) BOOST_CHECK(storageEmpty(m_contractAddress)); } -BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) -{ - char const* sourceCode = R"( - contract C { - bytes32 constant x = keccak256("abc"); - function f() public returns (bytes32) { return x; } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f()"), encodeArgs(util::keccak256("abc"))); -} - -// Disabled until https://github.com/ethereum/solidity/issues/715 is implemented //BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars) //{ // char const* sourceCode = R"( @@ -3733,35 +3570,6 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete) BOOST_CHECK(storageEmpty(m_contractAddress)); } -BOOST_AUTO_TEST_CASE(bool_conversion) -{ - char const* sourceCode = R"( - contract C { - function f(bool _b) public returns(uint) { - if (_b) - return 1; - else - return 0; - } - function g(bool _in) public returns (bool _out) { - _out = _in; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(bool)", 0), encodeArgs(0)); - ABI_CHECK(callContractFunction("f(bool)", 1), encodeArgs(1)); - ABI_CHECK(callContractFunction("f(bool)", 2), v2 ? encodeArgs() : encodeArgs(1)); - ABI_CHECK(callContractFunction("f(bool)", 3), v2 ? encodeArgs() : encodeArgs(1)); - ABI_CHECK(callContractFunction("f(bool)", 255), v2 ? encodeArgs() : encodeArgs(1)); - ABI_CHECK(callContractFunction("g(bool)", 0), encodeArgs(0)); - ABI_CHECK(callContractFunction("g(bool)", 1), encodeArgs(1)); - ABI_CHECK(callContractFunction("g(bool)", 2), v2 ? encodeArgs() : encodeArgs(1)); - ABI_CHECK(callContractFunction("g(bool)", 3), v2 ? encodeArgs() : encodeArgs(1)); - ABI_CHECK(callContractFunction("g(bool)", 255), v2 ? encodeArgs() : encodeArgs(1)); -} - BOOST_AUTO_TEST_CASE(invalid_enum_logged) { char const* sourceCode = R"( @@ -3837,32 +3645,6 @@ BOOST_AUTO_TEST_CASE(failing_send) BOOST_REQUIRE(callContractFunction("callHelper(address)", c_helperAddress) == encodeArgs(true, 20)); } -BOOST_AUTO_TEST_CASE(reusing_memory) -{ - // Invoke some features that use memory and test that they do not interfere with each other. - char const* sourceCode = R"( - contract Helper { - uint public flag; - constructor(uint x) public { - flag = x; - } - } - contract Main { - mapping(uint => uint) map; - function f(uint x) public returns (uint) { - map[x] = x; - return (new Helper(uint(keccak256(abi.encodePacked(this.g(map[x])))))).flag(); - } - function g(uint a) public returns (uint) - { - return map[a]; - } - } - )"; - compileAndRun(sourceCode, 0, "Main"); - BOOST_REQUIRE(callContractFunction("f(uint256)", 0x34) == encodeArgs(util::keccak256(util::toBigEndian(u256(0x34))))); -} - BOOST_AUTO_TEST_CASE(return_string) { char const* sourceCode = R"( @@ -4195,83 +3977,6 @@ BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage) ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0x20), u256(data.size()), data)); } -BOOST_AUTO_TEST_CASE(arrays_complex_from_and_to_storage) -{ - char const* sourceCode = R"( - contract Test { - uint24[3][] public data; - function set(uint24[3][] memory _data) public returns (uint) { - data = _data; - return data.length; - } - function get() public returns (uint24[3][] memory) { - return data; - } - } - )"; - compileAndRun(sourceCode, 0, "Test"); - - vector data{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; - BOOST_REQUIRE( - callContractFunction("set(uint24[3][])", u256(0x20), u256(data.size() / 3), data) == - encodeArgs(u256(data.size() / 3)) - ); - ABI_CHECK(callContractFunction("data(uint256,uint256)", u256(2), u256(2)), encodeArgs(u256(9))); - ABI_CHECK(callContractFunction("data(uint256,uint256)", u256(5), u256(1)), encodeArgs(u256(17))); - ABI_CHECK(callContractFunction("data(uint256,uint256)", u256(6), u256(0)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0x20), u256(data.size() / 3), data)); -} - -BOOST_AUTO_TEST_CASE(arrays_complex_memory_index_access) -{ - char const* sourceCode = R"( - contract Test { - function set(uint24[3][] memory _data, uint a, uint b) public returns (uint l, uint e) { - l = _data.length; - e = _data[a][b]; - } - } - )"; - vector data{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; - ALSO_VIA_YUL( - compileAndRun(sourceCode, 0, "Test"); - - BOOST_REQUIRE(callContractFunction( - "set(uint24[3][],uint256,uint256)", - u256(0x60), - u256(3), - u256(2), - u256(data.size() / 3), - data - ) == encodeArgs(u256(data.size() / 3), u256(data[3 * 3 + 2]))); - ); -} - -BOOST_AUTO_TEST_CASE(bytes_memory_index_access) -{ - char const* sourceCode = R"( - contract Test { - function set(bytes memory _data, uint i) public returns (uint l, byte c) { - l = _data.length; - c = _data[i]; - } - } - )"; - string data("abcdefgh"); - - ALSO_VIA_YUL( - compileAndRun(sourceCode, 0, "Test"); - - BOOST_REQUIRE(callContractFunction( - "set(bytes,uint256)", - u256(0x40), - u256(3), - u256(data.size()), - data - ) == encodeArgs(u256(data.size()), string("d"))); - ); -} - BOOST_AUTO_TEST_CASE(memory_types_initialisation) { char const* sourceCode = R"( @@ -4323,128 +4028,6 @@ BOOST_AUTO_TEST_CASE(memory_arrays_delete) ABI_CHECK(callContractFunction("del()"), encodeArgs(data)); } -BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write) -{ - char const* sourceCode = R"( - contract Test { - function set(uint24[3][4] memory x) public { - x[2][2] = 1; - x[3][2] = 7; - } - function f() public returns (uint24[3][4] memory){ - uint24[3][4] memory data; - set(data); - return data; - } - } - )"; - compileAndRun(sourceCode, 0, "Test"); - - vector data(3 * 4); - data[3 * 2 + 2] = 1; - data[3 * 3 + 2] = 7; - ABI_CHECK(callContractFunction("f()"), encodeArgs(data)); -} - -BOOST_AUTO_TEST_CASE(memory_arrays_dynamic_index_access_write) -{ - char const* sourceCode = R"( - contract Test { - uint24[3][][4] data; - function set(uint24[3][][4] memory x) internal returns (uint24[3][][4] memory) { - x[1][2][2] = 1; - x[1][3][2] = 7; - return x; - } - function f() public returns (uint24[3][] memory) { - while (data[1].length < 4) - data[1].push(); - return set(data)[1]; - } - } - )"; - compileAndRun(sourceCode, 0, "Test"); - - vector data(3 * 4); - data[3 * 2 + 2] = 1; - data[3 * 3 + 2] = 7; - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0x20), u256(4), data)); -} - -BOOST_AUTO_TEST_CASE(memory_structs_nested_load) -{ - char const* sourceCode = R"( - contract Test { - struct S { uint8 x; uint16 y; uint z; } - struct X { uint8 x; S s; uint8[2] a; } - X m_x; - function load() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { - m_x.x = 1; - m_x.s.x = 2; - m_x.s.y = 3; - m_x.s.z = 4; - m_x.a[0] = 5; - m_x.a[1] = 6; - X memory d = m_x; - a = d.x; - x = d.s.x; - y = d.s.y; - z = d.s.z; - a1 = d.a[0]; - a2 = d.a[1]; - } - function store() public returns (uint a, uint x, uint y, uint z, uint a1, uint a2) { - X memory d; - d.x = 1; - d.s.x = 2; - d.s.y = 3; - d.s.z = 4; - d.a[0] = 5; - d.a[1] = 6; - m_x = d; - a = m_x.x; - x = m_x.s.x; - y = m_x.s.y; - z = m_x.s.z; - a1 = m_x.a[0]; - a2 = m_x.a[1]; - } - } - )"; - compileAndRun(sourceCode, 0, "Test"); - - auto out = encodeArgs(u256(1), u256(2), u256(3), u256(4), u256(5), u256(6)); - ABI_CHECK(callContractFunction("load()"), out); - ABI_CHECK(callContractFunction("store()"), out); -} - -BOOST_AUTO_TEST_CASE(struct_constructor_nested) -{ - char const* sourceCode = R"( - contract C { - struct X { uint x1; uint x2; } - struct S { uint s1; uint[3] s2; X s3; } - S s; - constructor() public { - uint[3] memory s2; - s2[1] = 9; - s = S(1, s2, X(4, 5)); - } - function get() public returns (uint s1, uint[3] memory s2, uint x1, uint x2) - { - s1 = s.s1; - s2 = s.s2; - x1 = s.s3.x1; - x2 = s.s3.x2; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - auto out = encodeArgs(u256(1), u256(0), u256(9), u256(0), u256(4), u256(5)); - ABI_CHECK(callContractFunction("get()"), out); -} - BOOST_AUTO_TEST_CASE(calldata_struct_short) { char const* sourceCode = R"( @@ -4468,31 +4051,6 @@ BOOST_AUTO_TEST_CASE(calldata_struct_short) ABI_CHECK(callContractFunctionNoEncoding("f((uint256,uint256))", bytes()), encodeArgs()); } -BOOST_AUTO_TEST_CASE(calldata_struct_cleaning) -{ - char const* sourceCode = R"( - pragma experimental ABIEncoderV2; - contract C { - struct S { uint8 a; bytes1 b; } - function f(S calldata s) external pure returns (uint256 a, bytes32 b) { - uint8 tmp1 = s.a; - bytes1 tmp2 = s.b; - assembly { - a := tmp1 - b := tmp2 - } - - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - // double check that the valid case goes through - ABI_CHECK(callContractFunction("f((uint8,bytes1))", u256(0x12), bytes{0x34} + bytes(31,0)), encodeArgs(0x12, bytes{0x34} + bytes(31,0))); - ABI_CHECK(callContractFunction("f((uint8,bytes1))", u256(0x1234), bytes{0x56, 0x78} + bytes(30,0)), encodeArgs()); - ABI_CHECK(callContractFunction("f((uint8,bytes1))", u256(-1), u256(-1)), encodeArgs()); -} - BOOST_AUTO_TEST_CASE(calldata_struct_function_type) { char const* sourceCode = R"( @@ -4518,92 +4076,6 @@ BOOST_AUTO_TEST_CASE(calldata_struct_function_type) ABI_CHECK(callContractFunctionNoEncoding("f((function))", fn_C_h), encodeArgs(23)); } -BOOST_AUTO_TEST_CASE(calldata_array_dynamic_bytes) -{ - char const* sourceCode = R"( - pragma experimental ABIEncoderV2; - contract C { - function f1(bytes[1] calldata a) external returns (uint256, uint256, uint256, uint256) { - return (a[0].length, uint8(a[0][0]), uint8(a[0][1]), uint8(a[0][2])); - } - function f2(bytes[1] calldata a, bytes[1] calldata b) external returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) { - return (a[0].length, uint8(a[0][0]), uint8(a[0][1]), uint8(a[0][2]), b[0].length, uint8(b[0][0]), uint8(b[0][1])); - } - function g1(bytes[2] calldata a) external returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) { - return (a[0].length, uint8(a[0][0]), uint8(a[0][1]), uint8(a[0][2]), a[1].length, uint8(a[1][0]), uint8(a[1][1]), uint8(a[1][2])); - } - function g2(bytes[] calldata a) external returns (uint256[8] memory) { - return [a.length, a[0].length, uint8(a[0][0]), uint8(a[0][1]), a[1].length, uint8(a[1][0]), uint8(a[1][1]), uint8(a[1][2])]; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - bytes bytes010203 = bytes{1,2,3}+bytes(29,0); - bytes bytes040506 = bytes{4,5,6}+bytes(29,0); - bytes bytes0102 = bytes{1,2}+bytes(30,0); - ABI_CHECK( - callContractFunction("f1(bytes[1])", 0x20, 0x20, 3, bytes010203), - encodeArgs(3, 1, 2, 3) - ); - ABI_CHECK( - callContractFunction("f2(bytes[1],bytes[1])", 0x40, 0xA0, 0x20, 3, bytes010203, 0x20, 2, bytes0102), - encodeArgs(3, 1, 2, 3, 2, 1, 2) - ); - ABI_CHECK( - callContractFunction("g1(bytes[2])", 0x20, 0x40, 0x80, 3, bytes010203, 3, bytes040506), - encodeArgs(3, 1, 2, 3, 3, 4, 5, 6) - ); - // same offset for both arrays - ABI_CHECK( - callContractFunction("g1(bytes[2])", 0x20, 0x40, 0x40, 3, bytes010203), - encodeArgs(3, 1, 2, 3, 3, 1, 2, 3) - ); - ABI_CHECK( - callContractFunction("g2(bytes[])", 0x20, 2, 0x40, 0x80, 2, bytes0102, 3, bytes040506), - encodeArgs(2, 2, 1, 2, 3, 4, 5, 6) - ); -} - -BOOST_AUTO_TEST_CASE(calldata_bytes_array_to_memory) -{ - char const* sourceCode = R"( - pragma experimental ABIEncoderV2; - contract C { - function f(bytes[] calldata a) external returns (uint, uint, bytes memory) { - bytes memory m = a[0]; - return (a.length, m.length, m); - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - ABI_CHECK( - callContractFunction("f(bytes[])", 0x20, 1, 0x20, 2, bytes{'a', 'b'} + bytes(30, 0)), - encodeArgs(1, 2, 0x60, 2, bytes{'a','b'} + bytes(30, 0)) - ); - - ABI_CHECK( - callContractFunction("f(bytes[])", 0x20, 1, 0x20, 32, bytes(32, 'x')), - encodeArgs(1, 32, 0x60, 32, bytes(32, 'x')) - ); - bytes x_zero_a = bytes{'x'} + bytes(30, 0) + bytes{'a'}; - bytes a_zero_x = bytes{'a'} + bytes(30, 0) + bytes{'x'}; - bytes a_m_x = bytes{'a'} + bytes(30, 'm') + bytes{'x'}; - ABI_CHECK( - callContractFunction("f(bytes[])", 0x20, 1, 0x20, 32, x_zero_a), - encodeArgs(1, 32, 0x60, 32, x_zero_a) - ); - ABI_CHECK( - callContractFunction("f(bytes[])", 0x20, 1, 0x20, 32, a_zero_x), - encodeArgs(1, 32, 0x60, 32, a_zero_x) - ); - ABI_CHECK( - callContractFunction("f(bytes[])", 0x20, 1, 0x20, 32, a_m_x), - encodeArgs(1, 32, 0x60, 32, a_m_x) - ); -} - BOOST_AUTO_TEST_CASE(calldata_bytes_array_bounds) { char const* sourceCode = R"( @@ -4630,26 +4102,6 @@ BOOST_AUTO_TEST_CASE(calldata_bytes_array_bounds) ); } -BOOST_AUTO_TEST_CASE(calldata_string_array) -{ - char const* sourceCode = R"( - pragma experimental ABIEncoderV2; - contract C { - function f(string[] calldata a) external returns (uint, uint, uint, string memory) { - string memory s1 = a[0]; - bytes memory m1 = bytes(s1); - return (a.length, m1.length, uint8(m1[0]), s1); - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - ABI_CHECK( - callContractFunction("f(string[])", 0x20, 1, 0x20, 2, bytes{'a', 'b'} + bytes(30, 0)), - encodeArgs(1, 2, 'a', 0x80, 2, bytes{'a', 'b'} + bytes(30, 0)) - ); -} - BOOST_AUTO_TEST_CASE(calldata_array_two_dimensional) { vector> data { @@ -4835,25 +4287,6 @@ BOOST_AUTO_TEST_CASE(initialise_string_constant) ABI_CHECK(callContractFunction("short()"), encodeDyn(shortStr)); } -BOOST_AUTO_TEST_CASE(string_bytes_conversion) -{ - char const* sourceCode = R"( - contract Test { - string s; - bytes b; - function f(string memory _s, uint n) public returns (byte) { - b = bytes(_s); - s = string(b); - return bytes(s)[n]; - } - function l() public returns (uint) { return bytes(s).length; } - } - )"; - compileAndRun(sourceCode, 0, "Test"); - ABI_CHECK(callContractFunction("f(string,uint256)", u256(0x40), u256(2), u256(6), string("abcdef")), encodeArgs("c")); - ABI_CHECK(callContractFunction("l()"), encodeArgs(u256(6))); -} - BOOST_AUTO_TEST_CASE(string_as_mapping_key) { char const* sourceCode = R"( @@ -5108,48 +4541,6 @@ BOOST_AUTO_TEST_CASE(library_stray_values) ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(42))); } -BOOST_AUTO_TEST_CASE(strings_in_struct) -{ - char const* sourceCode = R"( - contract buggystruct { - Buggy public bug; - - struct Buggy { - uint first; - uint second; - uint third; - string last; - } - - constructor() public { - bug = Buggy(10, 20, 30, "asdfghjkl"); - } - function getFirst() public returns (uint) - { - return bug.first; - } - function getSecond() public returns (uint) - { - return bug.second; - } - function getThird() public returns (uint) - { - return bug.third; - } - function getLast() public returns (string memory) - { - return bug.last; - } - } - )"; - compileAndRun(sourceCode); - string s = "asdfghjkl"; - ABI_CHECK(callContractFunction("getFirst()"), encodeArgs(u256(10))); - ABI_CHECK(callContractFunction("getSecond()"), encodeArgs(u256(20))); - ABI_CHECK(callContractFunction("getThird()"), encodeArgs(u256(30))); - ABI_CHECK(callContractFunction("getLast()"), encodeDyn(s)); -} - BOOST_AUTO_TEST_CASE(internal_types_in_library) { char const* sourceCode = R"( @@ -5641,27 +5032,6 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) } } -BOOST_AUTO_TEST_CASE(string_allocation_bug) -{ - char const* sourceCode = R"( - contract Sample - { - struct s { uint16 x; uint16 y; string a; string b;} - s[2] public p; - constructor() public { - s memory m; - m.x = 0xbbbb; - m.y = 0xcccc; - m.a = "hello"; - m.b = "world"; - p[0] = m; - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("p(uint256)", 0), encodeArgs(u256(0xbbbb), u256(0xcccc), u256(0x80), u256(0xc0), u256(5), string("hello"), u256(5), string("world"))); -} - BOOST_AUTO_TEST_CASE(using_for_function_on_int) { char const* sourceCode = R"( @@ -5815,27 +5185,6 @@ BOOST_AUTO_TEST_CASE(inline_long_string_return) ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong)); } -BOOST_AUTO_TEST_CASE(fixed_bytes_index_access) -{ - char const* sourceCode = R"( - contract C { - bytes16[] public data; - function f(bytes32 x) public returns (byte) { - return x[2]; - } - function g(bytes32 x) public returns (uint) { - data = [x[0], x[1], x[2]]; - data[0] = "12345"; - return uint(uint8(data[0][4])); - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f(bytes32)", "789"), encodeArgs("9")); - ABI_CHECK(callContractFunction("g(bytes32)", "789"), encodeArgs(u256(int('5')))); - ABI_CHECK(callContractFunction("data(uint256)", u256(1)), encodeArgs("8")); -} - BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) { // Test for a bug where higher order bits cleanup was not done for array index access. @@ -5852,47 +5201,6 @@ BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) BOOST_CHECK(callContractFunction("f(uint256)", u256(0x101)).size() == 256 * 32); } -BOOST_AUTO_TEST_CASE(cleanup_bytes_types) -{ - // Checks that bytesXX types are properly cleaned before they are compared. - char const* sourceCode = R"( - contract C { - function f(bytes2 a, uint16 x) public returns (uint) { - if (a != "ab") return 1; - if (x != 0x0102) return 2; - if (bytes3(uint24(x)) != 0x000102) return 3; - return 0; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - // We input longer data on purpose. - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(bytes2,uint16)", string("abc"), u256(0x040102)), v2 ? encodeArgs() : encodeArgs(0)); -} -BOOST_AUTO_TEST_CASE(cleanup_address_types) -{ - // Checks that address types are properly cleaned before they are compared. - char const* sourceCode = R"( - contract C { - function f(address a) public returns (uint) { - if (a != 0x1234567890123456789012345678901234567890) return 1; - return 0; - } - function g(address payable a) public returns (uint) { - if (a != 0x1234567890123456789012345678901234567890) return 1; - return 0; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - // We input longer data on purpose. - ABI_CHECK(callContractFunction("f(address)", u256("0xFFFF1234567890123456789012345678901234567890")), v2 ? encodeArgs() : encodeArgs(0)); - ABI_CHECK(callContractFunction("g(address)", u256("0xFFFF1234567890123456789012345678901234567890")), v2 ? encodeArgs() : encodeArgs(0)); -} - BOOST_AUTO_TEST_CASE(failed_create) { char const* sourceCode = R"( @@ -6172,113 +5480,6 @@ BOOST_AUTO_TEST_CASE(return_external_function_type) // TODO: store bound internal library functions -BOOST_AUTO_TEST_CASE(shift_right_garbled) -{ - char const* sourceCode = R"( - contract C { - function f(uint8 a, uint8 b) public returns (uint) { - assembly { - a := 0xffffffff - } - // Higher bits should be cleared before the shift - return a >> b; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(uint8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(0xf))); - ABI_CHECK(callContractFunction("f(uint8,uint8)", u256(0x0), u256(0x1004)), v2 ? encodeArgs() : encodeArgs(u256(0xf))); -} - -BOOST_AUTO_TEST_CASE(shift_right_garbled_signed) -{ - char const* sourceCode = R"( - contract C { - function f(int8 a, uint8 b) public returns (int) { - assembly { - a := 0xfffffff0 - } - // Higher bits should be signextended before the shift - return a >> b; - } - function g(int8 a, uint8 b) public returns (int) { - assembly { - a := 0xf0 - } - // Higher bits should be signextended before the shift - return a >> b; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); - ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); - ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); - ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1003)), v2 ? encodeArgs() : encodeArgs(u256(-2))); - ABI_CHECK(callContractFunction("f(int8,uint8)", u256(0x0), u256(0x1004)), v2 ? encodeArgs() : encodeArgs(u256(-1))); - ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(3)), encodeArgs(u256(-2))); - ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(4)), encodeArgs(u256(-1))); - ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0xFF)), encodeArgs(u256(-1))); - ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1003)), v2 ? encodeArgs() : encodeArgs(u256(-2))); - ABI_CHECK(callContractFunction("g(int8,uint8)", u256(0x0), u256(0x1004)), v2 ? encodeArgs() : encodeArgs(u256(-1))); -} - -BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int8) -{ - char const* sourceCode = R"( - contract C { - function f(int8 a, int8 b) public returns (int8) { - return a >> b; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(0)), v2 ? encodeArgs() : encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(1)), v2 ? encodeArgs() : encodeArgs(u256(-52))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(2)), v2 ? encodeArgs() : encodeArgs(u256(-26))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(4)), v2 ? encodeArgs() : encodeArgs(u256(-7))); - ABI_CHECK(callContractFunction("f(int8,int8)", u256(0x99u), u256(8)), v2 ? encodeArgs() : encodeArgs(u256(-1))); -} - -BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int16) -{ - char const* sourceCode = R"( - contract C { - function f(int16 a, int16 b) public returns (int16) { - return a >> b; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(0)), v2 ? encodeArgs() : encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(1)), v2 ? encodeArgs() : encodeArgs(u256(-52))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(2)), v2 ? encodeArgs() : encodeArgs(u256(-26))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(4)), v2 ? encodeArgs() : encodeArgs(u256(-7))); - ABI_CHECK(callContractFunction("f(int16,int16)", u256(0xFF99u), u256(8)), v2 ? encodeArgs() : encodeArgs(u256(-1))); -} - -BOOST_AUTO_TEST_CASE(shift_right_negative_lvalue_signextend_int32) -{ - char const* sourceCode = R"( - contract C { - function f(int32 a, int32 b) public returns (int32) { - return a >> b; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2; - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(0)), v2 ? encodeArgs() : encodeArgs(u256(-103))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(1)), v2 ? encodeArgs() : encodeArgs(u256(-52))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(2)), v2 ? encodeArgs() : encodeArgs(u256(-26))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(4)), v2 ? encodeArgs() : encodeArgs(u256(-7))); - ABI_CHECK(callContractFunction("f(int32,int32)", u256(0xFFFFFF99u), u256(8)), v2 ? encodeArgs() : encodeArgs(u256(-1))); -} - BOOST_AUTO_TEST_CASE(shift_bytes) { char const* sourceCode = R"( @@ -6653,33 +5854,6 @@ BOOST_AUTO_TEST_CASE(interface_contract) ABI_CHECK(callContractFunction("f(address)", recipient), encodeArgs(true)); } -BOOST_AUTO_TEST_CASE(multi_modifiers) -{ - // This triggered a bug in some version because the variable in the modifier was not - // unregistered correctly. - char const* sourceCode = R"( - contract C { - uint public x; - modifier m1 { - address a1 = msg.sender; - x++; - _; - } - function f1() m1() public { - x += 7; - } - function f2() m1() public { - x += 3; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f1()"), bytes()); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(8))); - ABI_CHECK(callContractFunction("f2()"), bytes()); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(12))); -} - BOOST_AUTO_TEST_CASE(bare_call_invalid_address) { char const* sourceCode = R"YY( @@ -6840,110 +6014,6 @@ BOOST_AUTO_TEST_CASE(bare_call_return_data) } } -BOOST_AUTO_TEST_CASE(delegatecall_return_value) -{ - if (solidity::test::CommonOptions::get().evmVersion().supportsReturndata()) - { - char const* sourceCode = R"DELIMITER( - contract C { - uint value; - function set(uint _value) external { - value = _value; - } - function get() external view returns (uint) { - return value; - } - function get_delegated() external returns (bool, bytes memory) { - return address(this).delegatecall(abi.encodeWithSignature("get()")); - } - function assert0() external view { - assert(value == 0); - } - function assert0_delegated() external returns (bool, bytes memory) { - return address(this).delegatecall(abi.encodeWithSignature("assert0()")); - } - } - )DELIMITER"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(1), 0x40, 0x00)); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 0x00)); - ABI_CHECK(callContractFunction("set(uint256)", u256(1)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0), 0x40, 0x00)); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 1)); - ABI_CHECK(callContractFunction("set(uint256)", u256(42)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0), 0x40, 0x00)); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1), 0x40, 0x20, 42)); - } - else - { - char const* sourceCode = R"DELIMITER( - contract C { - uint value; - function set(uint _value) external { - value = _value; - } - function get() external view returns (uint) { - return value; - } - function get_delegated() external returns (bool) { - (bool success,) = address(this).delegatecall(abi.encodeWithSignature("get()")); - return success; - } - function assert0() external view { - assert(value == 0); - } - function assert0_delegated() external returns (bool) { - (bool success,) = address(this).delegatecall(abi.encodeWithSignature("assert0()")); - return success; - } - } - )DELIMITER"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("set(uint256)", u256(1)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunction("set(uint256)", u256(42)), encodeArgs()); - ABI_CHECK(callContractFunction("get()"), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("assert0_delegated()"), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_delegated()"), encodeArgs(u256(1))); - } -} - -BOOST_AUTO_TEST_CASE(function_types_sig) -{ - char const* sourceCode = R"( - contract C { - uint public x; - function f() public pure returns (bytes4) { - return this.f.selector; - } - function g() public returns (bytes4) { - function () pure external returns (bytes4) fun = this.f; - return fun.selector; - } - function h() public returns (bytes4) { - function () pure external returns (bytes4) fun = this.f; - return fun.selector; - } - function i() public pure returns (bytes4) { - return this.x.selector; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f()"), encodeArgs(asString(FixedHash<4>(util::keccak256("f()")).asBytes()))); - ABI_CHECK(callContractFunction("g()"), encodeArgs(asString(FixedHash<4>(util::keccak256("f()")).asBytes()))); - ABI_CHECK(callContractFunction("h()"), encodeArgs(asString(FixedHash<4>(util::keccak256("f()")).asBytes()))); - ABI_CHECK(callContractFunction("i()"), encodeArgs(asString(FixedHash<4>(util::keccak256("x()")).asBytes()))); -} - BOOST_AUTO_TEST_CASE(abi_encodePacked) { char const* sourceCode = R"( @@ -7488,344 +6558,6 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signaturev2) ABI_CHECK(callContractFunction("f4()"), expectation); } -BOOST_AUTO_TEST_CASE(abi_encode_empty_string) -{ - char const* sourceCode = R"( - // Tests that this will not end up using a "bytes0" type - // (which would assert) - contract C { - function f() public pure returns (bytes memory, bytes memory) { - return (abi.encode(""), abi.encodePacked("")); - } - } - )"; - - compileAndRun(sourceCode, 0, "C"); - if (!solidity::test::CommonOptions::get().useABIEncoderV2) - { - // ABI Encoder V2 has slightly different padding, tested below. - ABI_CHECK(callContractFunction("f()"), encodeArgs( - 0x40, 0xc0, - 0x60, 0x20, 0x00, 0x00, - 0x00 - )); - } -} - -BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure) -{ - char const* sourceCode = R"( - contract C { - uint x; - function f() public returns (uint) { - x = 3; - return 1; - } - } - interface CView { - function f() view external returns (uint); - } - interface CPure { - function f() pure external returns (uint); - } - contract D { - function f() public returns (uint) { - return (new C()).f(); - } - function fview() public returns (uint) { - return (CView(address(new C()))).f(); - } - function fpure() public returns (uint) { - return (CPure(address(new C()))).f(); - } - } - )"; - compileAndRun(sourceCode, 0, "D"); - // This should work (called via CALL) - ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); - if (solidity::test::CommonOptions::get().evmVersion().hasStaticCall()) - { - // These should throw (called via STATICCALL) - ABI_CHECK(callContractFunction("fview()"), encodeArgs()); - ABI_CHECK(callContractFunction("fpure()"), encodeArgs()); - } - else - { - ABI_CHECK(callContractFunction("fview()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("fpure()"), encodeArgs(1)); - } -} - -BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople) -{ - if (!solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting()) - return; - char const* sourceCode = R"( - contract C { - function shl(uint a, uint b) public returns (uint c) { - assembly { - c := shl(b, a) - } - } - function shr(uint a, uint b) public returns (uint c) { - assembly { - c := shr(b, a) - } - } - function sar(uint a, uint b) public returns (uint c) { - assembly { - c := sar(b, a) - } - } - } - )"; - ALSO_VIA_YUL( - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(4))); - BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"))); - BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(255)) == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(255)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - ) -} - -BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople) -{ - if (!solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting()) - return; - char const* sourceCode = R"( - contract C { - function shl_1() public returns (bool) { - uint c; - assembly { - c := shl(2, 1) - } - assert(c == 4); - return true; - } - function shl_2() public returns (bool) { - uint c; - assembly { - c := shl(1, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) - } - assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe); - return true; - } - function shl_3() public returns (bool) { - uint c; - assembly { - c := shl(256, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) - } - assert(c == 0); - return true; - } - function shr_1() public returns (bool) { - uint c; - assembly { - c := shr(1, 3) - } - assert(c == 1); - return true; - } - function shr_2() public returns (bool) { - uint c; - assembly { - c := shr(1, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) - } - assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); - return true; - } - function shr_3() public returns (bool) { - uint c; - assembly { - c := shr(256, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) - } - assert(c == 0); - return true; - } - } - )"; - ALSO_VIA_YUL( - compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("shl_1()") == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shl_2()") == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shl_3()") == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shr_1()") == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shr_2()") == encodeArgs(u256(1))); - BOOST_CHECK(callContractFunction("shr_3()") == encodeArgs(u256(1))); - ) -} - -BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople_combined) -{ - if (!solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting()) - return; - char const* sourceCode = R"( - contract C { - function shl_zero(uint a) public returns (uint c) { - assembly { - c := shl(0, a) - } - } - function shr_zero(uint a) public returns (uint c) { - assembly { - c := shr(0, a) - } - } - function sar_zero(uint a) public returns (uint c) { - assembly { - c := sar(0, a) - } - } - - function shl_large(uint a) public returns (uint c) { - assembly { - c := shl(0x110, a) - } - } - function shr_large(uint a) public returns (uint c) { - assembly { - c := shr(0x110, a) - } - } - function sar_large(uint a) public returns (uint c) { - assembly { - c := sar(0x110, a) - } - } - - function shl_combined(uint a) public returns (uint c) { - assembly { - c := shl(4, shl(12, a)) - } - } - function shr_combined(uint a) public returns (uint c) { - assembly { - c := shr(4, shr(12, a)) - } - } - function sar_combined(uint a) public returns (uint c) { - assembly { - c := sar(4, sar(12, a)) - } - } - - function shl_combined_large(uint a) public returns (uint c) { - assembly { - c := shl(0xd0, shl(0x40, a)) - } - } - function shl_combined_overflow(uint a) public returns (uint c) { - assembly { - c := shl(0x01, shl(not(0x00), a)) - } - } - function shr_combined_large(uint a) public returns (uint c) { - assembly { - c := shr(0xd0, shr(0x40, a)) - } - } - function shr_combined_overflow(uint a) public returns (uint c) { - assembly { - c := shr(0x01, shr(not(0x00), a)) - } - } - function sar_combined_large(uint a) public returns (uint c) { - assembly { - c := sar(0xd0, sar(0x40, a)) - } - } - } - )"; - ALSO_VIA_YUL( - compileAndRun(sourceCode); - - BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256("0xffff")) == encodeArgs(u256("0xffff"))); - BOOST_CHECK(callContractFunction("shl_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("shr_zero(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("sar_zero(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_zero(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - - BOOST_CHECK(callContractFunction("shl_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_large(uint256)", u256("0xffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_large(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - - BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256("0xffff")) == encodeArgs(u256("0xffff0000"))); - BOOST_CHECK(callContractFunction("shl_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000"))); - BOOST_CHECK(callContractFunction("shr_combined(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0x00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - BOOST_CHECK(callContractFunction("sar_combined(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - - BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256("0xffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shl_combined_overflow(uint256)", u256(2)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_combined_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("shr_combined_overflow(uint256)", u256(2)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256(0)) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256(0))); - BOOST_CHECK(callContractFunction("sar_combined_large(uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - ) -} - -BOOST_AUTO_TEST_CASE(abi_decode_simple) -{ - char const* sourceCode = R"( - contract C { - function f(bytes memory data) public pure returns (uint, bytes memory) { - return abi.decode(data, (uint, bytes)); - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), encodeArgs(33, 0x40, 7, "abcdefg")); -} - -BOOST_AUTO_TEST_CASE(abi_decode_simple_storage) -{ - char const* sourceCode = R"( - contract C { - bytes data; - function f(bytes memory _data) public returns (uint, bytes memory) { - data = _data; - return abi.decode(data, (uint, bytes)); - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), encodeArgs(33, 0x40, 7, "abcdefg")); -} - -BOOST_AUTO_TEST_CASE(abi_decode_calldata) -{ - char const* sourceCode = R"( - contract C { - function f(bytes calldata data) external pure returns (uint, bytes memory r) { - return abi.decode(data, (uint, bytes)); - } - } - )"; - compileAndRun(sourceCode); - ABI_CHECK(callContractFunction("f(bytes)", 0x20, 0x20 * 4, 33, 0x40, 7, "abcdefg"), encodeArgs(33, 0x40, 7, "abcdefg")); -} - BOOST_AUTO_TEST_CASE(code_access) { char const* sourceCode = R"( diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol b/test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol new file mode 100644 index 000000000..6b6e55e02 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol @@ -0,0 +1,11 @@ +contract C { + function f(bytes calldata data) + external + pure + returns (uint256, bytes memory r) + { + return abi.decode(data, (uint256, bytes)); + } +} +// ---- +// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_simple.sol b/test/libsolidity/semanticTests/extracted/abi_decode_simple.sol new file mode 100644 index 000000000..9ae6602f3 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/abi_decode_simple.sol @@ -0,0 +1,7 @@ +contract C { + function f(bytes memory data) public pure returns (uint256, bytes memory) { + return abi.decode(data, (uint256, bytes)); + } +} +// ---- +// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol b/test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol new file mode 100644 index 000000000..af37480a3 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol @@ -0,0 +1,10 @@ +contract C { + bytes data; + + function f(bytes memory _data) public returns (uint256, bytes memory) { + data = _data; + return abi.decode(data, (uint256, bytes)); + } +} +// ---- +// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" diff --git a/test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol b/test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol new file mode 100644 index 000000000..6ca284908 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol @@ -0,0 +1,11 @@ +// Tests that this will not end up using a "bytes0" type +// (which would assert) +contract C { + function f() public pure returns (bytes memory, bytes memory) { + return (abi.encode(""), abi.encodePacked("")); + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f() -> 0x40, 0xc0, 0x60, 0x20, 0x0, 0x0, 0x0 diff --git a/test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol b/test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol new file mode 100644 index 000000000..9cec148c7 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol @@ -0,0 +1,18 @@ +contract Test { + uint24[3][] public data; + + function set(uint24[3][] memory _data) public returns (uint256) { + data = _data; + return data.length; + } + + function get() public returns (uint24[3][] memory) { + return data; + } +} +// ---- +// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06 +// data(uint256,uint256): 0x02, 0x02 -> 0x09 +// data(uint256,uint256): 0x05, 0x01 -> 0x11 +// data(uint256,uint256): 0x06, 0x00 -> FAILURE +// get() -> 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 diff --git a/test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol b/test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol new file mode 100644 index 000000000..d21bcc53f --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol @@ -0,0 +1,13 @@ +contract Test { + function set(uint24[3][] memory _data, uint256 a, uint256 b) + public + returns (uint256 l, uint256 e) + { + l = _data.length; + e = _data[a][b]; + } +} +// ==== +// compileViaYul: also +// ---- +// set(uint24[3][],uint256,uint256): 0x60, 0x03, 0x02, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06, 0x0c diff --git a/test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol b/test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol new file mode 100644 index 000000000..2fc479d0e --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol @@ -0,0 +1,9 @@ +contract C { + bytes32 constant x = keccak256("abc"); + + function f() public returns (bytes32) { + return x; + } +} +// ---- +// f() -> 0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol new file mode 100644 index 000000000..c6ada8c6a --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol @@ -0,0 +1,34 @@ +contract C { + function shl(uint256 a, uint256 b) public returns (uint256 c) { + assembly { + c := shl(b, a) + } + } + + function shr(uint256 a, uint256 b) public returns (uint256 c) { + assembly { + c := shr(b, a) + } + } + + function sar(uint256 a, uint256 b) public returns (uint256 c) { + assembly { + c := sar(b, a) + } + } +} +// ==== +// EVMVersion: >=constantinople +// compileViaYul: also +// ---- +// shl(uint256,uint256): 0x01, 0x02 -> 0x04 +// shl(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// shl(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0x00 +// shr(uint256,uint256): 0x03, 0x01 -> 0x01 +// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xff -> 0x01 +// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0x00 +// sar(uint256,uint256): 0x03, 0x01 -> 0x01 +// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol new file mode 100644 index 000000000..6cacbe300 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol @@ -0,0 +1,122 @@ +contract C { + function shl_zero(uint256 a) public returns (uint256 c) { + assembly { + c := shl(0, a) + } + } + + function shr_zero(uint256 a) public returns (uint256 c) { + assembly { + c := shr(0, a) + } + } + + function sar_zero(uint256 a) public returns (uint256 c) { + assembly { + c := sar(0, a) + } + } + + function shl_large(uint256 a) public returns (uint256 c) { + assembly { + c := shl(0x110, a) + } + } + + function shr_large(uint256 a) public returns (uint256 c) { + assembly { + c := shr(0x110, a) + } + } + + function sar_large(uint256 a) public returns (uint256 c) { + assembly { + c := sar(0x110, a) + } + } + + function shl_combined(uint256 a) public returns (uint256 c) { + assembly { + c := shl(4, shl(12, a)) + } + } + + function shr_combined(uint256 a) public returns (uint256 c) { + assembly { + c := shr(4, shr(12, a)) + } + } + + function sar_combined(uint256 a) public returns (uint256 c) { + assembly { + c := sar(4, sar(12, a)) + } + } + + function shl_combined_large(uint256 a) public returns (uint256 c) { + assembly { + c := shl(0xd0, shl(0x40, a)) + } + } + + function shl_combined_overflow(uint256 a) public returns (uint256 c) { + assembly { + c := shl(0x01, shl(not(0x00), a)) + } + } + + function shr_combined_large(uint256 a) public returns (uint256 c) { + assembly { + c := shr(0xd0, shr(0x40, a)) + } + } + + function shr_combined_overflow(uint256 a) public returns (uint256 c) { + assembly { + c := shr(0x01, shr(not(0x00), a)) + } + } + + function sar_combined_large(uint256 a) public returns (uint256 c) { + assembly { + c := sar(0xd0, sar(0x40, a)) + } + } +} +// ==== +// EVMVersion: >=constantinople +// compileViaYul: also +// ---- +// shl_zero(uint256): 0x00 -> 0x00 +// shl_zero(uint256): 0xffff -> 0xffff +// shl_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// shr_zero(uint256): 0x00 -> 0x00 +// shr_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// sar_zero(uint256): 0x00 -> 0x00 +// sar_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// shl_large(uint256): 0x00 -> 0x00 +// shl_large(uint256): 0xffff -> 0x00 +// shl_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// shr_large(uint256): 0x00 -> 0x00 +// shr_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// sar_large(uint256): 0x00 -> 0x00 +// sar_large(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// sar_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// shl_combined(uint256): 0x00 -> 0x00 +// shl_combined(uint256): 0xffff -> 0xffff0000 +// shl_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000 +// shr_combined(uint256): 0x00 -> 0x00 +// shr_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// sar_combined(uint256): 0x00 -> 0x00 +// sar_combined(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// sar_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// shl_combined_large(uint256): 0x00 -> 0x00 +// shl_combined_large(uint256): 0xffff -> 0x00 +// shl_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// shl_combined_overflow(uint256): 0x02 -> 0x00 +// shr_combined_large(uint256): 0x00 -> 0x00 +// shr_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// shr_combined_overflow(uint256): 0x02 -> 0x00 +// sar_combined_large(uint256): 0x00 -> 0x00 +// sar_combined_large(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00 +// sar_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol new file mode 100644 index 000000000..bbc5ddaa4 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol @@ -0,0 +1,83 @@ +contract C { + function shl_1() public returns (bool) { + uint256 c; + assembly { + c := shl(2, 1) + } + assert(c == 4); + return true; + } + + function shl_2() public returns (bool) { + uint256 c; + assembly { + c := shl( + 1, + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) + } + assert( + c == + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe + ); + return true; + } + + function shl_3() public returns (bool) { + uint256 c; + assembly { + c := shl( + 256, + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) + } + assert(c == 0); + return true; + } + + function shr_1() public returns (bool) { + uint256 c; + assembly { + c := shr(1, 3) + } + assert(c == 1); + return true; + } + + function shr_2() public returns (bool) { + uint256 c; + assembly { + c := shr( + 1, + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) + } + assert( + c == + 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ); + return true; + } + + function shr_3() public returns (bool) { + uint256 c; + assembly { + c := shr( + 256, + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) + } + assert(c == 0); + return true; + } +} +// ==== +// EVMVersion: >=constantinople +// compileViaYul: also +// ---- +// shl_1() -> 0x01 +// shl_2() -> 0x01 +// shl_3() -> 0x01 +// shr_1() -> 0x01 +// shr_2() -> 0x01 +// shr_3() -> 0x01 diff --git a/test/libsolidity/semanticTests/extracted/bool_conversion.sol b/test/libsolidity/semanticTests/extracted/bool_conversion.sol new file mode 100644 index 000000000..20f594764 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bool_conversion.sol @@ -0,0 +1,23 @@ +contract C { + function f(bool _b) public returns (uint256) { + if (_b) return 1; + else return 0; + } + + function g(bool _in) public returns (bool _out) { + _out = _in; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(bool): 0x0 -> 0x0 +// f(bool): 0x1 -> 0x1 +// f(bool): 0x2 -> 0x1 +// f(bool): 0x3 -> 0x1 +// f(bool): 0xff -> 0x1 +// g(bool): 0x0 -> 0x0 +// g(bool): 0x1 -> 0x1 +// g(bool): 0x2 -> 0x1 +// g(bool): 0x3 -> 0x1 +// g(bool): 0xff -> 0x1 diff --git a/test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol b/test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol new file mode 100644 index 000000000..a8fd89833 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol @@ -0,0 +1,24 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(bool _b) public returns (uint256) { + if (_b) return 1; + else return 0; + } + + function g(bool _in) public returns (bool _out) { + _out = _in; + } +} +// ---- +// f(bool): 0x0 -> 0x0 +// f(bool): 0x1 -> 0x1 +// f(bool): 0x2 -> FAILURE +// f(bool): 0x3 -> FAILURE +// f(bool): 0xff -> FAILURE +// g(bool): 0x0 -> 0x0 +// g(bool): 0x1 -> 0x1 +// g(bool): 0x2 -> FAILURE +// g(bool): 0x3 -> FAILURE +// g(bool): 0xff -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol b/test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol new file mode 100644 index 000000000..5b7fd7ac3 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol @@ -0,0 +1,13 @@ +contract Test { + function set(bytes memory _data, uint256 i) + public + returns (uint256 l, bytes1 c) + { + l = _data.length; + c = _data[i]; + } +} +// ==== +// compileViaYul: also +// ---- +// set(bytes,uint256): 0x40, 0x03, 0x08, "abcdefgh" -> 0x08, "d" diff --git a/test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol b/test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol new file mode 100644 index 000000000..c2c2fa70a --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol @@ -0,0 +1,74 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f1(bytes[1] calldata a) + external + returns (uint256, uint256, uint256, uint256) + { + return (a[0].length, uint8(a[0][0]), uint8(a[0][1]), uint8(a[0][2])); + } + + function f2(bytes[1] calldata a, bytes[1] calldata b) + external + returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) + { + return ( + a[0].length, + uint8(a[0][0]), + uint8(a[0][1]), + uint8(a[0][2]), + b[0].length, + uint8(b[0][0]), + uint8(b[0][1]) + ); + } + + function g1(bytes[2] calldata a) + external + returns ( + uint256, + uint256, + uint256, + uint256, + uint256, + uint256, + uint256, + uint256 + ) + { + return ( + a[0].length, + uint8(a[0][0]), + uint8(a[0][1]), + uint8(a[0][2]), + a[1].length, + uint8(a[1][0]), + uint8(a[1][1]), + uint8(a[1][2]) + ); + } + + function g2(bytes[] calldata a) external returns (uint256[8] memory) { + return [ + a.length, + a[0].length, + uint8(a[0][0]), + uint8(a[0][1]), + a[1].length, + uint8(a[1][0]), + uint8(a[1][1]), + uint8(a[1][2]) + ]; + } +} + +// found expectation comments: +// same offset for both arrays @ ABI_CHECK( + +// ---- +// f1(bytes[1]): 0x20, 0x20, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3 +// f2(bytes[1],bytes[1]): 0x40, 0xa0, 0x20, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000", 0x20, 0x2, hex"0102000000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x2, 0x1, 0x2 +// g1(bytes[2]): 0x20, 0x40, 0x80, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000", 0x3, hex"0405060000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x3, 0x4, 0x5, 0x6 +// g1(bytes[2]): 0x20, 0x40, 0x40, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x3, 0x1, 0x2, 0x3 +// g2(bytes[]): 0x20, 0x2, 0x40, 0x80, 0x2, hex"0102000000000000000000000000000000000000000000000000000000000000", 0x3, hex"0405060000000000000000000000000000000000000000000000000000000000" -> 0x2, 0x2, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 diff --git a/test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol b/test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol new file mode 100644 index 000000000..04b2ed15d --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol @@ -0,0 +1,18 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(bytes[] calldata a) + external + returns (uint256, uint256, bytes memory) + { + bytes memory m = a[0]; + return (a.length, m.length, m); + } +} +// ---- +// f(bytes[]): 0x20, 0x1, 0x20, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000" -> 0x1, 0x2, 0x60, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000" +// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"7878787878787878787878787878787878787878787878787878787878787878" -> 0x1, 0x20, 0x60, 0x20, hex"7878787878787878787878787878787878787878787878787878787878787878" +// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"7800000000000000000000000000000000000000000000000000000000000061" -> 0x1, 0x20, 0x60, 0x20, hex"7800000000000000000000000000000000000000000000000000000000000061" +// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"6100000000000000000000000000000000000000000000000000000000000078" -> 0x1, 0x20, 0x60, 0x20, hex"6100000000000000000000000000000000000000000000000000000000000078" +// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"616d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d78" -> 0x1, 0x20, 0x60, 0x20, hex"616d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d78" diff --git a/test/libsolidity/semanticTests/extracted/calldata_string_array.sol b/test/libsolidity/semanticTests/extracted/calldata_string_array.sol new file mode 100644 index 000000000..ae7d1e2ef --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/calldata_string_array.sol @@ -0,0 +1,15 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(string[] calldata a) + external + returns (uint256, uint256, uint256, string memory) + { + string memory s1 = a[0]; + bytes memory m1 = bytes(s1); + return (a.length, m1.length, uint8(m1[0]), s1); + } +} +// ---- +// f(string[]): 0x20, 0x1, 0x20, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000" -> 1, 2, 97, 0x80, 2, "ab" diff --git a/test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol b/test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol new file mode 100644 index 000000000..dbf6e4440 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol @@ -0,0 +1,22 @@ +pragma experimental ABIEncoderV2; + + +contract C { + struct S { + uint8 a; + bytes1 b; + } + + function f(S calldata s) external pure returns (uint256 a, bytes32 b) { + uint8 tmp1 = s.a; + bytes1 tmp2 = s.b; + assembly { + a := tmp1 + b := tmp2 + } + } +} +// ---- +// f((uint8,bytes1)): 0x12, hex"3400000000000000000000000000000000000000000000000000000000000000" -> 0x12, hex"3400000000000000000000000000000000000000000000000000000000000000" # double check that the valid case goes through # +// f((uint8,bytes1)): 0x1234, hex"5678000000000000000000000000000000000000000000000000000000000000" -> FAILURE +// f((uint8,bytes1)): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/cleanup_address_types.sol b/test/libsolidity/semanticTests/extracted/cleanup_address_types.sol new file mode 100644 index 000000000..c94cfc776 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/cleanup_address_types.sol @@ -0,0 +1,17 @@ +// Checks that address types are properly cleaned before they are compared. +contract C { + function f(address a) public returns (uint256) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + + function g(address payable a) public returns (uint256) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(address): 0xffff1234567890123456789012345678901234567890 -> 0x0 # We input longer data on purpose.# +// g(address): 0xffff1234567890123456789012345678901234567890 -> 0x0 diff --git a/test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol b/test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol new file mode 100644 index 000000000..beff156f7 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol @@ -0,0 +1,18 @@ +pragma experimental ABIEncoderV2; + + +// Checks that address types are properly cleaned before they are compared. +contract C { + function f(address a) public returns (uint256) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + + function g(address payable a) public returns (uint256) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } +} +// ---- +// f(address): 0xffff1234567890123456789012345678901234567890 -> FAILURE # We input longer data on purpose.# +// g(address): 0xffff1234567890123456789012345678901234567890 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol b/test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol new file mode 100644 index 000000000..32b90748e --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol @@ -0,0 +1,13 @@ +// Checks that bytesXX types are properly cleaned before they are compared. +contract C { + function f(bytes2 a, uint16 x) public returns (uint256) { + if (a != "ab") return 1; + if (x != 0x0102) return 2; + if (bytes3(uint24(x)) != 0x000102) return 3; + return 0; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(bytes2,uint16): "abc", 0x40102 -> 0x0 # We input longer data on purpose. # diff --git a/test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol b/test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol new file mode 100644 index 000000000..5adc97378 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol @@ -0,0 +1,14 @@ +pragma experimental ABIEncoderV2; + + +// Checks that bytesXX types are properly cleaned before they are compared. +contract C { + function f(bytes2 a, uint16 x) public returns (uint256) { + if (a != "ab") return 1; + if (x != 0x0102) return 2; + if (bytes3(uint24(x)) != 0x000102) return 3; + return 0; + } +} +// ---- +// f(bytes2,uint16): "abc", 0x40102 -> FAILURE # We input longer data on purpose. # diff --git a/test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol b/test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol new file mode 100644 index 000000000..ffa22b8a2 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol @@ -0,0 +1,37 @@ +contract C { + uint256 value; + + function set(uint256 _value) external { + value = _value; + } + + function get() external view returns (uint256) { + return value; + } + + function get_delegated() external returns (bool, bytes memory) { + return address(this).delegatecall(abi.encodeWithSignature("get()")); + } + + function assert0() external view { + assert(value == 0); + } + + function assert0_delegated() external returns (bool, bytes memory) { + return address(this).delegatecall(abi.encodeWithSignature("assert0()")); + } +} +// ==== +// EVMVersion: >=byzantium +// ---- +// get() -> 0x00 +// assert0_delegated() -> 0x01, 0x40, 0x0 +// get_delegated() -> 0x01, 0x40, 0x20, 0x0 +// set(uint256): 0x01 -> +// get() -> 0x01 +// assert0_delegated() -> 0x00, 0x40, 0x0 +// get_delegated() -> 0x01, 0x40, 0x20, 0x1 +// set(uint256): 0x2a -> +// get() -> 0x2a +// assert0_delegated() -> 0x00, 0x40, 0x0 +// get_delegated() -> 0x01, 0x40, 0x20, 0x2a diff --git a/test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol b/test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol new file mode 100644 index 000000000..498449d17 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol @@ -0,0 +1,39 @@ +contract C { + uint256 value; + + function set(uint256 _value) external { + value = _value; + } + + function get() external view returns (uint256) { + return value; + } + + function get_delegated() external returns (bool) { + (bool success,) = address(this).delegatecall(abi.encodeWithSignature("get()")); + return success; + } + + function assert0() external view { + assert(value == 0); + } + + function assert0_delegated() external returns (bool) { + (bool success,) = address(this).delegatecall(abi.encodeWithSignature("assert0()")); + return success; + } +} +// ==== +// EVMVersion: 0x00 +// assert0_delegated() -> true +// get_delegated() -> true +// set(uint256): 0x01 -> +// get() -> 0x01 +// assert0_delegated() -> false +// get_delegated() -> true +// set(uint256): 0x2a -> +// get() -> 0x2a +// assert0_delegated() -> false +// get_delegated() -> true diff --git a/test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol b/test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol new file mode 100644 index 000000000..b65a3d254 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol @@ -0,0 +1,45 @@ +contract c { + struct Data { + uint256 x; + uint256 y; + } + Data[2**10] data; + uint256[2**10 + 3] ids; + + function setIDStatic(uint256 id) public { + ids[2] = id; + } + + function setID(uint256 index, uint256 id) public { + ids[index] = id; + } + + function setData(uint256 index, uint256 x, uint256 y) public { + data[index].x = x; + data[index].y = y; + } + + function getID(uint256 index) public returns (uint256) { + return ids[index]; + } + + function getData(uint256 index) public returns (uint256 x, uint256 y) { + x = data[index].x; + y = data[index].y; + } + + function getLengths() public returns (uint256 l1, uint256 l2) { + l1 = data.length; + l2 = ids.length; + } +} +// ---- +// setIDStatic(uint256): 0xb -> +// getID(uint256): 0x2 -> 0xb +// setID(uint256,uint256): 0x7, 0x8 -> +// getID(uint256): 0x7 -> 0x8 +// setData(uint256,uint256,uint256): 0x7, 0x8, 0x9 -> +// setData(uint256,uint256,uint256): 0x8, 0xa, 0xb -> +// getData(uint256): 0x7 -> 0x8, 0x9 +// getData(uint256): 0x8 -> 0xa, 0xb +// getLengths() -> 0x400, 0x403 diff --git a/test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol b/test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol new file mode 100644 index 000000000..9ab74eaf3 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol @@ -0,0 +1,17 @@ +contract C { + bytes16[] public data; + + function f(bytes32 x) public returns (bytes1) { + return x[2]; + } + + function g(bytes32 x) public returns (uint256) { + data = [x[0], x[1], x[2]]; + data[0] = "12345"; + return uint256(uint8(data[0][4])); + } +} +// ---- +// f(bytes32): "789" -> "9" +// g(bytes32): "789" -> 0x35 +// data(uint256): 0x01 -> "8" diff --git a/test/libsolidity/semanticTests/extracted/function_types_sig.sol b/test/libsolidity/semanticTests/extracted/function_types_sig.sol new file mode 100644 index 000000000..2e771032b --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/function_types_sig.sol @@ -0,0 +1,26 @@ +contract C { + uint256 public x; + + function f() public pure returns (bytes4) { + return this.f.selector; + } + + function g() public returns (bytes4) { + function () pure external returns (bytes4) fun = this.f; + return fun.selector; + } + + function h() public returns (bytes4) { + function () pure external returns (bytes4) fun = this.f; + return fun.selector; + } + + function i() public pure returns (bytes4) { + return this.x.selector; + } +} +// ---- +// f() -> 0x26121ff000000000000000000000000000000000000000000000000000000000 +// g() -> 0x26121ff000000000000000000000000000000000000000000000000000000000 +// h() -> 0x26121ff000000000000000000000000000000000000000000000000000000000 +// i() -> 0x0c55699c00000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol b/test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol new file mode 100644 index 000000000..91a26945c --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol @@ -0,0 +1,12 @@ +contract c { + bytes data; + + function foo() public returns (bytes32) { + data.push("x"); + data.push("y"); + data.push("z"); + return keccak256(abi.encodePacked("b", keccak256(data), "a")); + } +} +// ---- +// foo() -> 0xb338eefce206f9f57b83aa738deecd5326dc4b72dd81ee6a7c621a6facb7acdc diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol new file mode 100644 index 000000000..972aee839 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol @@ -0,0 +1,7 @@ +contract c { + function foo(uint256 a, uint256 b, uint256 c) public returns (bytes32 d) { + d = keccak256(abi.encodePacked(a, b, c)); + } +} +// ---- +// foo(uint256,uint256,uint256): 0xa, 0xc, 0xd -> 0xbc740a98aae5923e8f04c9aa798c9ee82f69e319997699f2782c40828db9fd81 diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol new file mode 100644 index 000000000..01397f55f --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol @@ -0,0 +1,7 @@ +contract c { + function foo(uint256 a, uint16 b) public returns (bytes32 d) { + d = keccak256(abi.encodePacked(a, b, uint8(145))); + } +} +// ---- +// foo(uint256,uint16): 0xa, 0xc -> 0x88acd45f75907e7c560318bc1a5249850a0999c4896717b1167d05d116e6dbad diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol new file mode 100644 index 000000000..b157178fb --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol @@ -0,0 +1,12 @@ +contract c { + function foo() public returns (bytes32 d) { + d = keccak256("foo"); + } + + function bar(uint256 a, uint16 b) public returns (bytes32 d) { + d = keccak256(abi.encodePacked(a, b, uint8(145), "foo")); + } +} +// ---- +// foo() -> 0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d +// bar(uint256,uint16): 0xa, 0xc -> 0x6990f36476dc412b1c4baa48e2d9f4aa4bb313f61fda367c8fdbbb2232dc6146 diff --git a/test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol b/test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol new file mode 100644 index 000000000..be824b759 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol @@ -0,0 +1,19 @@ +contract Test { + uint24[3][][4] data; + + function set(uint24[3][][4] memory x) + internal + returns (uint24[3][][4] memory) + { + x[1][2][2] = 1; + x[1][3][2] = 7; + return x; + } + + function f() public returns (uint24[3][] memory) { + while (data[1].length < 4) data[1].push(); + return set(data)[1]; + } +} +// ---- +// f() -> 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07 diff --git a/test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol b/test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol new file mode 100644 index 000000000..7a8a18670 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol @@ -0,0 +1,14 @@ +contract Test { + function set(uint24[3][4] memory x) public { + x[2][2] = 1; + x[3][2] = 7; + } + + function f() public returns (uint24[3][4] memory) { + uint24[3][4] memory data; + set(data); + return data; + } +} +// ---- +// f() -> 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07 diff --git a/test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol b/test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol new file mode 100644 index 000000000..c16705643 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol @@ -0,0 +1,69 @@ +contract Test { + struct S { + uint8 x; + uint16 y; + uint256 z; + } + struct X { + uint8 x; + S s; + uint8[2] a; + } + X m_x; + + function load() + public + returns ( + uint256 a, + uint256 x, + uint256 y, + uint256 z, + uint256 a1, + uint256 a2 + ) + { + m_x.x = 1; + m_x.s.x = 2; + m_x.s.y = 3; + m_x.s.z = 4; + m_x.a[0] = 5; + m_x.a[1] = 6; + X memory d = m_x; + a = d.x; + x = d.s.x; + y = d.s.y; + z = d.s.z; + a1 = d.a[0]; + a2 = d.a[1]; + } + + function store() + public + returns ( + uint256 a, + uint256 x, + uint256 y, + uint256 z, + uint256 a1, + uint256 a2 + ) + { + X memory d; + d.x = 1; + d.s.x = 2; + d.s.y = 3; + d.s.z = 4; + d.a[0] = 5; + d.a[1] = 6; + m_x = d; + a = m_x.x; + x = m_x.s.x; + y = m_x.s.y; + z = m_x.s.z; + a1 = m_x.a[0]; + a2 = m_x.a[1]; + } +} +// ---- +// load() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 +// store() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 diff --git a/test/libsolidity/semanticTests/extracted/msg_sig.sol b/test/libsolidity/semanticTests/extracted/msg_sig.sol new file mode 100644 index 000000000..11b9a5339 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/msg_sig.sol @@ -0,0 +1,9 @@ +contract test { + function foo(uint256 a) public returns (bytes4 value) { + return msg.sig; + } +} +// ==== +// compileViaYul: also +// ---- +// foo(uint256): 0x0 -> 0x2fbebd3800000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol b/test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol new file mode 100644 index 000000000..646f8f6e9 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol @@ -0,0 +1,13 @@ +contract test { + function boo() public returns (bytes4 value) { + return msg.sig; + } + + function foo(uint256 a) public returns (bytes4 value) { + return boo(); + } +} +// ==== +// compileViaYul: also +// ---- +// foo(uint256): 0x0 -> 0x2fbebd3800000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/extracted/multi_modifiers.sol b/test/libsolidity/semanticTests/extracted/multi_modifiers.sol new file mode 100644 index 000000000..07f6c038d --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/multi_modifiers.sol @@ -0,0 +1,23 @@ +// This triggered a bug in some version because the variable in the modifier was not +// unregistered correctly. +contract C { + uint256 public x; + modifier m1 { + address a1 = msg.sender; + x++; + _; + } + + function f1() public m1() { + x += 7; + } + + function f2() public m1() { + x += 3; + } +} +// ---- +// f1() -> +// x() -> 0x08 +// f2() -> +// x() -> 0x0c diff --git a/test/libsolidity/semanticTests/extracted/reusing_memory.sol b/test/libsolidity/semanticTests/extracted/reusing_memory.sol new file mode 100644 index 000000000..b2876eeb3 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/reusing_memory.sol @@ -0,0 +1,26 @@ +// Invoke some features that use memory and test that they do not interfere with each other. +contract Helper { + uint256 public flag; + + constructor(uint256 x) public { + flag = x; + } +} + + +contract Main { + mapping(uint256 => uint256) map; + + function f(uint256 x) public returns (uint256) { + map[x] = x; + return + (new Helper(uint256(keccak256(abi.encodePacked(this.g(map[x])))))) + .flag(); + } + + function g(uint256 a) public returns (uint256) { + return map[a]; + } +} +// ---- +// f(uint256): 0x34 -> 0x46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1 diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled.sol b/test/libsolidity/semanticTests/extracted/shift_right_garbled.sol new file mode 100644 index 000000000..c0d6be8bd --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_garbled.sol @@ -0,0 +1,14 @@ +contract C { + function f(uint8 a, uint8 b) public returns (uint256) { + assembly { + a := 0xffffffff + } + // Higher bits should be cleared before the shift + return a >> b; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(uint8,uint8): 0x00, 0x04 -> 0x0f +// f(uint8,uint8): 0x00, 0x1004 -> 0x0f diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol b/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol new file mode 100644 index 000000000..df0570cb7 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol @@ -0,0 +1,30 @@ +contract C { + function f(int8 a, uint8 b) public returns (int256) { + assembly { + a := 0xfffffff0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + + function g(int8 a, uint8 b) public returns (int256) { + assembly { + a := 0xf0 + } + // Higher bits should be signextended before the shift + return a >> b; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// f(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// f(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// f(int8,uint8): 0x00, 0x1003 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// f(int8,uint8): 0x00, 0x1004 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// g(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// g(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// g(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// g(int8,uint8): 0x00, 0x1003 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// g(int8,uint8): 0x00, 0x1004 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol b/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol new file mode 100644 index 000000000..0c1949a59 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol @@ -0,0 +1,31 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(int8 a, uint8 b) public returns (int256) { + assembly { + a := 0xfffffff0 + } + // Higher bits should be signextended before the shift + return a >> b; + } + + function g(int8 a, uint8 b) public returns (int256) { + assembly { + a := 0xf0 + } + // Higher bits should be signextended before the shift + return a >> b; + } +} +// ---- +// f(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// f(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// f(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// f(int8,uint8): 0x00, 0x1003 -> FAILURE +// f(int8,uint8): 0x00, 0x1004 -> FAILURE +// g(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// g(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// g(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// g(int8,uint8): 0x00, 0x1003 -> FAILURE +// g(int8,uint8): 0x00, 0x1004 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol b/test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol new file mode 100644 index 000000000..54ac9540f --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol @@ -0,0 +1,15 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(uint8 a, uint8 b) public returns (uint256) { + assembly { + a := 0xffffffff + } + // Higher bits should be cleared before the shift + return a >> b; + } +} +// ---- +// f(uint8,uint8): 0x00, 0x04 -> 0x0f +// f(uint8,uint8): 0x00, 0x1004 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol new file mode 100644 index 000000000..c59107f52 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol @@ -0,0 +1,13 @@ +contract C { + function f(int16 a, int16 b) public returns (int16) { + return a >> b; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(int16,int16): 0xff99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99 +// f(int16,int16): 0xff99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc +// f(int16,int16): 0xff99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6 +// f(int16,int16): 0xff99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9 +// f(int16,int16): 0xff99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol new file mode 100644 index 000000000..6e462e704 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol @@ -0,0 +1,14 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(int16 a, int16 b) public returns (int16) { + return a >> b; + } +} +// ---- +// f(int16,int16): 0xff99, 0x00 -> FAILURE +// f(int16,int16): 0xff99, 0x01 -> FAILURE +// f(int16,int16): 0xff99, 0x02 -> FAILURE +// f(int16,int16): 0xff99, 0x04 -> FAILURE +// f(int16,int16): 0xff99, 0x08 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol new file mode 100644 index 000000000..74e9d53b0 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol @@ -0,0 +1,13 @@ +contract C { + function f(int32 a, int32 b) public returns (int32) { + return a >> b; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(int32,int32): 0xffffff99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99 +// f(int32,int32): 0xffffff99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc +// f(int32,int32): 0xffffff99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6 +// f(int32,int32): 0xffffff99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9 +// f(int32,int32): 0xffffff99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol new file mode 100644 index 000000000..2466298f0 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol @@ -0,0 +1,14 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(int32 a, int32 b) public returns (int32) { + return a >> b; + } +} +// ---- +// f(int32,int32): 0xffffff99, 0x00 -> FAILURE +// f(int32,int32): 0xffffff99, 0x01 -> FAILURE +// f(int32,int32): 0xffffff99, 0x02 -> FAILURE +// f(int32,int32): 0xffffff99, 0x04 -> FAILURE +// f(int32,int32): 0xffffff99, 0x08 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol new file mode 100644 index 000000000..06dcf8eb5 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol @@ -0,0 +1,13 @@ +contract C { + function f(int8 a, int8 b) public returns (int8) { + return a >> b; + } +} +// ==== +// ABIEncoderV1Only: true +// ---- +// f(int8,int8): 0x99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99 +// f(int8,int8): 0x99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc +// f(int8,int8): 0x99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6 +// f(int8,int8): 0x99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9 +// f(int8,int8): 0x99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol new file mode 100644 index 000000000..643bc5e62 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol @@ -0,0 +1,14 @@ +pragma experimental ABIEncoderV2; + + +contract C { + function f(int8 a, int8 b) public returns (int8) { + return a >> b; + } +} +// ---- +// f(int8,int8): 0x99, 0x00 -> FAILURE +// f(int8,int8): 0x99, 0x01 -> FAILURE +// f(int8,int8): 0x99, 0x02 -> FAILURE +// f(int8,int8): 0x99, 0x04 -> FAILURE +// f(int8,int8): 0x99, 0x08 -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol b/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol new file mode 100644 index 000000000..96c5419be --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol @@ -0,0 +1,39 @@ +contract C { + uint256 x; + + function f() public returns (uint256) { + x = 3; + return 1; + } +} + + +interface CView { + function f() external view returns (uint256); +} + + +interface CPure { + function f() external pure returns (uint256); +} + + +contract D { + function f() public returns (uint256) { + return (new C()).f(); + } + + function fview() public returns (uint256) { + return (CView(address(new C()))).f(); + } + + function fpure() public returns (uint256) { + return (CPure(address(new C()))).f(); + } +} +// ==== +// EVMVersion: >=byzantium +// ---- +// f() -> 0x1 # This should work, next should throw # +// fview() -> FAILURE +// fpure() -> FAILURE diff --git a/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol b/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol new file mode 100644 index 000000000..a193e8752 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol @@ -0,0 +1,39 @@ +contract C { + uint256 x; + + function f() public returns (uint256) { + x = 3; + return 1; + } +} + + +interface CView { + function f() external view returns (uint256); +} + + +interface CPure { + function f() external pure returns (uint256); +} + + +contract D { + function f() public returns (uint256) { + return (new C()).f(); + } + + function fview() public returns (uint256) { + return (CView(address(new C()))).f(); + } + + function fpure() public returns (uint256) { + return (CPure(address(new C()))).f(); + } +} +// ==== +// EVMVersion: 0x1 +// fview() -> 1 +// fpure() -> 1 diff --git a/test/libsolidity/semanticTests/extracted/string_allocation_bug.sol b/test/libsolidity/semanticTests/extracted/string_allocation_bug.sol new file mode 100644 index 000000000..9c2ec2e53 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/string_allocation_bug.sol @@ -0,0 +1,20 @@ +contract Sample { + struct s { + uint16 x; + uint16 y; + string a; + string b; + } + s[2] public p; + + constructor() public { + s memory m; + m.x = 0xbbbb; + m.y = 0xcccc; + m.a = "hello"; + m.b = "world"; + p[0] = m; + } +} +// ---- +// p(uint256): 0x0 -> 0xbbbb, 0xcccc, 0x80, 0xc0, 0x05, "hello", 0x05, "world" diff --git a/test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol b/test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol new file mode 100644 index 000000000..9578fc4f7 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol @@ -0,0 +1,17 @@ +contract Test { + string s; + bytes b; + + function f(string memory _s, uint256 n) public returns (bytes1) { + b = bytes(_s); + s = string(b); + return bytes(s)[n]; + } + + function l() public returns (uint256) { + return bytes(s).length; + } +} +// ---- +// f(string,uint256): 0x40, 0x02, 0x06, "abcdef" -> "c" +// l() -> 0x06 diff --git a/test/libsolidity/semanticTests/extracted/strings_in_struct.sol b/test/libsolidity/semanticTests/extracted/strings_in_struct.sol new file mode 100644 index 000000000..a6ec607f4 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/strings_in_struct.sol @@ -0,0 +1,35 @@ +contract buggystruct { + Buggy public bug; + + struct Buggy { + uint256 first; + uint256 second; + uint256 third; + string last; + } + + constructor() public { + bug = Buggy(10, 20, 30, "asdfghjkl"); + } + + function getFirst() public returns (uint256) { + return bug.first; + } + + function getSecond() public returns (uint256) { + return bug.second; + } + + function getThird() public returns (uint256) { + return bug.third; + } + + function getLast() public returns (string memory) { + return bug.last; + } +} +// ---- +// getFirst() -> 0x0a +// getSecond() -> 0x14 +// getThird() -> 0x1e +// getLast() -> 0x20, 0x09, "asdfghjkl" diff --git a/test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol b/test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol new file mode 100644 index 000000000..dbd67ab58 --- /dev/null +++ b/test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol @@ -0,0 +1,30 @@ +contract C { + struct X { + uint256 x1; + uint256 x2; + } + struct S { + uint256 s1; + uint256[3] s2; + X s3; + } + S s; + + constructor() public { + uint256[3] memory s2; + s2[1] = 9; + s = S(1, s2, X(4, 5)); + } + + function get() + public + returns (uint256 s1, uint256[3] memory s2, uint256 x1, uint256 x2) + { + s1 = s.s1; + s2 = s.s2; + x1 = s.s3.x1; + x2 = s.s3.x2; + } +} +// ---- +// get() -> 0x01, 0x00, 0x09, 0x00, 0x04, 0x05 From 165f7bf60f50a0ad8799591331c6e3363da17aa3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 26 Mar 2020 17:47:36 +0100 Subject: [PATCH 2/2] Move files. --- .../{extracted => abiencodedecode}/abi_decode_calldata.sol | 0 .../{extracted => abiencodedecode}/abi_decode_simple.sol | 0 .../{extracted => abiencodedecode}/abi_decode_simple_storage.sol | 0 .../{extracted => abiencodedecode}/abi_encode_empty_string.sol | 0 .../{extracted => array}/arrays_complex_from_and_to_storage.sol | 0 .../{extracted => array}/arrays_complex_memory_index_access.sol | 0 .../{extracted => array}/bytes_memory_index_access.sol | 0 .../{extracted => array}/fixed_arrays_in_storage.sol | 0 .../{extracted => array}/fixed_bytes_index_access.sol | 0 .../memory_arrays_dynamic_index_access_write.sol | 0 .../{extracted => array}/memory_arrays_index_access_write.sol | 0 .../semanticTests/{extracted => array}/reusing_memory.sol | 0 .../semanticTests/{extracted => array}/string_allocation_bug.sol | 0 .../{extracted => array}/string_bytes_conversion.sol | 0 .../semanticTests/{extracted => array}/strings_in_struct.sol | 0 .../assignment_to_const_var_involving_keccak.sol | 0 .../{extracted => builtinFunctions}/function_types_sig.sol | 0 .../iterated_keccak256_with_bytes.sol | 0 .../keccak256_multiple_arguments.sol | 0 .../keccak256_multiple_arguments_with_numeric_literals.sol | 0 .../keccak256_multiple_arguments_with_string_literals.sol | 0 .../semanticTests/{extracted => builtinFunctions}/msg_sig.sol | 0 .../msg_sig_after_internal_call_is_same.sol | 0 .../{extracted => calldata}/calldata_array_dynamic_bytes.sol | 0 .../{extracted => calldata}/calldata_bytes_array_to_memory.sol | 0 .../{extracted => calldata}/calldata_string_array.sol | 0 .../{extracted => calldata}/calldata_struct_cleaning.sol | 0 .../semanticTests/{extracted => cleanup}/bool_conversion.sol | 0 .../semanticTests/{extracted => cleanup}/bool_conversion_v2.sol | 0 .../{extracted => cleanup}/cleanup_address_types.sol | 0 .../{extracted => cleanup}/cleanup_address_types_v2.sol | 0 .../semanticTests/{extracted => cleanup}/cleanup_bytes_types.sol | 0 .../{extracted => cleanup}/cleanup_bytes_types_v2.sol | 0 .../{extracted => functionCall}/delegatecall_return_value.sol | 0 .../delegatecall_return_value_pre_byzantium.sol | 0 .../{extracted => shifts}/bitwise_shifting_constantinople.sol | 0 .../bitwise_shifting_constantinople_combined.sol | 0 .../bitwise_shifting_constants_constantinople.sol | 0 .../semanticTests/{extracted => shifts}/shift_right_garbled.sol | 0 .../{extracted => shifts}/shift_right_garbled_signed.sol | 0 .../{extracted => shifts}/shift_right_garbled_signed_v2.sol | 0 .../{extracted => shifts}/shift_right_garbled_v2.sol | 0 .../shift_right_negative_lvalue_signextend_int16.sol | 0 .../shift_right_negative_lvalue_signextend_int16_v2.sol | 0 .../shift_right_negative_lvalue_signextend_int32.sol | 0 .../shift_right_negative_lvalue_signextend_int32_v2.sol | 0 .../shift_right_negative_lvalue_signextend_int8.sol | 0 .../shift_right_negative_lvalue_signextend_int8_v2.sol | 0 .../{extracted => structs}/memory_structs_nested_load.sol | 0 .../{extracted => structs}/struct_constructor_nested.sol | 0 .../semanticTests/{extracted => various}/multi_modifiers.sol | 0 .../{extracted => various}/staticcall_for_view_and_pure.sol | 0 .../staticcall_for_view_and_pure_pre_byzantium.sol | 0 53 files changed, 0 insertions(+), 0 deletions(-) rename test/libsolidity/semanticTests/{extracted => abiencodedecode}/abi_decode_calldata.sol (100%) rename test/libsolidity/semanticTests/{extracted => abiencodedecode}/abi_decode_simple.sol (100%) rename test/libsolidity/semanticTests/{extracted => abiencodedecode}/abi_decode_simple_storage.sol (100%) rename test/libsolidity/semanticTests/{extracted => abiencodedecode}/abi_encode_empty_string.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/arrays_complex_from_and_to_storage.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/arrays_complex_memory_index_access.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/bytes_memory_index_access.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/fixed_arrays_in_storage.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/fixed_bytes_index_access.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/memory_arrays_dynamic_index_access_write.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/memory_arrays_index_access_write.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/reusing_memory.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/string_allocation_bug.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/string_bytes_conversion.sol (100%) rename test/libsolidity/semanticTests/{extracted => array}/strings_in_struct.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/assignment_to_const_var_involving_keccak.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/function_types_sig.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/iterated_keccak256_with_bytes.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/keccak256_multiple_arguments.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/keccak256_multiple_arguments_with_numeric_literals.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/keccak256_multiple_arguments_with_string_literals.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/msg_sig.sol (100%) rename test/libsolidity/semanticTests/{extracted => builtinFunctions}/msg_sig_after_internal_call_is_same.sol (100%) rename test/libsolidity/semanticTests/{extracted => calldata}/calldata_array_dynamic_bytes.sol (100%) rename test/libsolidity/semanticTests/{extracted => calldata}/calldata_bytes_array_to_memory.sol (100%) rename test/libsolidity/semanticTests/{extracted => calldata}/calldata_string_array.sol (100%) rename test/libsolidity/semanticTests/{extracted => calldata}/calldata_struct_cleaning.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/bool_conversion.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/bool_conversion_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/cleanup_address_types.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/cleanup_address_types_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/cleanup_bytes_types.sol (100%) rename test/libsolidity/semanticTests/{extracted => cleanup}/cleanup_bytes_types_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => functionCall}/delegatecall_return_value.sol (100%) rename test/libsolidity/semanticTests/{extracted => functionCall}/delegatecall_return_value_pre_byzantium.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/bitwise_shifting_constantinople.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/bitwise_shifting_constantinople_combined.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/bitwise_shifting_constants_constantinople.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_garbled.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_garbled_signed.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_garbled_signed_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_garbled_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int16.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int16_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int32.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int32_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int8.sol (100%) rename test/libsolidity/semanticTests/{extracted => shifts}/shift_right_negative_lvalue_signextend_int8_v2.sol (100%) rename test/libsolidity/semanticTests/{extracted => structs}/memory_structs_nested_load.sol (100%) rename test/libsolidity/semanticTests/{extracted => structs}/struct_constructor_nested.sol (100%) rename test/libsolidity/semanticTests/{extracted => various}/multi_modifiers.sol (100%) rename test/libsolidity/semanticTests/{extracted => various}/staticcall_for_view_and_pure.sol (100%) rename test/libsolidity/semanticTests/{extracted => various}/staticcall_for_view_and_pure_pre_byzantium.sol (100%) diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_calldata.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/abi_decode_calldata.sol rename to test/libsolidity/semanticTests/abiencodedecode/abi_decode_calldata.sol diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_simple.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/abi_decode_simple.sol rename to test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple.sol diff --git a/test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/abi_decode_simple_storage.sol rename to test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol diff --git a/test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_encode_empty_string.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/abi_encode_empty_string.sol rename to test/libsolidity/semanticTests/abiencodedecode/abi_encode_empty_string.sol diff --git a/test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol b/test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/arrays_complex_from_and_to_storage.sol rename to test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol diff --git a/test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol b/test/libsolidity/semanticTests/array/arrays_complex_memory_index_access.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/arrays_complex_memory_index_access.sol rename to test/libsolidity/semanticTests/array/arrays_complex_memory_index_access.sol diff --git a/test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol b/test/libsolidity/semanticTests/array/bytes_memory_index_access.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bytes_memory_index_access.sol rename to test/libsolidity/semanticTests/array/bytes_memory_index_access.sol diff --git a/test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol b/test/libsolidity/semanticTests/array/fixed_arrays_in_storage.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/fixed_arrays_in_storage.sol rename to test/libsolidity/semanticTests/array/fixed_arrays_in_storage.sol diff --git a/test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol b/test/libsolidity/semanticTests/array/fixed_bytes_index_access.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/fixed_bytes_index_access.sol rename to test/libsolidity/semanticTests/array/fixed_bytes_index_access.sol diff --git a/test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol b/test/libsolidity/semanticTests/array/memory_arrays_dynamic_index_access_write.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/memory_arrays_dynamic_index_access_write.sol rename to test/libsolidity/semanticTests/array/memory_arrays_dynamic_index_access_write.sol diff --git a/test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol b/test/libsolidity/semanticTests/array/memory_arrays_index_access_write.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/memory_arrays_index_access_write.sol rename to test/libsolidity/semanticTests/array/memory_arrays_index_access_write.sol diff --git a/test/libsolidity/semanticTests/extracted/reusing_memory.sol b/test/libsolidity/semanticTests/array/reusing_memory.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/reusing_memory.sol rename to test/libsolidity/semanticTests/array/reusing_memory.sol diff --git a/test/libsolidity/semanticTests/extracted/string_allocation_bug.sol b/test/libsolidity/semanticTests/array/string_allocation_bug.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/string_allocation_bug.sol rename to test/libsolidity/semanticTests/array/string_allocation_bug.sol diff --git a/test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol b/test/libsolidity/semanticTests/array/string_bytes_conversion.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/string_bytes_conversion.sol rename to test/libsolidity/semanticTests/array/string_bytes_conversion.sol diff --git a/test/libsolidity/semanticTests/extracted/strings_in_struct.sol b/test/libsolidity/semanticTests/array/strings_in_struct.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/strings_in_struct.sol rename to test/libsolidity/semanticTests/array/strings_in_struct.sol diff --git a/test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol b/test/libsolidity/semanticTests/builtinFunctions/assignment_to_const_var_involving_keccak.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/assignment_to_const_var_involving_keccak.sol rename to test/libsolidity/semanticTests/builtinFunctions/assignment_to_const_var_involving_keccak.sol diff --git a/test/libsolidity/semanticTests/extracted/function_types_sig.sol b/test/libsolidity/semanticTests/builtinFunctions/function_types_sig.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/function_types_sig.sol rename to test/libsolidity/semanticTests/builtinFunctions/function_types_sig.sol diff --git a/test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol b/test/libsolidity/semanticTests/builtinFunctions/iterated_keccak256_with_bytes.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/iterated_keccak256_with_bytes.sol rename to test/libsolidity/semanticTests/builtinFunctions/iterated_keccak256_with_bytes.sol diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol b/test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments.sol rename to test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments.sol diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol b/test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments_with_numeric_literals.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_numeric_literals.sol rename to test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments_with_numeric_literals.sol diff --git a/test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol b/test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments_with_string_literals.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/keccak256_multiple_arguments_with_string_literals.sol rename to test/libsolidity/semanticTests/builtinFunctions/keccak256_multiple_arguments_with_string_literals.sol diff --git a/test/libsolidity/semanticTests/extracted/msg_sig.sol b/test/libsolidity/semanticTests/builtinFunctions/msg_sig.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/msg_sig.sol rename to test/libsolidity/semanticTests/builtinFunctions/msg_sig.sol diff --git a/test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol b/test/libsolidity/semanticTests/builtinFunctions/msg_sig_after_internal_call_is_same.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/msg_sig_after_internal_call_is_same.sol rename to test/libsolidity/semanticTests/builtinFunctions/msg_sig_after_internal_call_is_same.sol diff --git a/test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol b/test/libsolidity/semanticTests/calldata/calldata_array_dynamic_bytes.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/calldata_array_dynamic_bytes.sol rename to test/libsolidity/semanticTests/calldata/calldata_array_dynamic_bytes.sol diff --git a/test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol b/test/libsolidity/semanticTests/calldata/calldata_bytes_array_to_memory.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/calldata_bytes_array_to_memory.sol rename to test/libsolidity/semanticTests/calldata/calldata_bytes_array_to_memory.sol diff --git a/test/libsolidity/semanticTests/extracted/calldata_string_array.sol b/test/libsolidity/semanticTests/calldata/calldata_string_array.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/calldata_string_array.sol rename to test/libsolidity/semanticTests/calldata/calldata_string_array.sol diff --git a/test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol b/test/libsolidity/semanticTests/calldata/calldata_struct_cleaning.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/calldata_struct_cleaning.sol rename to test/libsolidity/semanticTests/calldata/calldata_struct_cleaning.sol diff --git a/test/libsolidity/semanticTests/extracted/bool_conversion.sol b/test/libsolidity/semanticTests/cleanup/bool_conversion.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bool_conversion.sol rename to test/libsolidity/semanticTests/cleanup/bool_conversion.sol diff --git a/test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol b/test/libsolidity/semanticTests/cleanup/bool_conversion_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bool_conversion_v2.sol rename to test/libsolidity/semanticTests/cleanup/bool_conversion_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/cleanup_address_types.sol b/test/libsolidity/semanticTests/cleanup/cleanup_address_types.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/cleanup_address_types.sol rename to test/libsolidity/semanticTests/cleanup/cleanup_address_types.sol diff --git a/test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol b/test/libsolidity/semanticTests/cleanup/cleanup_address_types_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/cleanup_address_types_v2.sol rename to test/libsolidity/semanticTests/cleanup/cleanup_address_types_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol b/test/libsolidity/semanticTests/cleanup/cleanup_bytes_types.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/cleanup_bytes_types.sol rename to test/libsolidity/semanticTests/cleanup/cleanup_bytes_types.sol diff --git a/test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol b/test/libsolidity/semanticTests/cleanup/cleanup_bytes_types_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/cleanup_bytes_types_v2.sol rename to test/libsolidity/semanticTests/cleanup/cleanup_bytes_types_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol b/test/libsolidity/semanticTests/functionCall/delegatecall_return_value.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/delegatecall_return_value.sol rename to test/libsolidity/semanticTests/functionCall/delegatecall_return_value.sol diff --git a/test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol b/test/libsolidity/semanticTests/functionCall/delegatecall_return_value_pre_byzantium.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/delegatecall_return_value_pre_byzantium.sol rename to test/libsolidity/semanticTests/functionCall/delegatecall_return_value_pre_byzantium.sol diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol b/test/libsolidity/semanticTests/shifts/bitwise_shifting_constantinople.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople.sol rename to test/libsolidity/semanticTests/shifts/bitwise_shifting_constantinople.sol diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol b/test/libsolidity/semanticTests/shifts/bitwise_shifting_constantinople_combined.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bitwise_shifting_constantinople_combined.sol rename to test/libsolidity/semanticTests/shifts/bitwise_shifting_constantinople_combined.sol diff --git a/test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol b/test/libsolidity/semanticTests/shifts/bitwise_shifting_constants_constantinople.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/bitwise_shifting_constants_constantinople.sol rename to test/libsolidity/semanticTests/shifts/bitwise_shifting_constants_constantinople.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled.sol b/test/libsolidity/semanticTests/shifts/shift_right_garbled.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_garbled.sol rename to test/libsolidity/semanticTests/shifts/shift_right_garbled.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol b/test/libsolidity/semanticTests/shifts/shift_right_garbled_signed.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_garbled_signed.sol rename to test/libsolidity/semanticTests/shifts/shift_right_garbled_signed.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol b/test/libsolidity/semanticTests/shifts/shift_right_garbled_signed_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_garbled_signed_v2.sol rename to test/libsolidity/semanticTests/shifts/shift_right_garbled_signed_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol b/test/libsolidity/semanticTests/shifts/shift_right_garbled_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_garbled_v2.sol rename to test/libsolidity/semanticTests/shifts/shift_right_garbled_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int16.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int16.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int16_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int16_v2.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int16_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int32.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int32.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int32_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int32_v2.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int32_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int8.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int8.sol diff --git a/test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol b/test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int8_v2.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/shift_right_negative_lvalue_signextend_int8_v2.sol rename to test/libsolidity/semanticTests/shifts/shift_right_negative_lvalue_signextend_int8_v2.sol diff --git a/test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol b/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/memory_structs_nested_load.sol rename to test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol diff --git a/test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol b/test/libsolidity/semanticTests/structs/struct_constructor_nested.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/struct_constructor_nested.sol rename to test/libsolidity/semanticTests/structs/struct_constructor_nested.sol diff --git a/test/libsolidity/semanticTests/extracted/multi_modifiers.sol b/test/libsolidity/semanticTests/various/multi_modifiers.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/multi_modifiers.sol rename to test/libsolidity/semanticTests/various/multi_modifiers.sol diff --git a/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol b/test/libsolidity/semanticTests/various/staticcall_for_view_and_pure.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure.sol rename to test/libsolidity/semanticTests/various/staticcall_for_view_and_pure.sol diff --git a/test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol b/test/libsolidity/semanticTests/various/staticcall_for_view_and_pure_pre_byzantium.sol similarity index 100% rename from test/libsolidity/semanticTests/extracted/staticcall_for_view_and_pure_pre_byzantium.sol rename to test/libsolidity/semanticTests/various/staticcall_for_view_and_pure_pre_byzantium.sol