mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9925 from ethereum/develop
Merge develop into breaking.
This commit is contained in:
@@ -35,6 +35,7 @@ set(libsolutil_sources
|
||||
libsolutil/JSON.cpp
|
||||
libsolutil/Keccak256.cpp
|
||||
libsolutil/LazyInit.cpp
|
||||
libsolutil/LEB128.cpp
|
||||
libsolutil/StringUtils.cpp
|
||||
libsolutil/SwarmHash.cpp
|
||||
libsolutil/UTF8.cpp
|
||||
|
||||
+2
-4
@@ -14,13 +14,11 @@ contract LoopFor2 {
|
||||
c[i] = b[i];
|
||||
++i;
|
||||
}
|
||||
// Fails as false positive.
|
||||
assert(b[0] == c[0]);
|
||||
assert(a[0] == 900);
|
||||
assert(b[0] == 900);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (320-339): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (343-362): CHC: Assertion violation happens here.
|
||||
// Warning 4661: (296-316): BMC: Assertion violation happens here.
|
||||
// Warning 6328: (290-309): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (313-332): CHC: Assertion violation happens here.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
assert(addmod(2**256 - 1, 10, 9) == 7);
|
||||
uint y = 0;
|
||||
uint x = addmod(2**256 - 1, 10, y);
|
||||
assert(x == 1);
|
||||
}
|
||||
function g(uint x, uint y, uint k) public pure returns (uint) {
|
||||
return addmod(x, y, k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (83-108): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (141-166): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (76-114): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (170-184): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (263-278): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 3046: (141-166): BMC: Division by zero happens here.
|
||||
// Warning 3046: (263-278): BMC: Division by zero happens here.
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function test() public pure {
|
||||
uint x;
|
||||
if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) x = 1;
|
||||
if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) x = 2;
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (118-143): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (183-208): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (219-233): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 6838: (93-143): BMC: Condition is always false.
|
||||
// Warning 6838: (158-208): BMC: Condition is always false.
|
||||
@@ -0,0 +1,35 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(uint256 d) public pure {
|
||||
uint x = addmod(1, 2, d);
|
||||
assert(x < d);
|
||||
}
|
||||
|
||||
function g(uint256 d) public pure {
|
||||
uint x = mulmod(1, 2, d);
|
||||
assert(x < d);
|
||||
}
|
||||
|
||||
function h() public pure returns (uint256) {
|
||||
uint x = mulmod(0, 1, 2);
|
||||
uint y = mulmod(1, 0, 2);
|
||||
assert(x == y);
|
||||
uint z = addmod(0, 1, 2);
|
||||
uint t = addmod(1, 0, 2);
|
||||
assert(z == t);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (94-109): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (113-126): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (180-195): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (199-212): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (275-290): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (303-318): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (349-364): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (377-392): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (322-336): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (396-410): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 3046: (94-109): BMC: Division by zero happens here.
|
||||
// Warning 3046: (180-195): BMC: Division by zero happens here.
|
||||
@@ -0,0 +1,24 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function test_addmod(uint x, uint y) public pure {
|
||||
require(x % 13 == 0);
|
||||
require(y % 13 == 0);
|
||||
|
||||
uint z = addmod(x, y, 13);
|
||||
assert(z == 0);
|
||||
}
|
||||
function test_mulmod(uint x, uint y) public pure {
|
||||
require(x % 13 == 0);
|
||||
require(y % 13 == 0);
|
||||
|
||||
uint z = mulmod(x, y, 13);
|
||||
assert(z == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (158-174): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (178-192): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (309-325): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (329-343): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 7812: (329-343): BMC: Assertion violation might happen here.
|
||||
@@ -0,0 +1,21 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
assert(mulmod(2**256 - 1, 2, 14) == 2);
|
||||
uint y = 0;
|
||||
uint x = mulmod(2**256 - 1, 10, y);
|
||||
assert(x == 1);
|
||||
}
|
||||
function g(uint x, uint y, uint k) public pure returns (uint) {
|
||||
return mulmod(x, y, k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (83-108): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (141-166): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (76-114): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (170-184): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (263-278): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 3046: (141-166): BMC: Division by zero happens here.
|
||||
// Warning 3046: (263-278): BMC: Division by zero happens here.
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
/**
|
||||
* Unit tests for LEB128.
|
||||
*/
|
||||
|
||||
#include <libsolutil/LEB128.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace solidity::util::test
|
||||
{
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LEB128Test)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(encode_unsigned)
|
||||
{
|
||||
bytes zero = solidity::util::lebEncode(0);
|
||||
BOOST_REQUIRE(zero.size() == 1);
|
||||
BOOST_REQUIRE(zero[0] == 0x00);
|
||||
|
||||
bytes one = solidity::util::lebEncode(1);
|
||||
BOOST_REQUIRE(one.size() == 1);
|
||||
BOOST_REQUIRE(one[0] == 0x01);
|
||||
|
||||
bytes large = solidity::util::lebEncode(624485);
|
||||
BOOST_REQUIRE(large.size() == 3);
|
||||
BOOST_REQUIRE(large[0] == 0xE5);
|
||||
BOOST_REQUIRE(large[1] == 0x8E);
|
||||
BOOST_REQUIRE(large[2] == 0x26);
|
||||
|
||||
bytes larger = solidity::util::lebEncodeSigned(123456123456);
|
||||
BOOST_REQUIRE(larger.size() == 6);
|
||||
BOOST_REQUIRE(larger[0] == 0xC0);
|
||||
BOOST_REQUIRE(larger[1] == 0xE4);
|
||||
BOOST_REQUIRE(larger[2] == 0xBB);
|
||||
BOOST_REQUIRE(larger[3] == 0xF4);
|
||||
BOOST_REQUIRE(larger[4] == 0xCB);
|
||||
BOOST_REQUIRE(larger[5] == 0x03);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(encode_signed)
|
||||
{
|
||||
bytes zero = solidity::util::lebEncodeSigned(0);
|
||||
BOOST_REQUIRE(zero.size() == 1);
|
||||
BOOST_REQUIRE(zero[0] == 0x00);
|
||||
|
||||
bytes one = solidity::util::lebEncodeSigned(1);
|
||||
BOOST_REQUIRE(one.size() == 1);
|
||||
BOOST_REQUIRE(one[0] == 0x01);
|
||||
|
||||
bytes negative_one = solidity::util::lebEncodeSigned(-1);
|
||||
BOOST_REQUIRE(negative_one.size() == 1);
|
||||
BOOST_REQUIRE(negative_one[0] == 0x7f);
|
||||
|
||||
bytes negative_two = solidity::util::lebEncodeSigned(-2);
|
||||
BOOST_REQUIRE(negative_two.size() == 1);
|
||||
BOOST_REQUIRE(negative_two[0] == 0x7e);
|
||||
|
||||
bytes large = solidity::util::lebEncodeSigned(624485);
|
||||
BOOST_REQUIRE(large.size() == 3);
|
||||
BOOST_REQUIRE(large[0] == 0xE5);
|
||||
BOOST_REQUIRE(large[1] == 0x8E);
|
||||
BOOST_REQUIRE(large[2] == 0x26);
|
||||
|
||||
bytes negative_large = solidity::util::lebEncodeSigned(-123456);
|
||||
BOOST_REQUIRE(negative_large.size() == 3);
|
||||
BOOST_REQUIRE(negative_large[0] == 0xC0);
|
||||
BOOST_REQUIRE(negative_large[1] == 0xBB);
|
||||
BOOST_REQUIRE(negative_large[2] == 0x78);
|
||||
|
||||
bytes negative_larger = solidity::util::lebEncodeSigned(-123456123456);
|
||||
BOOST_REQUIRE(negative_larger.size() == 6);
|
||||
BOOST_REQUIRE(negative_larger[0] == 0xC0);
|
||||
BOOST_REQUIRE(negative_larger[1] == 0x9B);
|
||||
BOOST_REQUIRE(negative_larger[2] == 0xC4);
|
||||
BOOST_REQUIRE(negative_larger[3] == 0x8B);
|
||||
BOOST_REQUIRE(negative_larger[4] == 0xB4);
|
||||
BOOST_REQUIRE(negative_larger[5] == 0x7C);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user