Skip to content

Commit 74399b6

Browse files
authored
Merge pull request #15204 from ethereum/smt-tests-update
SMTChecker: Bring back assertions in "external_calls" SMTChecker tests
2 parents 3c65632 + fbb5eed commit 74399b6

File tree

12 files changed

+58
-35
lines changed

12 files changed

+58
-35
lines changed

docs/contributing.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ Prerequisites
9393

9494
For running all compiler tests you may want to optionally install a few
9595
dependencies (`evmone <https://github.com/ethereum/evmone/releases>`_,
96-
`libz3 <https://github.com/Z3Prover/z3>`_).
96+
`libz3 <https://github.com/Z3Prover/z3>`_, `Eldarica <https://github.com/uuverifiers/eldarica/>`_,
97+
`cvc5 <https://github.com/cvc5/cvc5>`).
9798

9899
On macOS systems, some of the testing scripts expect GNU coreutils to be installed.
99100
This can be easiest accomplished using Homebrew: ``brew install coreutils``.
@@ -133,11 +134,14 @@ extension ``.so`` on Linux, ``.dll`` on Windows systems and ``.dylib`` on macOS.
133134

134135
For running SMT tests, the ``libz3`` library must be installed and locatable
135136
by ``cmake`` during compiler configure stage.
137+
A few SMT tests use ``Eldarica`` instead of ``Z3``.
138+
``Eldarica`` is a runtime dependency, its executable (``eld``) must be present in ``PATH`` for the tests to pass.
139+
However, if ``Eldarica`` is not found, these tests will be automatically skipped.
136140

137141
If the ``libz3`` library is not installed on your system, you should disable the
138142
SMT tests by exporting ``SMT_FLAGS=--no-smt`` before running ``./scripts/tests.sh`` or
139143
running ``./scripts/soltest.sh --no-smt``.
140-
These tests are ``libsolidity/smtCheckerTests`` and ``libsolidity/smtCheckerTestsJSON``.
144+
These tests are ``libsolidity/smtCheckerTests``.
141145

142146
.. note::
143147

docs/installing-solidity.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,24 @@ If you are interested what CMake options are available run ``cmake .. -LH``.
527527

528528
SMT Solvers
529529
-----------
530-
Solidity can be built against SMT solvers and will do so by default if
531-
they are found in the system. Each solver can be disabled by a ``cmake`` option.
530+
Solidity can be built against Z3 SMT solver and will do so by default if
531+
it is found in the system. Z3 can be disabled by a ``cmake`` option.
532532

533533
*Note: In some cases, this can also be a potential workaround for build failures.*
534534

535535

536-
Inside the build folder you can disable them, since they are enabled by default:
536+
Inside the build folder you can disable Z3, since it is enabled by default:
537537

538538
.. code-block:: bash
539539
540-
# disables only Z3 SMT Solver.
540+
# disables Z3 SMT Solver.
541541
cmake .. -DUSE_Z3=OFF
542542
543+
.. note::
544+
545+
Solidity can optionally use other solvers, namely ``cvc5`` and ``Eldarica``,
546+
but their presence is checked only at runtime, they are not needed for the build to succeed.
547+
543548
The Version String in Detail
544549
============================
545550

libsolidity/interface/SMTSolverCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void SMTSolverCommand::setCvc5(std::optional<unsigned int> timeoutInMilliseconds
6363
}
6464
}
6565

