2019-06-25 10:46:17 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2019-06-25 10:46:17 +00:00
|
|
|
/**
|
|
|
|
* Entry point to the model checking engines.
|
|
|
|
* The goal of this class is to make different
|
|
|
|
* engines share knowledge to boost their proving power.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libsolidity/formal/BMC.h>
|
2019-07-04 12:44:10 +00:00
|
|
|
#include <libsolidity/formal/CHC.h>
|
2019-06-25 10:46:17 +00:00
|
|
|
#include <libsolidity/formal/EncodingContext.h>
|
|
|
|
|
|
|
|
#include <libsolidity/interface/ReadFile.h>
|
2020-05-18 15:42:24 +00:00
|
|
|
|
|
|
|
#include <libsmtutil/SolverInterface.h>
|
2019-06-25 10:46:17 +00:00
|
|
|
#include <liblangutil/ErrorReporter.h>
|
|
|
|
|
2020-10-14 15:44:40 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2019-06-25 10:46:17 +00:00
|
|
|
{
|
|
|
|
class ErrorReporter;
|
|
|
|
struct SourceLocation;
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2019-06-25 10:46:17 +00:00
|
|
|
{
|
|
|
|
|
2020-10-14 15:44:40 +00:00
|
|
|
struct ModelCheckerEngine
|
|
|
|
{
|
|
|
|
bool bmc = false;
|
|
|
|
bool chc = false;
|
|
|
|
|
|
|
|
static constexpr ModelCheckerEngine All() { return {true, true}; }
|
|
|
|
static constexpr ModelCheckerEngine BMC() { return {true, false}; }
|
|
|
|
static constexpr ModelCheckerEngine CHC() { return {false, true}; }
|
|
|
|
static constexpr ModelCheckerEngine None() { return {false, false}; }
|
|
|
|
|
|
|
|
bool none() const { return !any(); }
|
|
|
|
bool any() const { return bmc || chc; }
|
|
|
|
bool all() const { return bmc && chc; }
|
|
|
|
|
|
|
|
static std::optional<ModelCheckerEngine> fromString(std::string const& _engine)
|
|
|
|
{
|
|
|
|
static std::map<std::string, ModelCheckerEngine> engineMap{
|
|
|
|
{"all", All()},
|
|
|
|
{"bmc", BMC()},
|
|
|
|
{"chc", CHC()},
|
|
|
|
{"none", None()}
|
|
|
|
};
|
|
|
|
if (engineMap.count(_engine))
|
|
|
|
return engineMap.at(_engine);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-25 10:46:17 +00:00
|
|
|
class ModelChecker
|
|
|
|
{
|
|
|
|
public:
|
2019-12-04 16:31:39 +00:00
|
|
|
/// @param _enabledSolvers represents a runtime choice of which SMT solvers
|
|
|
|
/// should be used, even if all are available. The default choice is to use all.
|
2019-09-17 14:06:43 +00:00
|
|
|
ModelChecker(
|
|
|
|
langutil::ErrorReporter& _errorReporter,
|
2020-02-12 01:04:25 +00:00
|
|
|
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
|
2020-10-14 15:44:40 +00:00
|
|
|
ModelCheckerEngine _engine = ModelCheckerEngine::All(),
|
2019-12-05 15:44:26 +00:00
|
|
|
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback(),
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::SMTSolverChoice _enabledSolvers = smtutil::SMTSolverChoice::All()
|
2019-09-17 14:06:43 +00:00
|
|
|
);
|
2019-06-25 10:46:17 +00:00
|
|
|
|
2019-08-06 14:02:11 +00:00
|
|
|
void analyze(SourceUnit const& _sources);
|
2019-06-25 10:46:17 +00:00
|
|
|
|
|
|
|
/// This is used if the SMT solver is not directly linked into this binary.
|
|
|
|
/// @returns a list of inputs to the SMT solver that were not part of the argument to
|
|
|
|
/// the constructor.
|
|
|
|
std::vector<std::string> unhandledQueries();
|
|
|
|
|
2019-12-03 15:50:28 +00:00
|
|
|
/// @returns SMT solvers that are available via the C++ API.
|
2020-05-19 12:14:46 +00:00
|
|
|
static smtutil::SMTSolverChoice availableSolvers();
|
2019-12-03 15:50:28 +00:00
|
|
|
|
2019-06-25 10:46:17 +00:00
|
|
|
private:
|
2020-10-14 15:44:40 +00:00
|
|
|
ModelCheckerEngine m_engine;
|
|
|
|
|
2020-02-12 01:52:35 +00:00
|
|
|
/// Stores the context of the encoding.
|
|
|
|
smt::EncodingContext m_context;
|
|
|
|
|
2019-06-25 10:46:17 +00:00
|
|
|
/// Bounded Model Checker engine.
|
|
|
|
BMC m_bmc;
|
|
|
|
|
2019-07-04 12:44:10 +00:00
|
|
|
/// Constrained Horn Clauses engine.
|
|
|
|
CHC m_chc;
|
2019-06-25 10:46:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|