mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10048 from ethereum/develop
Merge develop into breaking
This commit is contained in:
@@ -622,27 +622,30 @@ BOOST_AUTO_TEST_CASE(for_loop_break_continue)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto breakContinue = [](u256 const& n) -> u256
|
||||
{
|
||||
u256 i = 1;
|
||||
u256 k = 0;
|
||||
for (i *= 5; k < n; i *= 7)
|
||||
auto breakContinue = [](u256 const& n) -> u256
|
||||
{
|
||||
k++;
|
||||
i += 4;
|
||||
if (n % 3 == 0)
|
||||
break;
|
||||
i += 9;
|
||||
if (n % 2 == 0)
|
||||
continue;
|
||||
i += 19;
|
||||
}
|
||||
return i;
|
||||
};
|
||||
u256 i = 1;
|
||||
u256 k = 0;
|
||||
for (i *= 5; k < n; i *= 7)
|
||||
{
|
||||
k++;
|
||||
i += 4;
|
||||
if (n % 3 == 0)
|
||||
break;
|
||||
i += 9;
|
||||
if (n % 2 == 0)
|
||||
continue;
|
||||
i += 19;
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
testContractAgainstCppOnRange("f(uint256)", breakContinue, 0, 10);
|
||||
testContractAgainstCppOnRange("f(uint256)", breakContinue, 0, 10);
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
@@ -663,8 +666,6 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto evenStep_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
return n / 2;
|
||||
@@ -687,12 +688,16 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
}
|
||||
return y;
|
||||
};
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(0));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(1));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(2));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(8));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(127));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(0));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(1));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(2));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(8));
|
||||
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(127));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(many_local_variables)
|
||||
@@ -706,18 +711,18 @@ BOOST_AUTO_TEST_CASE(many_local_variables)
|
||||
}
|
||||
}
|
||||
)";
|
||||
auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
|
||||
{
|
||||
u256 a = 0x1;
|
||||
u256 b = 0x10;
|
||||
u256 c = 0x100;
|
||||
u256 y = a + b + c + x1 + x2 + x3;
|
||||
return y + b + x2;
|
||||
};
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
|
||||
{
|
||||
u256 a = 0x1;
|
||||
u256 b = 0x10;
|
||||
u256 c = 0x100;
|
||||
u256 y = a + b + c + x1 + x2 + x3;
|
||||
return y + b + x2;
|
||||
};
|
||||
testContractAgainstCpp("run(uint256,uint256,uint256)", f, u256(0x1000), u256(0x10000), u256(0x100000));
|
||||
)
|
||||
}
|
||||
@@ -823,12 +828,15 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto small_signed_types_cpp = []() -> u256
|
||||
{
|
||||
return -int32_t(10) * -int64_t(20);
|
||||
};
|
||||
testContractAgainstCpp("run()", small_signed_types_cpp);
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
auto small_signed_types_cpp = []() -> u256
|
||||
{
|
||||
return -int32_t(10) * -int64_t(20);
|
||||
};
|
||||
testContractAgainstCpp("run()", small_signed_types_cpp);
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compound_assign)
|
||||
@@ -1154,10 +1162,13 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(code, 0, "C");
|
||||
bytes result = callContractFunction("f()");
|
||||
BOOST_REQUIRE_EQUAL(result.size(), 32);
|
||||
BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0);
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(code, 0, "C");
|
||||
bytes result = callContractFunction("f()");
|
||||
BOOST_REQUIRE_EQUAL(result.size(), 32);
|
||||
BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0);
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(log0)
|
||||
@@ -1325,14 +1336,17 @@ BOOST_AUTO_TEST_CASE(keccak256)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> u256
|
||||
{
|
||||
return util::keccak256(toBigEndian(_x));
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> u256
|
||||
{
|
||||
return util::keccak256(toBigEndian(_x));
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sha256)
|
||||
@@ -1344,7 +1358,6 @@ BOOST_AUTO_TEST_CASE(sha256)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> bytes
|
||||
{
|
||||
if (_x == u256(4))
|
||||
@@ -1355,9 +1368,13 @@ BOOST_AUTO_TEST_CASE(sha256)
|
||||
return fromHex("af9613760f72635fbdb44a5a0a63c39f12af30f950a6ee5c971be188e89c4051");
|
||||
return fromHex("");
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ripemd)
|
||||
@@ -1369,7 +1386,6 @@ BOOST_AUTO_TEST_CASE(ripemd)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> bytes
|
||||
{
|
||||
if (_x == u256(4))
|
||||
@@ -1380,9 +1396,13 @@ BOOST_AUTO_TEST_CASE(ripemd)
|
||||
return fromHex("1cf4e77f5966e13e109703cd8a0df7ceda7f3dc3000000000000000000000000");
|
||||
return fromHex("");
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(packed_keccak256)
|
||||
@@ -1396,7 +1416,6 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> u256
|
||||
{
|
||||
return util::keccak256(
|
||||
@@ -1407,9 +1426,13 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
|
||||
toBigEndian(u256(256))
|
||||
);
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
|
||||
@@ -1428,13 +1451,16 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
// Strangely, arrays are encoded with intra-element padding.
|
||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(
|
||||
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
|
||||
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
|
||||
util::keccak256(fromHex(m_contractAddress.hex() + "26121ff0"))
|
||||
));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
// Strangely, arrays are encoded with intra-element padding.
|
||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(
|
||||
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
|
||||
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
|
||||
util::keccak256(fromHex(m_contractAddress.hex() + "26121ff0"))
|
||||
));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(packed_sha256)
|
||||
@@ -1448,7 +1474,6 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> bytes
|
||||
{
|
||||
if (_x == u256(4))
|
||||
@@ -1459,9 +1484,13 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
|
||||
return fromHex("f14def4d07cd185ddd8b10a81b2238326196a38867e6e6adbcc956dc913488c7");
|
||||
return fromHex("");
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(packed_ripemd160)
|
||||
@@ -1475,7 +1504,6 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
auto f = [&](u256 const& _x) -> bytes
|
||||
{
|
||||
if (_x == u256(4))
|
||||
@@ -1486,9 +1514,13 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
|
||||
return fromHex("c0a2e4b1f3ff766a9a0089e7a410391730872495000000000000000000000000");
|
||||
return fromHex("");
|
||||
};
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
ALSO_VIA_YUL(
|
||||
DISABLE_EWASM_TESTRUN()
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(4));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(5));
|
||||
testContractAgainstCpp("a(bytes32)", f, u256(-1));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inter_contract_calls)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
contract C {
|
||||
bytes data;
|
||||
bytes otherData;
|
||||
function fromMemory() public returns (byte) {
|
||||
bytes memory t;
|
||||
uint[2] memory x;
|
||||
x[0] = type(uint).max;
|
||||
data = t;
|
||||
data.push();
|
||||
return data[0];
|
||||
}
|
||||
function fromCalldata(bytes calldata x) public returns (byte) {
|
||||
data = x;
|
||||
data.push();
|
||||
return data[0];
|
||||
}
|
||||
function fromStorage() public returns (byte) {
|
||||
// zero-length but dirty higher order bits
|
||||
assembly { sstore(otherData.slot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00) }
|
||||
data = otherData;
|
||||
data.push();
|
||||
return data[0];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// fromMemory() -> 0x00
|
||||
// fromCalldata(bytes): 0x40, 0x60, 0x00, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
|
||||
// fromStorage() -> 0x00
|
||||
@@ -0,0 +1,35 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint32 a;
|
||||
S[] x;
|
||||
}
|
||||
S s;
|
||||
function f() public returns (uint256 r1, uint256 r2, uint256 r3) {
|
||||
assembly {
|
||||
// 2 ** 150 - 1
|
||||
sstore(s.slot, 1427247692705959881058285969449495136382746623)
|
||||
}
|
||||
s.a = 1;
|
||||
s.x.push(); s.x.push();
|
||||
S storage ptr1 = s.x[0];
|
||||
S storage ptr2 = s.x[1];
|
||||
assembly {
|
||||
// 2 ** 150 - 1
|
||||
sstore(ptr1.slot, 1427247692705959881058285969449495136382746623)
|
||||
sstore(ptr2.slot, 1427247692705959881058285969449495136382746623)
|
||||
}
|
||||
s.x[0].a = 2; s.x[1].a = 3;
|
||||
delete s;
|
||||
assert(s.a == 0);
|
||||
assert(s.x.length == 0);
|
||||
assembly {
|
||||
r1 := sload(s.slot)
|
||||
r2 := sload(ptr1.slot)
|
||||
r3 := sload(ptr2.slot)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 0, 0, 0
|
||||
@@ -0,0 +1,24 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint64 y;
|
||||
uint64 z;
|
||||
}
|
||||
S s;
|
||||
function f() public returns (uint256 ret) {
|
||||
assembly {
|
||||
// 2 ** 150 - 1
|
||||
sstore(s.slot, 1427247692705959881058285969449495136382746623)
|
||||
}
|
||||
s.y = 1; s.z = 2;
|
||||
delete s;
|
||||
assert(s.y == 0);
|
||||
assert(s.z == 0);
|
||||
assembly {
|
||||
ret := sload(s.slot)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 0
|
||||
@@ -0,0 +1,29 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint32 a;
|
||||
uint32[3] b;
|
||||
uint32[] x;
|
||||
}
|
||||
S s;
|
||||
function f() public returns (uint256 ret) {
|
||||
assembly {
|
||||
// 2 ** 150 - 1
|
||||
sstore(s.slot, 1427247692705959881058285969449495136382746623)
|
||||
}
|
||||
s.a = 1;
|
||||
s.b[0] = 2; s.b[1] = 3;
|
||||
s.x.push(4); s.x.push(5);
|
||||
delete s;
|
||||
assert(s.a == 0);
|
||||
assert(s.b[0] == 0);
|
||||
assert(s.b[1] == 0);
|
||||
assert(s.x.length == 0);
|
||||
assembly {
|
||||
ret := sload(s.slot)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 0
|
||||
@@ -27,30 +27,16 @@ if (OSSFUZZ)
|
||||
solc_opt_ossfuzz.cpp
|
||||
../fuzzer_common.cpp
|
||||
../../TestCaseReader.cpp
|
||||
SolidityLexer.cpp
|
||||
SolidityParser.cpp
|
||||
)
|
||||
target_compile_options(solc_opt_ossfuzz
|
||||
PUBLIC
|
||||
${COMPILE_OPTIONS} -Wno-extra-semi -Wno-unused-parameter
|
||||
)
|
||||
target_include_directories(solc_opt_ossfuzz PRIVATE /usr/include/antlr4-runtime)
|
||||
target_link_libraries(solc_opt_ossfuzz PRIVATE libsolc evmasm antlr4-runtime)
|
||||
target_link_libraries(solc_opt_ossfuzz PRIVATE libsolc evmasm)
|
||||
set_target_properties(solc_opt_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
|
||||
add_executable(solc_noopt_ossfuzz
|
||||
solc_noopt_ossfuzz.cpp
|
||||
../fuzzer_common.cpp
|
||||
../../TestCaseReader.cpp
|
||||
SolidityLexer.cpp
|
||||
SolidityParser.cpp
|
||||
)
|
||||
target_compile_options(solc_noopt_ossfuzz
|
||||
PUBLIC
|
||||
${COMPILE_OPTIONS} -Wno-extra-semi -Wno-unused-parameter
|
||||
)
|
||||
target_include_directories(solc_noopt_ossfuzz PRIVATE /usr/include/antlr4-runtime)
|
||||
target_link_libraries(solc_noopt_ossfuzz PRIVATE libsolc evmasm antlr4-runtime)
|
||||
target_link_libraries(solc_noopt_ossfuzz PRIVATE libsolc evmasm)
|
||||
set_target_properties(solc_noopt_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
|
||||
add_executable(const_opt_ossfuzz const_opt_ossfuzz.cpp ../fuzzer_common.cpp)
|
||||
|
||||
Reference in New Issue
Block a user