mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into breaking
This commit is contained in:
@@ -29,6 +29,7 @@ detect_stray_source_files("${contracts_sources}" "contracts/")
|
||||
set(libsolutil_sources
|
||||
libsolutil/Checksum.cpp
|
||||
libsolutil/CommonData.cpp
|
||||
libsolutil/FixedHash.cpp
|
||||
libsolutil/IndentedWriter.cpp
|
||||
libsolutil/IpfsHash.cpp
|
||||
libsolutil/IterateReplacing.cpp
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace po = boost::program_options;
|
||||
namespace solidity::test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/// If non-empty returns the value of the env. variable ETH_TEST_PATH, otherwise
|
||||
/// it tries to find a path that contains the directories "libsolidity/syntaxTests"
|
||||
/// and returns it if found.
|
||||
@@ -84,6 +87,8 @@ std::string envOrDefaultPath(std::string const& env_name, std::string const& lib
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CommonOptions::CommonOptions(std::string _caption):
|
||||
options(_caption,
|
||||
po::options_description::m_default_line_length,
|
||||
|
||||
@@ -148,6 +148,10 @@ void initializeOptions()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Prototype -- why isn't this declared in the boost headers?
|
||||
// TODO: replace this with a (global) fixture.
|
||||
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] );
|
||||
|
||||
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
|
||||
{
|
||||
master_test_suite_t& master = framework::master_test_suite();
|
||||
|
||||
@@ -206,7 +206,7 @@ function test_solc_assembly_output()
|
||||
local expected_object="object \"object\" { code "${expected}" }"
|
||||
|
||||
output=$(echo "${input}" | "$SOLC" - ${solc_args} 2>/dev/null)
|
||||
empty=$(echo $output | sed -ne '/'"${expected_object}"'/p')
|
||||
empty=$(echo "$output" | tr '\n' ' ' | tr -s ' ' | sed -ne "/${expected_object}/p")
|
||||
if [ -z "$empty" ]
|
||||
then
|
||||
printError "Incorrect assembly output. Expected: "
|
||||
@@ -436,15 +436,18 @@ SOLTMPDIR=$(mktemp -d)
|
||||
# The contract should be compiled
|
||||
if [[ "$result" != 0 ]]
|
||||
then
|
||||
printError "Failed to compile a simple contract from standard input"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This should not fail
|
||||
set +e
|
||||
output=$(echo '' | "$SOLC" --ast - 2>/dev/null)
|
||||
output=$(echo '' | "$SOLC" --ast-json - 2>/dev/null)
|
||||
result=$?
|
||||
set -e
|
||||
if [[ $? != 0 ]]
|
||||
if [[ $result != 0 ]]
|
||||
then
|
||||
printError "Incorrect response to --ast-json option with empty stdin"
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
|
||||
@@ -19,4 +19,4 @@ target_sources(evmc INTERFACE
|
||||
${PROJECT_SOURCE_DIR}/test/evmc/utils.h
|
||||
)
|
||||
target_include_directories(evmc INTERFACE ${PROJECT_SOURCE_DIR}/test/)
|
||||
target_link_libraries(evmc INTERFACE evmc_loader)
|
||||
target_link_libraries(evmc INTERFACE evmc_loader)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
## Solidity external tests
|
||||
This directory contains scripts for compiling some of the popular open-source projects using the
|
||||
current version of the compiler and running their test suites.
|
||||
|
||||
Since projects often do not use the latest compiler, we keep a fork of each of these projects
|
||||
at https://github.com/solidity-external-tests/. If changes are needed to make a project work with the
|
||||
latest version of the compiler, they are maintained as a branch on top of the upstream master branch.
|
||||
This is especially important for testing our `breaking` branch because we can not realistically expect
|
||||
external projects to be instantly compatible with a compiler version that has not been released yet.
|
||||
Applying necessary changes ourselves gives us confidence that breaking changes are sane and that
|
||||
these projects *can* be upgraded at all.
|
||||
|
||||
### Recommended workflow
|
||||
|
||||
#### Adding a new external project
|
||||
1. Create a fork of the upstream repository in https://github.com/solidity-external-tests/. If the
|
||||
project consists of several repositories, fork them all.
|
||||
2. Remove all the branches except for main one (`master`, `develop`, `main`, etc). This branch is
|
||||
going to be always kept up to date with the upstream repository and should not contain any extra
|
||||
commits.
|
||||
- If the project is not up to date with the latest compiler version but has a branch that is,
|
||||
try to use that branch instead.
|
||||
3. Create a new branch named after the main branch and the compiler version from our `develop`
|
||||
branch. E.g. if the latest Solidity version is 0.7.5 and the main branch of the external project
|
||||
is called `master`, create `master_070`. This is where we will be adding our own commits.
|
||||
4. Create a script for compiling/testing the project and put it in `test/externalTests/` in the
|
||||
Solidity repository.
|
||||
- The script should apply workarounds necessary to make the project actually use the compiler
|
||||
binary it receives as a parameter and possibly add generic workarounds that should
|
||||
work across different versions of the upstream project.
|
||||
- Very specific workarounds that may easily break with every upstream change are better done as
|
||||
commits in the newly added branch in the fork instead.
|
||||
5. List the script in `test/externalTests.sh`.
|
||||
6. Add the script to CircleCI configuration. Make sure to add both a compilation-only run and one that
|
||||
also executes the test suite. If the latter takes a significant amount of time (say, more than
|
||||
15 minutes) make it run nightly rather than on every PR.
|
||||
7. Make sure that tests pass both on `develop` and on `breaking`. If the compiler from `breaking`
|
||||
branch will not work without additional changes, add another branch, called after it in turn,
|
||||
and add necessary workarounds there. Continuing the example above, the new branch would be
|
||||
called `master_080` and should be rebased on top of `master_070`.
|
||||
- The fewer commits in these branches, the better. Ideally, any changes needed to make the compiler
|
||||
work should be submitted upstream and our branches should just be tracking the main upstream
|
||||
branch without any extra commits.
|
||||
|
||||
#### Updating external projects for a PR that introduces breaking changes in the compiler
|
||||
If a PR to our `breaking` branch introduces changes that will make an external project no longer
|
||||
compile or pass its tests, the fork needs to be modified:
|
||||
- If a branch specific to the compiler version from `breaking` does not exist yet:
|
||||
1. Create the branch. It should be based on the version-specific branch used on `develop`.
|
||||
2. Make your PR modify the project script in `test/externalScripts/` to use the new branch.
|
||||
3. You are free to add any changes you need in the new branch since it will not interfere with
|
||||
tests on `breaking`.
|
||||
4. Work on your PR until it is approved and merged into `breaking`.
|
||||
- If the branch already exists and our CI depends on it:
|
||||
1. If the external project after your changes can still work with `breaking` even without your PR or
|
||||
if you know that the PR is straightforward and will be merged immediately without interfering
|
||||
with tests on `breaking` for a significant amount of time, you can just push your modifications
|
||||
to the branch directly and skip straight to steps 4. and 6.
|
||||
2. Create a PR in the fork, targeting the existing version-specific branch.
|
||||
3. In your PR to `breaking`, modify the corresponding script in `test/externalScripts/` to
|
||||
use the branch from your PR in the fork.
|
||||
4. Work on your PR until it is approved and ready to merge.
|
||||
5. Merge the PR in the fork.
|
||||
6. Discard your changes to the script and merge your PR into `breaking`.
|
||||
|
||||
#### Pulling upstream changes into a fork
|
||||
1. Pull changes directly into the main branch in the fork. This should be straightforward thanks to
|
||||
it not containing any of our customizations.
|
||||
2. If the project has been updated to a newer Solidity version, abandon the current version-specific
|
||||
branch used on `develop` (but do not delete it) and create a new one corresponding to the newer
|
||||
version. Then update project script in `test/externalTests/` to use the new branch. E.g. if `develop` uses
|
||||
`master_050` and the project has been updated to use Solidity 0.7.3, create `master_070`.
|
||||
3. Otherwise, rebase the current version-specific branch on the main branch of the fork. This may require
|
||||
tweaking some of the commits to apply our fixes in new places.
|
||||
4. If we have a separate branch for `breaking`, rebase it on top of the one used on `develop`.
|
||||
|
||||
The above is the workflow to use when the update is straightforward and looks safe. In that case it is
|
||||
fine to just modify the branches directly. If this is not the case, it is recommended to first perform the
|
||||
operation on copies of these version-specific branches and test them by creating PRs on `develop` and
|
||||
`breaking` to see if tests pass. The PRs should just modify project scripts in `test/externalScripts/`
|
||||
to use the updated copies of the branches and can be discarded aferwards without being merged.
|
||||
|
||||
#### Changes needed after a breaking release of the compiler
|
||||
When a non-backwards-compatible version becomes the most recent release, `breaking` branch
|
||||
gets merged into `develop` which automatically results in a switch to the newer version-specific
|
||||
branches if they exist. If no changes on our part were necessary, it is completely fine to keep using
|
||||
e.g. the `master_060` of an external project in in Solidity 0.8.x.
|
||||
|
||||
Since each project is handled separately, this approach may result in a mix of version-specific branches
|
||||
between different external projects. For example, in one project we could could have `master_050` on
|
||||
both `develop` and `breaking` and in another `breaking` could use `master_080` while `develop` still
|
||||
uses `master_060`.
|
||||
@@ -257,7 +257,7 @@ void ASTJSONTest::printSource(ostream& _stream, string const& _linePrefix, bool
|
||||
for (auto const& source: m_sources)
|
||||
{
|
||||
if (m_sources.size() > 1 || source.first != "a")
|
||||
_stream << _linePrefix << sourceDelimiter << source.first << endl << endl;
|
||||
_stream << _linePrefix << sourceDelimiter << source.first << " ====" << endl << endl;
|
||||
stringstream stream(source.second);
|
||||
string line;
|
||||
while (getline(stream, line))
|
||||
|
||||
@@ -91,7 +91,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
||||
);
|
||||
compiler.compileContract(*contract, map<ContractDefinition const*, shared_ptr<Compiler const>>{}, bytes());
|
||||
|
||||
return compiler.runtimeAssemblyItems();
|
||||
return compiler.runtimeAssembly().items();
|
||||
}
|
||||
BOOST_FAIL("No contract found in source.");
|
||||
return AssemblyItems();
|
||||
|
||||
@@ -38,6 +38,9 @@ namespace solidity::frontend::test
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(SemVerMatcher)
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
SemVerMatchExpression parseExpression(string const& _input)
|
||||
{
|
||||
Scanner scanner{CharStream(_input, "")};
|
||||
@@ -62,6 +65,8 @@ SemVerMatchExpression parseExpression(string const& _input)
|
||||
return expression;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_range)
|
||||
{
|
||||
// Positive range tests
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <libsolidity/ast/TypeProvider.h>
|
||||
#include <libsolidity/analysis/TypeChecker.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
#include <test/Common.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@@ -161,7 +162,10 @@ bytes compileFirstExpression(
|
||||
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(
|
||||
resolveDeclaration(*sourceUnit, function, resolver)
|
||||
));
|
||||
bytes instructions = context.assembledObject().bytecode;
|
||||
BOOST_REQUIRE(context.assemblyPtr());
|
||||
LinkerObject const& object = context.assemblyPtr()->assemble();
|
||||
BOOST_REQUIRE(object.immutableReferences.empty());
|
||||
bytes instructions = object.bytecode;
|
||||
// debug
|
||||
// cout << evmasm::disassemble(instructions) << endl;
|
||||
return instructions;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
contract c {
|
||||
bytes a;
|
||||
bytes b;
|
||||
function f(uint len) public returns (bytes memory) {
|
||||
bytes memory x = new bytes(len);
|
||||
for (uint i = 0; i < len; i++)
|
||||
x[i] = byte(uint8(i));
|
||||
a = x;
|
||||
for (uint i = 0; i < len; i++)
|
||||
assert(a[i] == x[i]);
|
||||
b = a;
|
||||
for (uint i = 0; i < len; i++)
|
||||
assert(b[i] == x[i]);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256): 0 -> 0x20, 0x00
|
||||
// f(uint256): 31 -> 0x20, 0x1f, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00
|
||||
// f(uint256): 32 -> 0x20, 0x20, 1780731860627700044960722568376592200742329637303199754547598369979440671
|
||||
// f(uint256): 33 -> 0x20, 33, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x2000000000000000000000000000000000000000000000000000000000000000
|
||||
// f(uint256): 63 -> 0x20, 0x3f, 1780731860627700044960722568376592200742329637303199754547598369979440671, 14532552714582660066924456880521368950258152170031413196862950297402215316992
|
||||
// f(uint256): 12 -> 0x20, 0x0c, 0x0102030405060708090a0b0000000000000000000000000000000000000000
|
||||
// f(uint256): 129 -> 0x20, 0x81, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f, 29063324697304692433803953038474361308315562010425523193971352996434451193439, 0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f, -57896044618658097711785492504343953926634992332820282019728792003956564819968
|
||||
@@ -9,3 +9,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (112-115): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
|
||||
@@ -11,4 +11,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (112-115): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 2529: (150-157): CHC: Empty array "pop" happens here.\nCounterexample:\na = []\nl = 0\n\n\nTransaction trace:\nconstructor()\nState: a = []\nf(0)
|
||||
|
||||
+2
@@ -11,3 +11,5 @@ contract C {
|
||||
assert(x[0] == 42);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (174-177): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract C {
|
||||
uint8 x;
|
||||
|
||||
function inc_pre() public {
|
||||
++x;
|
||||
}
|
||||
|
||||
function dec_pre() public {
|
||||
--x;
|
||||
}
|
||||
|
||||
/* Commented out because Spacer segfaults in Z3 4.8.9
|
||||
function inc_post() public {
|
||||
x++;
|
||||
}
|
||||
|
||||
function dec_post() public {
|
||||
x--;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
// ====
|
||||
// SMTEngine: bmc
|
||||
// ----
|
||||
// Warning 2661: (87-90): BMC: Overflow (resulting value larger than 255) happens here.
|
||||
// Warning 4144: (127-130): BMC: Underflow (resulting value less than 0) happens here.
|
||||
@@ -19,4 +19,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2661: (158-161): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -23,4 +23,3 @@ contract C {
|
||||
// Warning 6328: (274-300): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 6328: (304-330): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 6328: (334-362): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 2661: (158-161): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -28,4 +28,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2661: (188-191): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -38,4 +38,3 @@ contract C {
|
||||
// Warning 6328: (437-458): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (462-490): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (494-517): CHC: Assertion violation happens here.
|
||||
// Warning 2661: (188-191): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -18,5 +18,6 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (189-203): CHC: Assertion violation happens here.\nCounterexample:\nx = 10, d = 0\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0, d = 0\ninc()\nState: x = 1, d = 0\ninc()\nState: x = 2, d = 0\nf()
|
||||
// Warning 4984: (146-149): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 6328: (189-203): CHC: Assertion violation happens here.\nCounterexample:\nx = 10, d = 0\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0, d = 0\ninc()\nState: x = 1, d = 0\nf()
|
||||
// Warning 2661: (146-149): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -16,3 +16,6 @@ contract C {
|
||||
assert(x < 11);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (200-214): CHC: Assertion violation might happen here.
|
||||
// Warning 4661: (200-214): BMC: Assertion violation happens here.
|
||||
|
||||
@@ -21,5 +21,3 @@ contract C{
|
||||
}
|
||||
// ----
|
||||
// Warning 5667: (70-76): Unused function parameter. Remove or comment out the variable name to silence this warning.
|
||||
// Warning 2661: (156-159): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (238-241): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
@@ -26,5 +26,3 @@ contract C{
|
||||
// Warning 6328: (220-234): CHC: Assertion violation happens here.\nCounterexample:\nx = 2\n\n\n\nTransaction trace:\nconstructor(0)\nState: x = 1\nf()
|
||||
// Warning 6328: (245-259): CHC: Assertion violation happens here.\nCounterexample:\nx = 1\n\n\n\nTransaction trace:\nconstructor(0)\nState: x = 1\nf()
|
||||
// Warning 6328: (82-96): CHC: Assertion violation happens here.\nCounterexample:\nx = 0\ny = 0\n\n\nTransaction trace:\nconstructor(0)
|
||||
// Warning 2661: (156-159): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (238-241): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
-2
@@ -17,5 +17,3 @@ contract C is A {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4144: (100-103): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 4144: (100-103): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
-2
@@ -20,5 +20,3 @@ contract C is A {
|
||||
// Warning 6328: (82-96): CHC: Assertion violation happens here.\nCounterexample:\nx = 1\n\n\n\nTransaction trace:\nconstructor()
|
||||
// Warning 6328: (148-162): CHC: Assertion violation happens here.\nCounterexample:\nx = 0\n\n\n\nTransaction trace:\nconstructor()
|
||||
// Warning 6328: (180-194): CHC: Assertion violation happens here.\nCounterexample:\nx = 0\n\n\n\nTransaction trace:\nconstructor()
|
||||
// Warning 4144: (100-103): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 4144: (100-103): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
-4
@@ -21,7 +21,3 @@ contract C{
|
||||
}
|
||||
// ----
|
||||
// Warning 5667: (70-76): Unused function parameter. Remove or comment out the variable name to silence this warning.
|
||||
// Warning 2661: (156-159): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (163-166): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (234-237): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (234-237): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
-4
@@ -24,7 +24,3 @@ contract C{
|
||||
// Warning 6328: (138-152): CHC: Assertion violation happens here.\nCounterexample:\nx = 1\n\n\n\nTransaction trace:\nconstructor(0)\nState: x = 1\nf()
|
||||
// Warning 6328: (184-198): CHC: Assertion violation happens here.\nCounterexample:\nx = 1\n\n\n\nTransaction trace:\nconstructor(0)\nState: x = 1\nf()
|
||||
// Warning 6328: (82-96): CHC: Assertion violation happens here.\nCounterexample:\nx = 0\ny = 0\n\n\nTransaction trace:\nconstructor(0)
|
||||
// Warning 2661: (156-159): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (163-166): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (234-237): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (234-237): BMC: Underflow (resulting value less than 0) happens here.
|
||||
|
||||
@@ -20,6 +20,7 @@ contract Der is Base {
|
||||
// ----
|
||||
// Warning 4984: (der:101-109): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 6328: (der:113-126): CHC: Assertion violation happens here.\nCounterexample:\nx = 3, a = 0\ny = 0\n\n\nTransaction trace:\nconstructor()\nState: x = 0, a = 0\ng(0)
|
||||
// Warning 4984: (base:100-103): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 2661: (base:100-103): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (der:101-109): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 2661: (base:100-103): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -11,3 +11,5 @@ contract Simple {
|
||||
}
|
||||
// ====
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning 4984: (132-135): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
|
||||
@@ -9,3 +9,5 @@ contract Simple {
|
||||
}
|
||||
// ====
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning 4984: (116-119): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
|
||||
@@ -15,4 +15,4 @@ contract C
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning 5740: (120-123): Unreachable code.
|
||||
// Warning 6328: (131-145): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 1\n\n\nTransaction trace:\nconstructor()\nf(1)
|
||||
// Warning 6328: (131-145): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 3\n\n\nTransaction trace:\nconstructor()\nf(3)
|
||||
|
||||
+2
-1
@@ -18,9 +18,10 @@ contract LoopFor2 {
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// SMTSolvers: z3
|
||||
// SMTIgnoreCex: yes
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning 4984: (244-249): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 4984: (270-273): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 6328: (373-392): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (396-415): CHC: Assertion violation happens here.
|
||||
|
||||
@@ -26,3 +26,4 @@ contract LoopFor2 {
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning 4984: (237-242): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 4984: (263-266): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
|
||||
@@ -21,5 +21,6 @@ contract LoopFor2 {
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (229-234): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 4984: (255-258): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
|
||||
// Warning 6328: (338-357): CHC: Assertion violation happens here.\nCounterexample:\nb = [], c = []\nn = 1\n\n\nTransaction trace:\nconstructor()\nState: b = [], c = []\ntestUnboundedForLoop(1)
|
||||
// Warning 6328: (361-380): CHC: Assertion violation happens here.\nCounterexample:\nb = [], c = []\nn = 1\n\n\nTransaction trace:\nconstructor()\nState: b = [], c = []\ntestUnboundedForLoop(1)
|
||||
|
||||
@@ -7,7 +7,7 @@ contract A {
|
||||
A.y = A.x++;
|
||||
assert(A.y == A.x - 1);
|
||||
// Fails
|
||||
assert(A.y == 0);
|
||||
// assert(A.y == 0); // Disabled because of nondeterminism in Spacer
|
||||
A.y = ++A.x;
|
||||
assert(A.y == A.x);
|
||||
delete A.x;
|
||||
@@ -25,6 +25,7 @@ contract A {
|
||||
assert(A.y == A.x);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// SMTIgnoreCex: yes
|
||||
// ----
|
||||
// Warning 6328: (160-176): CHC: Assertion violation happens here.\nCounterexample:\nx = (- 1), y = (- 2)\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0, y = 0\na()\nState: x = (- 2), y = (- 2)\na()
|
||||
// Warning 6328: (373-389): CHC: Assertion violation happens here.\nCounterexample:\nx = 8, y = (- 2)\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0, y = 0\na()
|
||||
// Warning 6328: (424-440): CHC: Assertion violation happens here.
|
||||
|
||||
@@ -10,4 +10,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (161-174): CHC: Assertion violation happens here.\nCounterexample:\n\na = 6\nb = 5\n\n\nTransaction trace:\nconstructor()\nf(5, 5)
|
||||
// Warning 6328: (161-174): CHC: Assertion violation happens here.\nCounterexample:\n\na = 0\nb = 1\n\n\nTransaction trace:\nconstructor()\nf(0, 0)
|
||||
|
||||
@@ -10,3 +10,6 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (129-134): CHC: Overflow (resulting value larger than 2**256 - 1) happens here.\nCounterexample:\na = 115792089237316195423570985008687907853269984665640564039457584007913129639935, b = false\n\nc = 0\n\nTransaction trace:\nconstructor()\nState: a = 0, b = false\nf()\nState: a = 115792089237316195423570985008687907853269984665640564039457584007913129639935, b = false\nf()
|
||||
// Warning 3944: (137-140): CHC: Underflow (resulting value less than 0) happens here.\nCounterexample:\na = 0, b = false\n\nc = 0\n\nTransaction trace:\nconstructor()\nState: a = 0, b = false\nf()
|
||||
// Warning 6328: (150-163): CHC: Assertion violation happens here.\nCounterexample:\na = 115792089237316195423570985008687907853269984665640564039457584007913129639935, b = false\n\nc = 0\n\nTransaction trace:\nconstructor()\nState: a = 0, b = false\nf()
|
||||
|
||||
@@ -15,4 +15,4 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (240-253): CHC: Assertion violation happens here.\nCounterexample:\narray = []\nx = 38\n\n\nTransaction trace:\nconstructor()\nState: array = []\nf(38)
|
||||
// Warning 6328: (240-253): CHC: Assertion violation happens here.
|
||||
|
||||
@@ -14,5 +14,7 @@ contract C
|
||||
assert(b < 3);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// SMTIgnoreCex: yes
|
||||
// ----
|
||||
// Warning 6328: (244-257): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 38\n\n\nTransaction trace:\nconstructor()\nf(38)
|
||||
// Warning 6328: (244-257): CHC: Assertion violation happens here.
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract C {
|
||||
uint8 x;
|
||||
|
||||
function inc_pre() public {
|
||||
++x;
|
||||
}
|
||||
|
||||
function dec_pre() public {
|
||||
--x;
|
||||
}
|
||||
|
||||
/* Commented out because Spacer segfaults in Z3 4.8.9
|
||||
function inc_post() public {
|
||||
x++;
|
||||
}
|
||||
|
||||
function dec_post() public {
|
||||
x--;
|
||||
}
|
||||
*/
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (87-90): CHC: Overflow (resulting value larger than 255) happens here.\nCounterexample:\nx = 255\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0\ndec_pre()\nState: x = 255\ninc_pre()
|
||||
// Warning 3944: (127-130): CHC: Underflow (resulting value less than 0) happens here.\nCounterexample:\nx = 0\n\n\n\nTransaction trace:\nconstructor()\nState: x = 0\ndec_pre()
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint8 x = 254;
|
||||
|
||||
function inc_pre() public {
|
||||
++x;
|
||||
}
|
||||
|
||||
function check() view public {
|
||||
uint y = x;
|
||||
assert(y < 256);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (94-97): CHC: Overflow (resulting value larger than 255) happens here.\nCounterexample:\nx = 255\n\n\n\nTransaction trace:\nconstructor()\nState: x = 254\ninc_pre()\nState: x = 255\ninc_pre()
|
||||
@@ -0,0 +1,24 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint8 x;
|
||||
}
|
||||
|
||||
S s;
|
||||
|
||||
constructor() {
|
||||
s.x = 254;
|
||||
}
|
||||
|
||||
function inc_pre() public {
|
||||
++s.x;
|
||||
}
|
||||
|
||||
function check() view public {
|
||||
uint y = s.x;
|
||||
assert(y < 256);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4984: (145-150): CHC: Overflow (resulting value larger than 255) happens here.\nCounterexample:\ns = {x: 255}\n\n\n\nTransaction trace:\nconstructor()\nState: s = {x: 254}\ninc_pre()\nState: s = {x: 255}\ninc_pre()
|
||||
@@ -15,4 +15,4 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (240-253): CHC: Assertion violation happens here.\nCounterexample:\narray = []\nx = 38\n\n\nTransaction trace:\nconstructor()\nState: array = []\nf(38)
|
||||
// Warning 6328: (240-253): CHC: Assertion violation happens here.\nCounterexample:\narray = []\nx = 0\n\n\nTransaction trace:\nconstructor()\nState: array = []\nf(0)
|
||||
|
||||
@@ -15,4 +15,4 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (244-257): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 38\n\n\nTransaction trace:\nconstructor()\nf(38)
|
||||
// Warning 6328: (244-257): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 0\n\n\nTransaction trace:\nconstructor()\nf(0)
|
||||
|
||||
@@ -52,6 +52,10 @@ contract C {
|
||||
// Warning 8364: (258-260): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning 7650: (271-275): Assertion checker does not yet support this expression.
|
||||
// Warning 8364: (271-273): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning 4984: (132-138): CHC: Overflow (resulting value larger than 2**256 - 1) happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 4984: (142-148): CHC: Overflow (resulting value larger than 2**256 - 1) happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 3944: (165-171): CHC: Underflow (resulting value less than 0) happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 3944: (175-181): CHC: Underflow (resulting value less than 0) happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 4984: (200-208): CHC: Overflow (resulting value larger than 2**256 - 1) happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 6328: (185-209): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
// Warning 6328: (213-247): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nf()
|
||||
@@ -87,11 +91,3 @@ contract C {
|
||||
// Warning 8364: (258-260): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning 7650: (271-275): Assertion checker does not yet support this expression.
|
||||
// Warning 8364: (271-273): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning 4144: (132-138): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 2661: (132-138): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (142-148): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 2661: (142-148): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (165-171): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 2661: (165-171): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4144: (175-181): BMC: Underflow (resulting value less than 0) happens here.
|
||||
// Warning 2661: (175-181): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
|
||||
@@ -15,4 +15,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (225-245): CHC: Assertion violation happens here.\nCounterexample:\n\ns1 = {x: 2, a: []}\ns2 = {x: 3, a: [5, 5, 5, 5, 5, 5]}\n\n\nTransaction trace:\nconstructor()\nf({x: 0, a: []}, {x: 3, a: [5, 5, 5, 5, 5, 5]})
|
||||
// Warning 6328: (225-245): CHC: Assertion violation happens here.\nCounterexample:\n\ns1 = {x: 2, a: []}\ns2 = {x: 3, a: [6, 6, 6, 6, 6, 6, 6]}\n\n\nTransaction trace:\nconstructor()\nf({x: 0, a: []}, {x: 3, a: [6, 6, 6, 6, 6, 6, 6]})
|
||||
|
||||
@@ -16,4 +16,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (240-260): CHC: Assertion violation happens here.\nCounterexample:\n\ns1 = {x: 98, a: []}\ns2 = {x: (- 38), a: [5, 5, 5, 5, 5, 5]}\n\n\nTransaction trace:\nconstructor()\nf({x: 0, a: []}, {x: (- 38), a: [5, 5, 5, 5, 5, 5]})
|
||||
// Warning 6328: (240-260): CHC: Assertion violation happens here.\nCounterexample:\n\ns1 = {x: 98, a: []}\ns2 = {x: 99, a: [6, 6, 6, 6, 6, 6, 6]}\n\n\nTransaction trace:\nconstructor()\nf({x: 0, a: []}, {x: 99, a: [6, 6, 6, 6, 6, 6, 6]})
|
||||
|
||||
@@ -12,6 +12,7 @@ contract C {
|
||||
if(x == 0) x = 0; // noop state var read
|
||||
x++;
|
||||
y++;
|
||||
assert(y == x);
|
||||
// Commented out because of nondeterminism in Spacer in Z3 4.8.9
|
||||
//assert(y == x);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,4 +22,4 @@ contract Test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (B:269-313): Type function (struct L.Item memory) is not implicitly convertible to expected type function (struct L.Item memory) external.
|
||||
// TypeError 9574: (B:269-313): Type function (struct L.Item memory) is not implicitly convertible to expected type function (struct L.Item memory) external. Special functions can not be converted to function types.
|
||||
|
||||
@@ -30,6 +30,6 @@ contract E {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (140-143): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested.
|
||||
// TypeError 9553: (230-233): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested.
|
||||
// TypeError 9553: (345-348): Invalid type for argument in function call. Invalid implicit conversion from function D.f() to function () external requested.
|
||||
// TypeError 9553: (140-143): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested. Special functions can not be converted to function types.
|
||||
// TypeError 9553: (230-233): Invalid type for argument in function call. Invalid implicit conversion from function () to function () external requested. Special functions can not be converted to function types.
|
||||
// TypeError 9553: (345-348): Invalid type for argument in function call. Invalid implicit conversion from function D.f() to function () external requested. Special functions can not be converted to function types.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
library L {
|
||||
function foo(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
contract C {
|
||||
using L for uint256;
|
||||
|
||||
function bar() public {
|
||||
uint256 x;
|
||||
function (uint256, uint256) internal pure returns (uint256) ptr = x.foo;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (209-280): Type function (uint256,uint256) pure returns (uint256) is not implicitly convertible to expected type function (uint256,uint256) pure returns (uint256). Bound functions can not be converted to non-bound functions.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
function (uint) view returns (bytes32) _blockhash = blockhash;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (42-103): Type function (uint256) view returns (bytes32) is not implicitly convertible to expected type function (uint256) view returns (bytes32). Special functions can not be converted to function types.
|
||||
+2
-2
@@ -10,5 +10,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (230-233): Invalid type for argument in function call. Invalid implicit conversion from function (uint256) returns (uint256) to function (uint256) external returns (uint256) requested.
|
||||
// TypeError 9574: (244-305): Type function (uint256) returns (uint256) is not implicitly convertible to expected type function (uint256) external returns (uint256).
|
||||
// TypeError 9553: (230-233): Invalid type for argument in function call. Invalid implicit conversion from function (uint256) returns (uint256) to function (uint256) external returns (uint256) requested. Special functions can not be converted to function types.
|
||||
// TypeError 9574: (244-305): Type function (uint256) returns (uint256) is not implicitly convertible to expected type function (uint256) external returns (uint256). Special functions can not be converted to function types.
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ contract test {
|
||||
function(bytes memory) external internal a = fa;
|
||||
}
|
||||
// ----
|
||||
// TypeError 7407: (106-108): Type function (bytes memory) is not implicitly convertible to expected type function (bytes memory) external.
|
||||
// TypeError 7407: (106-108): Type function (bytes memory) is not implicitly convertible to expected type function (bytes memory) external. Special functions can not be converted to function types.
|
||||
|
||||
@@ -9,5 +9,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (218-271): Type function (struct D.s storage pointer,uint256) returns (uint256) is not implicitly convertible to expected type function (struct D.s storage pointer,uint256) returns (uint256).
|
||||
// TypeError 9574: (218-271): Type function (struct D.s storage pointer,uint256) returns (uint256) is not implicitly convertible to expected type function (struct D.s storage pointer,uint256) returns (uint256). Bound functions can not be converted to non-bound functions.
|
||||
// TypeError 6160: (298-302): Wrong argument count for function call: 1 arguments given but expected 2.
|
||||
|
||||
+2
-2
@@ -10,5 +10,5 @@ contract B is A {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (133-160): Type function A.f() is not implicitly convertible to expected type function () external.
|
||||
// TypeError 9574: (170-202): Type function A.g() pure is not implicitly convertible to expected type function () pure external.
|
||||
// TypeError 9574: (133-160): Type function A.f() is not implicitly convertible to expected type function () external. Special functions can not be converted to function types.
|
||||
// TypeError 9574: (170-202): Type function A.g() pure is not implicitly convertible to expected type function () pure external. Special functions can not be converted to function types.
|
||||
|
||||
+2
-2
@@ -10,5 +10,5 @@ contract B {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (128-155): Type function A.f() is not implicitly convertible to expected type function () external.
|
||||
// TypeError 9574: (165-197): Type function A.g() pure is not implicitly convertible to expected type function () pure external.
|
||||
// TypeError 9574: (128-155): Type function A.f() is not implicitly convertible to expected type function () external. Special functions can not be converted to function types.
|
||||
// TypeError 9574: (165-197): Type function A.g() pure is not implicitly convertible to expected type function () pure external. Special functions can not be converted to function types.
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace solidity::frontend::test
|
||||
using fmt = ExecutionFramework;
|
||||
using Mode = FunctionCall::DisplayMode;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
vector<FunctionCall> parse(string const& _source)
|
||||
{
|
||||
istringstream stream{_source, ios_base::out};
|
||||
@@ -86,6 +89,8 @@ void testFunctionCall(
|
||||
BOOST_REQUIRE_EQUAL(_call.kind == FunctionCall::Kind::Library, _isLibrary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestFileParserTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(smoke_test)
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
/**
|
||||
* Unit tests for FixedHash.
|
||||
*/
|
||||
|
||||
#include <libsolutil/FixedHash.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace solidity::util::test
|
||||
{
|
||||
|
||||
static_assert(std::is_same<h160, FixedHash<20>>());
|
||||
static_assert(std::is_same<h256, FixedHash<32>>());
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(FixedHashTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(default_constructor)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<1>{}.hex(),
|
||||
"00"
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<1>{}.size,
|
||||
1
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<8>{}.hex(),
|
||||
"0000000000000000"
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<8>{}.size,
|
||||
8
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<20>{}.hex(),
|
||||
"0000000000000000000000000000000000000000"
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<20>{}.size,
|
||||
20
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<32>{}.hex(),
|
||||
"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
);
|
||||
BOOST_CHECK_EQUAL(
|
||||
FixedHash<32>{}.size,
|
||||
32
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bytes_constructor)
|
||||
{
|
||||
FixedHash<8> a(bytes{});
|
||||
BOOST_CHECK_EQUAL(a.size, 8);
|
||||
BOOST_CHECK_EQUAL(a.hex(), "0000000000000000");
|
||||
|
||||
FixedHash<8> b(bytes{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88});
|
||||
BOOST_CHECK_EQUAL(b.size, 8);
|
||||
BOOST_CHECK_EQUAL(b.hex(), "1122334455667788");
|
||||
|
||||
// TODO: short input, this should fail
|
||||
FixedHash<8> c(bytes{0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
|
||||
BOOST_CHECK_EQUAL(c.size, 8);
|
||||
BOOST_CHECK_EQUAL(c.hex(), "0000000000000000");
|
||||
|
||||
// TODO: oversized input, this should fail
|
||||
FixedHash<8> d(bytes{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99});
|
||||
BOOST_CHECK_EQUAL(d.size, 8);
|
||||
BOOST_CHECK_EQUAL(d.hex(), "0000000000000000");
|
||||
}
|
||||
|
||||
// TODO: add FixedHash(bytesConstRef) constructor
|
||||
|
||||
BOOST_AUTO_TEST_CASE(string_constructor_fromhex)
|
||||
{
|
||||
// TODO: this tests the default settings ConstructFromStringType::fromHex, ConstructFromHashType::FailIfDifferent
|
||||
// should test other options too
|
||||
|
||||
FixedHash<8> a("");
|
||||
BOOST_CHECK_EQUAL(a.size, 8);
|
||||
BOOST_CHECK_EQUAL(a.hex(), "0000000000000000");
|
||||
|
||||
FixedHash<8> b("1122334455667788");
|
||||
BOOST_CHECK_EQUAL(b.size, 8);
|
||||
BOOST_CHECK_EQUAL(b.hex(), "1122334455667788");
|
||||
|
||||
FixedHash<8> c("0x1122334455667788");
|
||||
BOOST_CHECK_EQUAL(c.size, 8);
|
||||
BOOST_CHECK_EQUAL(c.hex(), "1122334455667788");
|
||||
|
||||
// TODO: short input, this should fail
|
||||
FixedHash<8> d("112233445566");
|
||||
BOOST_CHECK_EQUAL(d.size, 8);
|
||||
BOOST_CHECK_EQUAL(d.hex(), "0000000000000000");
|
||||
|
||||
// TODO: oversized input, this should fail
|
||||
FixedHash<8> e("112233445566778899");
|
||||
BOOST_CHECK_EQUAL(e.size, 8);
|
||||
BOOST_CHECK_EQUAL(e.hex(), "0000000000000000");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(string_constructor_frombytes)
|
||||
{
|
||||
|
||||
FixedHash<8> b("", FixedHash<8>::FromBinary);
|
||||
BOOST_CHECK_EQUAL(b.size, 8);
|
||||
BOOST_CHECK_EQUAL(b.hex(), "0000000000000000");
|
||||
|
||||
FixedHash<8> c("abcdefgh", FixedHash<8>::FromBinary);
|
||||
BOOST_CHECK_EQUAL(c.size, 8);
|
||||
BOOST_CHECK_EQUAL(c.hex(), "6162636465666768");
|
||||
|
||||
// TODO: short input, this should fail
|
||||
FixedHash<8> d("abcdefg", FixedHash<8>::FromBinary);
|
||||
BOOST_CHECK_EQUAL(d.size, 8);
|
||||
BOOST_CHECK_EQUAL(d.hex(), "0000000000000000");
|
||||
|
||||
// TODO: oversized input, this should fail
|
||||
FixedHash<8> e("abcdefghi", FixedHash<8>::FromBinary);
|
||||
BOOST_CHECK_EQUAL(e.size, 8);
|
||||
BOOST_CHECK_EQUAL(e.hex(), "0000000000000000");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(converting_constructor)
|
||||
{
|
||||
// Truncation
|
||||
FixedHash<8> a = FixedHash<8>(FixedHash<12>("112233445566778899001122"));
|
||||
BOOST_CHECK_EQUAL(a.size, 8);
|
||||
BOOST_CHECK_EQUAL(a.hex(), "1122334455667788");
|
||||
|
||||
// Left-aligned extension
|
||||
FixedHash<12> b = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignLeft);
|
||||
BOOST_CHECK_EQUAL(b.size, 12);
|
||||
BOOST_CHECK_EQUAL(b.hex(), "112233445566778800000000");
|
||||
|
||||
// Right-aligned extension
|
||||
FixedHash<12> c = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignRight);
|
||||
BOOST_CHECK_EQUAL(c.size, 12);
|
||||
BOOST_CHECK_EQUAL(c.hex(), "000000001122334455667788");
|
||||
|
||||
// Default setting
|
||||
FixedHash<12> d = FixedHash<12>(FixedHash<8>("1122334455667788"));
|
||||
BOOST_CHECK_EQUAL(d, b);
|
||||
|
||||
// FailIfDifferent setting
|
||||
// TODO: Shouldn't this throw?
|
||||
FixedHash<12> e = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::FailIfDifferent);
|
||||
BOOST_CHECK_EQUAL(e, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(arith_constructor)
|
||||
{
|
||||
FixedHash<20> a(u160(0x1234));
|
||||
BOOST_CHECK_EQUAL(
|
||||
a.hex(),
|
||||
"0000000000000000000000000000000000001234"
|
||||
);
|
||||
|
||||
FixedHash<32> b(u256(0x12340000));
|
||||
BOOST_CHECK_EQUAL(
|
||||
b.hex(),
|
||||
"0000000000000000000000000000000000000000000000000000000012340000"
|
||||
);
|
||||
|
||||
// NOTE: size-mismatched constructor is not available
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(to_arith)
|
||||
{
|
||||
FixedHash<20> a{};
|
||||
BOOST_CHECK_EQUAL(u160(a), 0);
|
||||
|
||||
FixedHash<32> b("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
BOOST_CHECK_EQUAL(u256(b), u256("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(comparison)
|
||||
{
|
||||
FixedHash<32> a("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
FixedHash<32> b("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
FixedHash<32> c("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a471");
|
||||
FixedHash<32> d("233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7");
|
||||
|
||||
BOOST_CHECK(a == a);
|
||||
BOOST_CHECK(b == b);
|
||||
BOOST_CHECK(a == b);
|
||||
BOOST_CHECK(b == a);
|
||||
BOOST_CHECK(a != c);
|
||||
BOOST_CHECK(c != a);
|
||||
BOOST_CHECK(a != d);
|
||||
BOOST_CHECK(d != a);
|
||||
|
||||
// Only equal size comparison is supported.
|
||||
BOOST_CHECK(FixedHash<8>{} == FixedHash<8>{});
|
||||
BOOST_CHECK(FixedHash<32>{} != b);
|
||||
|
||||
// Only equal size less than comparison is supported.
|
||||
BOOST_CHECK(!(a < b));
|
||||
BOOST_CHECK(d < c);
|
||||
BOOST_CHECK(FixedHash<32>{} < a);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(indexing)
|
||||
{
|
||||
// NOTE: uses std::array, so "Accessing a nonexistent element through this operator is undefined behavior."
|
||||
|
||||
FixedHash<32> a("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
BOOST_CHECK_EQUAL(a[0], 0xc5);
|
||||
BOOST_CHECK_EQUAL(a[1], 0xd2);
|
||||
BOOST_CHECK_EQUAL(a[31], 0x70);
|
||||
a[0] = 0xff;
|
||||
a[31] = 0x54;
|
||||
BOOST_CHECK_EQUAL(a[0], 0xff);
|
||||
BOOST_CHECK_EQUAL(a[1], 0xd2);
|
||||
BOOST_CHECK_EQUAL(a[31], 0x54);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(misc)
|
||||
{
|
||||
FixedHash<32> a("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
|
||||
uint8_t* mut_a = a.data();
|
||||
uint8_t const* const_a = a.data();
|
||||
BOOST_CHECK_EQUAL(mut_a, const_a);
|
||||
BOOST_CHECK_EQUAL(memcmp(mut_a, const_a, a.size), 0);
|
||||
|
||||
bytes bytes_a = a.asBytes();
|
||||
bytesRef bytesref_a = a.ref();
|
||||
bytesConstRef bytesconstref_a = a.ref();
|
||||
|
||||
// There's no printing for bytesRef/bytesConstRef
|
||||
BOOST_CHECK(bytes(a.data(), a.data() + a.size) == bytes_a);
|
||||
BOOST_CHECK(bytesRef(a.data(), a.size) == bytesref_a);
|
||||
BOOST_CHECK(bytesConstRef(a.data(), a.size) == bytesconstref_a);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tostream)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << FixedHash<4>("44114411");
|
||||
out << FixedHash<32>{};
|
||||
out << FixedHash<2>("f77f");
|
||||
out << FixedHash<1>("1");
|
||||
BOOST_CHECK_EQUAL(out.str(), "441144110000000000000000000000000000000000000000000000000000000000000000f77f01");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
@@ -34,6 +34,9 @@ namespace solidity::util::test
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(SwarmHash, *boost::unit_test::label("nooptions"))
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
string bzzr0HashHex(string const& _input)
|
||||
{
|
||||
return toHex(bzzr0Hash(_input).asBytes());
|
||||
@@ -52,6 +55,8 @@ bytes sequence(size_t _length)
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_zeros)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string()), string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce"));
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace po = boost::program_options;
|
||||
namespace solidity::test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
auto const description = R"(isoltest, tool for interactively managing test contracts.
|
||||
Usage: isoltest [Options]
|
||||
Interactively validates test contracts.
|
||||
@@ -51,6 +54,8 @@ std::string editorPath()
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IsolTestOptions::IsolTestOptions(std::string* _editor):
|
||||
CommonOptions(description)
|
||||
{
|
||||
|
||||
@@ -28,10 +28,28 @@ using namespace std;
|
||||
|
||||
static constexpr size_t abiCoderHeapSize = 1024 * 512;
|
||||
|
||||
DEFINE_PROTO_FUZZER(Contract const&)
|
||||
DEFINE_PROTO_FUZZER(Contract const& _contract)
|
||||
{
|
||||
ProtoConverter converter;
|
||||
string contractSource = converter.contractToString(_contract);
|
||||
|
||||
if (const char* dump_path = getenv("PROTO_FUZZER_DUMP_PATH"))
|
||||
{
|
||||
// With libFuzzer binary run this to generate the solidity source file x.sol from a proto input:
|
||||
// PROTO_FUZZER_DUMP_PATH=x.sol ./a.out proto-input
|
||||
ofstream of(dump_path);
|
||||
of << contractSource;
|
||||
}
|
||||
|
||||
string typeString = converter.isabelleTypeString();
|
||||
string valueString = converter.isabelleValueString();
|
||||
std::cout << typeString << std::endl;
|
||||
std::cout << valueString << std::endl;
|
||||
abicoder::ABICoder coder(abiCoderHeapSize);
|
||||
auto [encodeStatus, encodedData] = coder.encode("bool", "true");
|
||||
solAssert(encodeStatus, "Isabelle abicoder fuzzer: Encoding failed");
|
||||
if (!typeString.empty())
|
||||
{
|
||||
auto [encodeStatus, encodedData] = coder.encode(typeString, valueString);
|
||||
solAssert(encodeStatus, "Isabelle abicoder fuzzer: Encoding failed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,13 @@ add_dependencies(ossfuzz
|
||||
strictasm_assembly_ossfuzz
|
||||
)
|
||||
|
||||
|
||||
if (OSSFUZZ)
|
||||
add_custom_target(ossfuzz_proto)
|
||||
add_dependencies(ossfuzz_proto
|
||||
sol_proto_ossfuzz
|
||||
yul_proto_ossfuzz
|
||||
yul_proto_diff_ossfuzz
|
||||
yul_proto_diff_custom_mutate_ossfuzz
|
||||
sol_proto_ossfuzz
|
||||
yul_proto_ossfuzz
|
||||
yul_proto_diff_ossfuzz
|
||||
yul_proto_diff_custom_mutate_ossfuzz
|
||||
)
|
||||
|
||||
add_custom_target(ossfuzz_abiv2)
|
||||
@@ -85,7 +84,7 @@ if (OSSFUZZ)
|
||||
protobuf.a
|
||||
)
|
||||
set_target_properties(yul_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(yul_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
|
||||
add_executable(yul_proto_diff_ossfuzz yulProto_diff_ossfuzz.cpp yulFuzzerCommon.cpp protoToYul.cpp yulProto.pb.cc)
|
||||
target_include_directories(yul_proto_diff_ossfuzz PRIVATE /usr/include/libprotobuf-mutator)
|
||||
@@ -96,7 +95,7 @@ if (OSSFUZZ)
|
||||
protobuf.a
|
||||
)
|
||||
set_target_properties(yul_proto_diff_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(yul_proto_diff_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(yul_proto_diff_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
|
||||
add_executable(yul_proto_diff_custom_mutate_ossfuzz
|
||||
yulProto_diff_ossfuzz.cpp
|
||||
@@ -113,7 +112,7 @@ if (OSSFUZZ)
|
||||
protobuf.a
|
||||
)
|
||||
set_target_properties(yul_proto_diff_custom_mutate_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(yul_proto_diff_custom_mutate_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(yul_proto_diff_custom_mutate_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
|
||||
add_executable(abiv2_proto_ossfuzz
|
||||
../../EVMHost.cpp
|
||||
@@ -133,7 +132,7 @@ if (OSSFUZZ)
|
||||
protobuf.a
|
||||
)
|
||||
set_target_properties(abiv2_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(abiv2_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
|
||||
add_executable(abiv2_isabelle_ossfuzz
|
||||
../../EVMHost.cpp
|
||||
@@ -155,7 +154,7 @@ if (OSSFUZZ)
|
||||
gmp
|
||||
)
|
||||
set_target_properties(abiv2_isabelle_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(abiv2_isabelle_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(abiv2_isabelle_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
|
||||
add_executable(sol_proto_ossfuzz
|
||||
solProtoFuzzer.cpp
|
||||
@@ -175,7 +174,7 @@ if (OSSFUZZ)
|
||||
protobuf.a
|
||||
)
|
||||
set_target_properties(sol_proto_ossfuzz PROPERTIES LINK_FLAGS ${LIB_FUZZING_ENGINE})
|
||||
target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion)
|
||||
target_compile_options(sol_proto_ossfuzz PUBLIC ${COMPILE_OPTIONS} -Wno-sign-conversion -Wno-suggest-destructor-override -Wno-inconsistent-missing-destructor-override)
|
||||
else()
|
||||
add_library(solc_opt_ossfuzz
|
||||
solc_opt_ossfuzz.cpp
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
using namespace std;
|
||||
using namespace solidity::test::fuzzer;
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Forward declare libFuzzer's default mutator definition
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" size_t LLVMFuzzerMutate(uint8_t* _data, size_t _size, size_t _maxSize);
|
||||
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* _data, size_t size, size_t _maxSize, unsigned int seed);
|
||||
|
||||
/// Define Solidity's custom mutator by implementing libFuzzer's
|
||||
/// custom mutator external interface.
|
||||
@@ -42,7 +41,6 @@ extern "C" size_t LLVMFuzzerCustomMutator(
|
||||
return LLVMFuzzerMutate(_data, _size, _maxSize);
|
||||
return SolidityCustomMutatorInterface{_data, _size, _maxSize, _seed}.generate();
|
||||
}
|
||||
}
|
||||
|
||||
SolidityCustomMutatorInterface::SolidityCustomMutatorInterface(
|
||||
uint8_t* _data,
|
||||
|
||||
@@ -32,4 +32,4 @@ string SolidityGenerator::generateTestProgram()
|
||||
return Whiskers(R"(pragma <directive>;)")
|
||||
("directive", "solidity >= 0.0.0")
|
||||
.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,4 @@ private:
|
||||
/// Random number generator
|
||||
RandomEngine const m_rand;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,4 @@ evmc::result AbiV2Utility::deployContract(EVMHost& _hostContext, bytes const& _c
|
||||
evmc_message message = initializeMessage(_code);
|
||||
message.kind = EVMC_CREATE;
|
||||
return _hostContext.call(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,8 @@ message FixedByteType {
|
||||
required uint32 width = 1;
|
||||
}
|
||||
|
||||
// address, address payable
|
||||
message AddressType {
|
||||
required bool payable = 1;
|
||||
}
|
||||
// address
|
||||
message AddressType {}
|
||||
|
||||
message ValueType {
|
||||
oneof value_type_oneof {
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size <= 250)
|
||||
@@ -28,4 +31,4 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
FuzzerUtil::testConstantOptimizer(input, /*quiet=*/true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <test/tools/ossfuzz/protoToAbiV2.h>
|
||||
|
||||
#include <boost/preprocessor.hpp>
|
||||
#include <regex>
|
||||
|
||||
/// Convenience macros
|
||||
/// Returns a valid Solidity integer width w such that 8 <= w <= 256.
|
||||
@@ -315,6 +316,10 @@ pair<string, string> ProtoConverter::assignChecker(
|
||||
m_counter += acVisitor.counted();
|
||||
|
||||
m_checks << assignCheckStrPair.second;
|
||||
appendToIsabelleValueString(
|
||||
acVisitor.isabelleValueString(),
|
||||
((m_varCounter == 1) ? Delimiter::SKIP : Delimiter::ADD)
|
||||
);
|
||||
|
||||
// State variables cannot be assigned in contract-scope
|
||||
// Therefore, we buffer their assignments and
|
||||
@@ -333,12 +338,12 @@ std::string ProtoConverter::equalityChecksAsString()
|
||||
return m_checks.str();
|
||||
}
|
||||
|
||||
std::string ProtoConverter::delimiterToString(Delimiter _delimiter)
|
||||
std::string ProtoConverter::delimiterToString(Delimiter _delimiter, bool _space)
|
||||
{
|
||||
switch (_delimiter)
|
||||
{
|
||||
case Delimiter::ADD:
|
||||
return ", ";
|
||||
return _space ? ", " : ",";
|
||||
case Delimiter::SKIP:
|
||||
return "";
|
||||
}
|
||||
@@ -448,7 +453,15 @@ void ProtoConverter::appendToIsabelleTypeString(
|
||||
Delimiter _delimiter
|
||||
)
|
||||
{
|
||||
m_isabelleTypeString << delimiterToString(_delimiter) << _typeString;
|
||||
m_isabelleTypeString << delimiterToString(_delimiter, false) << _typeString;
|
||||
}
|
||||
|
||||
void ProtoConverter::appendToIsabelleValueString(
|
||||
std::string const& _valueString,
|
||||
Delimiter _delimiter
|
||||
)
|
||||
{
|
||||
m_isabelleValueString << delimiterToString(_delimiter, false) << _valueString;
|
||||
}
|
||||
|
||||
std::string ProtoConverter::typedParametersAsString(CalleeType _calleeType)
|
||||
@@ -736,6 +749,15 @@ string ProtoConverter::isabelleTypeString() const
|
||||
return typeString;
|
||||
}
|
||||
|
||||
string ProtoConverter::isabelleValueString() const
|
||||
{
|
||||
string valueString = m_isabelleValueString.str();
|
||||
if (!valueString.empty())
|
||||
return "(" + valueString + ")";
|
||||
else
|
||||
return valueString;
|
||||
}
|
||||
|
||||
string ProtoConverter::contractToString(Contract const& _input)
|
||||
{
|
||||
visit(_input);
|
||||
@@ -777,9 +799,9 @@ string TypeVisitor::visit(FixedByteType const& _type)
|
||||
return m_baseType;
|
||||
}
|
||||
|
||||
string TypeVisitor::visit(AddressType const& _type)
|
||||
string TypeVisitor::visit(AddressType const&)
|
||||
{
|
||||
m_baseType = getAddressTypeAsString(_type);
|
||||
m_baseType = "address";
|
||||
m_structTupleString.addTypeStringToTuple(m_baseType);
|
||||
return m_baseType;
|
||||
}
|
||||
@@ -890,33 +912,61 @@ string TypeVisitor::visit(StructType const& _type)
|
||||
}
|
||||
|
||||
/// AssignCheckVisitor implementation
|
||||
void AssignCheckVisitor::ValueStream::appendValue(string& _value)
|
||||
{
|
||||
solAssert(!_value.empty(), "Abiv2 fuzzer: Empty value");
|
||||
index++;
|
||||
if (index > 1)
|
||||
stream << ",";
|
||||
stream << _value;
|
||||
}
|
||||
|
||||
pair<string, string> AssignCheckVisitor::visit(BoolType const& _type)
|
||||
{
|
||||
string value = ValueGetterVisitor(counter()).visit(_type);
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.appendValue(value);
|
||||
return assignAndCheckStringPair(m_varName, m_paramName, value, value, DataType::VALUE);
|
||||
}
|
||||
|
||||
pair<string, string> AssignCheckVisitor::visit(IntegerType const& _type)
|
||||
{
|
||||
string value = ValueGetterVisitor(counter()).visit(_type);
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.appendValue(value);
|
||||
return assignAndCheckStringPair(m_varName, m_paramName, value, value, DataType::VALUE);
|
||||
}
|
||||
|
||||
pair<string, string> AssignCheckVisitor::visit(FixedByteType const& _type)
|
||||
{
|
||||
string value = ValueGetterVisitor(counter()).visit(_type);
|
||||
if (!m_forcedVisit)
|
||||
{
|
||||
string isabelleValue = ValueGetterVisitor{}.isabelleBytesValueAsString(value);
|
||||
m_valueStream.appendValue(isabelleValue);
|
||||
}
|
||||
return assignAndCheckStringPair(m_varName, m_paramName, value, value, DataType::VALUE);
|
||||
}
|
||||
|
||||
pair<string, string> AssignCheckVisitor::visit(AddressType const& _type)
|
||||
{
|
||||
string value = ValueGetterVisitor(counter()).visit(_type);
|
||||
if (!m_forcedVisit)
|
||||
{
|
||||
string isabelleValue = ValueGetterVisitor{}.isabelleAddressValueAsString(value);
|
||||
m_valueStream.appendValue(isabelleValue);
|
||||
}
|
||||
return assignAndCheckStringPair(m_varName, m_paramName, value, value, DataType::VALUE);
|
||||
}
|
||||
|
||||
pair<string, string> AssignCheckVisitor::visit(DynamicByteArrayType const& _type)
|
||||
{
|
||||
string value = ValueGetterVisitor(counter()).visit(_type);
|
||||
if (!m_forcedVisit)
|
||||
{
|
||||
string isabelleValue = ValueGetterVisitor{}.isabelleBytesValueAsString(value);
|
||||
m_valueStream.appendValue(isabelleValue);
|
||||
}
|
||||
DataType dataType = _type.type() == DynamicByteArrayType::BYTES ? DataType::BYTES : DataType::STRING;
|
||||
return assignAndCheckStringPair(m_varName, m_paramName, value, value, dataType);
|
||||
}
|
||||
@@ -981,6 +1031,8 @@ pair<string, string> AssignCheckVisitor::visit(ArrayType const& _type)
|
||||
pair<string, string> assignCheckBuffer;
|
||||
string wasVarName = m_varName;
|
||||
string wasParamName = m_paramName;
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.startArray();
|
||||
for (unsigned i = 0; i < length; i++)
|
||||
{
|
||||
m_varName = wasVarName + "[" + to_string(i) + "]";
|
||||
@@ -991,12 +1043,18 @@ pair<string, string> AssignCheckVisitor::visit(ArrayType const& _type)
|
||||
if (i < length - 1)
|
||||
m_structCounter = wasStructCounter;
|
||||
}
|
||||
|
||||
// Since struct visitor won't be called for zero-length
|
||||
// arrays, struct counter will not get incremented. Therefore,
|
||||
// we need to manually force a recursive struct visit.
|
||||
if (length == 0 && TypeVisitor().arrayOfStruct(_type))
|
||||
{
|
||||
bool previousState = m_forcedVisit;
|
||||
m_forcedVisit = true;
|
||||
visit(_type.t());
|
||||
m_forcedVisit = previousState;
|
||||
}
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.endArray();
|
||||
|
||||
m_varName = wasVarName;
|
||||
m_paramName = wasParamName;
|
||||
@@ -1022,6 +1080,8 @@ pair<string, string> AssignCheckVisitor::visit(StructType const& _type)
|
||||
string wasVarName = m_varName;
|
||||
string wasParamName = m_paramName;
|
||||
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.startStruct();
|
||||
for (auto const& t: _type.t())
|
||||
{
|
||||
m_varName = wasVarName + ".m" + to_string(i);
|
||||
@@ -1035,6 +1095,8 @@ pair<string, string> AssignCheckVisitor::visit(StructType const& _type)
|
||||
assignCheckBuffer.second += assign.second;
|
||||
i++;
|
||||
}
|
||||
if (!m_forcedVisit)
|
||||
m_valueStream.endStruct();
|
||||
m_varName = wasVarName;
|
||||
m_paramName = wasParamName;
|
||||
return assignCheckBuffer;
|
||||
@@ -1117,11 +1179,11 @@ string ValueGetterVisitor::visit(AddressType const&)
|
||||
return addressValueAsString(counter());
|
||||
}
|
||||
|
||||
string ValueGetterVisitor::visit(DynamicByteArrayType const& _type)
|
||||
string ValueGetterVisitor::visit(DynamicByteArrayType const&)
|
||||
{
|
||||
return bytesArrayValueAsString(
|
||||
counter(),
|
||||
getDataTypeOfDynBytesType(_type) == DataType::BYTES
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1195,10 +1257,29 @@ std::string ValueGetterVisitor::fixedByteValueAsString(unsigned _width, unsigned
|
||||
|
||||
std::string ValueGetterVisitor::addressValueAsString(unsigned _counter)
|
||||
{
|
||||
// TODO: Isabelle encoder expects address literal to be exactly
|
||||
return "address(" + maskUnsignedIntToHex(_counter, 40) + ")";
|
||||
}
|
||||
|
||||
std::string ValueGetterVisitor::isabelleAddressValueAsString(std::string& _solAddressString)
|
||||
{
|
||||
// Isabelle encoder expects address literal to be exactly
|
||||
// 20 bytes and a hex string.
|
||||
// Example: 0x0102030405060708090a0102030405060708090a
|
||||
return "address(" + maskUnsignedIntToHex(_counter, 40) + ")";
|
||||
std::regex const addressPattern("address\\((.*)\\)");
|
||||
std::smatch match;
|
||||
solAssert(std::regex_match(_solAddressString, match, addressPattern), "Abiv2 fuzzer: Invalid address string");
|
||||
std::string addressHex = match[1].str();
|
||||
addressHex.erase(2, 24);
|
||||
return addressHex;
|
||||
}
|
||||
|
||||
std::string ValueGetterVisitor::isabelleBytesValueAsString(std::string& _solBytesString)
|
||||
{
|
||||
std::regex const bytesPattern("hex\"(.*)\"");
|
||||
std::smatch match;
|
||||
solAssert(std::regex_match(_solBytesString, match, bytesPattern), "Abiv2 fuzzer: Invalid bytes string");
|
||||
std::string bytesHex = match[1].str();
|
||||
return "0x" + bytesHex;
|
||||
}
|
||||
|
||||
std::string ValueGetterVisitor::variableLengthValueAsString(
|
||||
|
||||
@@ -153,6 +153,7 @@ public:
|
||||
ProtoConverter(ProtoConverter&&) = delete;
|
||||
std::string contractToString(Contract const& _input);
|
||||
std::string isabelleTypeString() const;
|
||||
std::string isabelleValueString() const;
|
||||
private:
|
||||
enum class Delimiter
|
||||
{
|
||||
@@ -295,6 +296,13 @@ private:
|
||||
Delimiter _delimiter
|
||||
);
|
||||
|
||||
/// Append @a _valueString to value string meant to be
|
||||
/// passed to Isabelle coder API.
|
||||
void appendToIsabelleValueString(
|
||||
std::string const& _valueString,
|
||||
Delimiter _delimiter
|
||||
);
|
||||
|
||||
/// Returns a Solidity variable declaration statement
|
||||
/// @param _type: string containing Solidity type of the
|
||||
/// variable to be declared.
|
||||
@@ -367,7 +375,7 @@ private:
|
||||
}
|
||||
|
||||
/// Convert delimter to a comma or null string.
|
||||
static std::string delimiterToString(Delimiter _delimiter);
|
||||
static std::string delimiterToString(Delimiter _delimiter, bool _space = true);
|
||||
|
||||
/// Contains the test program
|
||||
std::ostringstream m_output;
|
||||
@@ -379,6 +387,9 @@ private:
|
||||
std::ostringstream m_typedParamsPublic;
|
||||
/// Contains type string to be passed to Isabelle API
|
||||
std::ostringstream m_isabelleTypeString;
|
||||
/// Contains values to be encoded in the format accepted
|
||||
/// by the Isabelle API.
|
||||
std::ostringstream m_isabelleValueString;
|
||||
/// Contains type stream to be used in returndata coder function
|
||||
/// signature
|
||||
std::ostringstream m_types;
|
||||
@@ -476,19 +487,6 @@ public:
|
||||
return "bytes" + std::to_string(getFixedByteWidth(_x));
|
||||
}
|
||||
|
||||
static std::string getAddressTypeAsString(AddressType const& _x)
|
||||
{
|
||||
return (_x.payable() ? "address payable" : "address");
|
||||
}
|
||||
|
||||
static DataType getDataTypeOfDynBytesType(DynamicByteArrayType const& _x)
|
||||
{
|
||||
if (_x.type() == DynamicByteArrayType::STRING)
|
||||
return DataType::STRING;
|
||||
else
|
||||
return DataType::BYTES;
|
||||
}
|
||||
|
||||
// Convert _counter to string and return its keccak256 hash
|
||||
static u256 hashUnsignedInt(unsigned _counter)
|
||||
{
|
||||
@@ -531,7 +529,13 @@ public:
|
||||
// this linear equation to make the number derived from
|
||||
// _counter approach a uniform distribution over
|
||||
// [0, s_maxDynArrayLength]
|
||||
return (_counter + 879) * 32 % (s_maxDynArrayLength + 1);
|
||||
auto v = (_counter + 879) * 32 % (s_maxDynArrayLength + 1);
|
||||
/// Always return an even number because Isabelle string
|
||||
/// values are formatted as hex literals
|
||||
if (v % 2 == 1)
|
||||
return v + 1;
|
||||
else
|
||||
return v;
|
||||
}
|
||||
|
||||
static std::string bytesArrayTypeAsString(DynamicByteArrayType const& _x)
|
||||
@@ -658,10 +662,6 @@ private:
|
||||
{
|
||||
stream << ")";
|
||||
}
|
||||
std::string operator()()
|
||||
{
|
||||
return stream.str();
|
||||
}
|
||||
void addTypeStringToTuple(std::string& _typeString);
|
||||
void addArrayBracketToType(std::string& _arrayBracket);
|
||||
};
|
||||
@@ -735,7 +735,42 @@ public:
|
||||
{
|
||||
return m_structCounter - m_structStart;
|
||||
}
|
||||
|
||||
std::string isabelleValueString()
|
||||
{
|
||||
return m_valueStream.stream.str();
|
||||
}
|
||||
private:
|
||||
struct ValueStream
|
||||
{
|
||||
ValueStream() = default;
|
||||
unsigned index = 0;
|
||||
std::ostringstream stream;
|
||||
void startStruct()
|
||||
{
|
||||
if (index >= 1)
|
||||
stream << ",";
|
||||
index = 0;
|
||||
stream << "(";
|
||||
}
|
||||
void endStruct()
|
||||
{
|
||||
stream << ")";
|
||||
}
|
||||
void startArray()
|
||||
{
|
||||
if (index >= 1)
|
||||
stream << ",";
|
||||
index = 0;
|
||||
stream << "[";
|
||||
}
|
||||
void endArray()
|
||||
{
|
||||
stream << "]";
|
||||
index++;
|
||||
}
|
||||
void appendValue(std::string& _value);
|
||||
};
|
||||
std::string indentation()
|
||||
{
|
||||
return std::string(m_indentation * 1, '\t');
|
||||
@@ -764,6 +799,8 @@ private:
|
||||
bool m_stateVar;
|
||||
unsigned m_structCounter;
|
||||
unsigned m_structStart;
|
||||
ValueStream m_valueStream;
|
||||
bool m_forcedVisit = false;
|
||||
};
|
||||
|
||||
/// Returns a valid value (as a string) for a given type.
|
||||
@@ -786,6 +823,8 @@ public:
|
||||
solAssert(false, "ABIv2 proto fuzzer: Cannot call valuegettervisitor on complex type");
|
||||
}
|
||||
using AbiV2ProtoVisitor<std::string>::visit;
|
||||
static std::string isabelleAddressValueAsString(std::string& _solAddressString);
|
||||
static std::string isabelleBytesValueAsString(std::string& _solFixedBytesString);
|
||||
private:
|
||||
unsigned counter()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size <= 600)
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size <= 600)
|
||||
|
||||
@@ -24,6 +24,9 @@ using namespace solidity;
|
||||
using namespace solidity::yul;
|
||||
using namespace std;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size > 600)
|
||||
|
||||
@@ -43,6 +43,9 @@ using namespace solidity::util;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::yul::test::yul_fuzzer;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size > 600)
|
||||
|
||||
@@ -24,6 +24,9 @@ using namespace solidity::util;
|
||||
using namespace solidity::yul;
|
||||
using namespace std;
|
||||
|
||||
// Prototype as we can't use the FuzzerInterface.h header.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
if (_size > 600)
|
||||
|
||||
Reference in New Issue
Block a user