66-
ReadCallback::Result SMTSolverCommand::solve(std::string const& _kind, std::string const& _query)
66+
ReadCallback::Result SMTSolverCommand::solve(std::string const& _kind, std::string const& _query) const
6767
{
6868
try
6969
{

libsolidity/interface/SMTSolverCommand.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class SMTSolverCommand
2929
{
3030
public:
3131
/// Calls an SMT solver with the given query.
32-
frontend::ReadCallback::Result solve(std::string const& _kind, std::string const& _query);
32+
frontend::ReadCallback::Result solve(std::string const& _kind, std::string const& _query) const;
3333

34-
frontend::ReadCallback::Callback solver()
34+
frontend::ReadCallback::Callback solver() const
3535
{
3636
return [this](std::string const& _kind, std::string const& _query) { return solve(_kind, _query); };
3737
}

libsolidity/interface/UniversalCallback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class UniversalCallback
4646
solAssert(false, "Unknown callback kind.");
4747
}
4848

49-
frontend::ReadCallback::Callback callback()
49+
frontend::ReadCallback::Callback callback() const
5050
{
5151
return *this;
5252
}

test/libsolidity/SMTCheckerTest.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ using namespace solidity;
2525
using namespace solidity::langutil;
2626
using namespace solidity::frontend;
2727
using namespace solidity::frontend::test;
28+
using namespace solidity::test;
2829

29-
SMTCheckerTest::SMTCheckerTest(std::string const& _filename): SyntaxTest(_filename, EVMVersion{})
30+
SMTCheckerTest::SMTCheckerTest(std::string const& _filename):
31+
SyntaxTest(_filename, EVMVersion{}),
32+
universalCallback(nullptr, smtCommand)
3033
{
3134
auto contract = m_reader.stringSetting("SMTContract", "");
3235
if (!contract.empty())
@@ -168,3 +171,7 @@ void SMTCheckerTest::printUpdatedExpectations(std::ostream &_stream, const std::
168171
else
169172
CommonSyntaxTest::printUpdatedExpectations(_stream, _linePrefix);
170173
}
174+
175+
std::unique_ptr<CompilerStack> SMTCheckerTest::createStack() const {
176+
return std::make_unique<CompilerStack>(universalCallback.callback());
177+
}

test/libsolidity/SMTCheckerTest.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#include <libsolidity/formal/ModelChecker.h>
2626

27+
#include <libsolidity/interface/SMTSolverCommand.h>
28+
#include <libsolidity/interface/UniversalCallback.h>
29+
2730
#include <string>
2831

2932
namespace solidity::frontend::test
@@ -36,14 +39,16 @@ class SMTCheckerTest: public SyntaxTest
3639
{
3740
return std::make_unique<SMTCheckerTest>(_config.filename);
3841
}
39-
SMTCheckerTest(std::string const& _filename);
42+
explicit SMTCheckerTest(std::string const& _filename);
4043

4144
void setupCompiler(CompilerStack& _compiler) override;
4245
void filterObtainedErrors() override;
4346

4447
void printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const override;
4548

4649
protected:
50+
std::unique_ptr<CompilerStack> createStack() const override;
51+
4752
/*
4853
Options that can be set in the test:
4954
SMTEngine: `all`, `chc`, `bmc`, `none`, where the default is `all`.
@@ -56,7 +61,7 @@ class SMTCheckerTest: public SyntaxTest
5661
Set in m_modelCheckerSettings.
5762
SMTShowUnproved: `yes`, `no`, where the default is `yes`.
5863
Set in m_modelCheckerSettings.
59-
SMTSolvers: `all`, `cvc5`, `z3`, `none`, where the default is `all`.
64+
SMTSolvers: `all`, `cvc5`, `z3`, `eld`, `none`, where the default is `z3`.
6065
Set in m_modelCheckerSettings.
6166
BMCLoopIterations: number of loop iterations for BMC engine, the default is 1.
6267
Set in m_modelCheckerSettings.
@@ -67,6 +72,9 @@ class SMTCheckerTest: public SyntaxTest
6772
bool m_ignoreCex = false;
6873

6974
std::vector<SyntaxTestError> m_unfilteredErrorList;
75+
76+
SMTSolverCommand smtCommand;
77+
UniversalCallback universalCallback;
7078
};
7179

7280
}

test/libsolidity/smtCheckerTests/external_calls/call_with_value_3.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ contract C {
33
require(address(this).balance > 100);
44
i.call{value: 20}("");
55
assert(address(this).balance > 0); // should hold
6-
// Disabled due to Spacer nondeterminism
7-
//assert(address(this).balance == 0); // should fail
6+
assert(address(this).balance == 0); // should fail
87
}
98
}
109
// ====
11-
// SMTEngine: all
10+
// SMTEngine: chc
11+
// SMTIgnoreCex: yes
12+
// SMTSolvers: eld
1213
// ----
1314
// Warning 9302: (95-116): Return value of low-level calls not used.
14-
// Warning 6328: (120-153): CHC: Assertion violation might happen here.
15-
// Warning 4661: (120-153): BMC: Assertion violation happens here.
15+
// Warning 6328: (172-206): CHC: Assertion violation happens here.
16+
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

test/libsolidity/smtCheckerTests/external_calls/external_call_with_value_1.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ contract C {
77
require(address(this).balance == 100);
88
i.f{value: 10}();
99
assert(address(this).balance == 90); // should hold
10-
// Disabled due to Spacer nondeterminism
11-
//assert(address(this).balance == 100); // should fail
10+
assert(address(this).balance == 100); // should fail
1211
}
1312
}
1413
// ====
15-
// SMTEngine: all
14+
// SMTEngine: chc
15+
// SMTSolvers: eld
1616
// ----
17-
// Warning 6328: (151-186): CHC: Assertion violation might happen here.
18-
// Warning 4661: (151-186): BMC: Assertion violation happens here.
17+
// Warning 6328: (205-241): CHC: Assertion violation happens here.
18+
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

test/libsolidity/smtCheckerTests/external_calls/external_hash_known_code_state_reentrancy.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ contract C {
1919
address prevOwner = owner;
2020
uint z = s.f();
2121
assert(z == y);
22-
// Disabled because of Spacer nondeterminism.
23-
//assert(prevOwner == owner);
22+
assert(prevOwner == owner);
2423
}
2524

2625
function g() public view returns (uint) {
@@ -31,5 +30,5 @@ contract C {
3130
// SMTEngine: all
3231
// SMTIgnoreCex: yes
3332
// ----
34-
// Warning 2072: (219-236): Unused local variable.
35-
// Warning 6328: (266-280): CHC: Assertion violation happens here.
33+
// Warning 6328: (266-280): CHC: Assertion violation happens here.\nCounterexample:\nowner = 0x0, y = 0, s = 0\nprevOwner = 0x0\nz = 1\n\nTransaction trace:\nC.constructor(){ msg.sender: 0x0 }\nState: owner = 0x0, y = 0, s = 0\nC.f()\n s.f() -- untrusted external call
34+
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 commit comments

Comments
 (0)