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>
|
2021-01-19 11:56:22 +00:00
|
|
|
#include <libsolidity/formal/ModelCheckerSettings.h>
|
2019-06-25 10:46:17 +00:00
|
|
|
|
|
|
|
#include <libsolidity/interface/ReadFile.h>
|
2020-05-18 15:42:24 +00:00
|
|
|
|
|
|
|
#include <libsmtutil/SolverInterface.h>
|
2021-08-27 09:40:20 +00:00
|
|
|
|
2019-06-25 10:46:17 +00:00
|
|
|
#include <liblangutil/ErrorReporter.h>
|
2021-08-27 09:40:20 +00:00
|
|
|
#include <liblangutil/UniqueErrorReporter.h>
|
2019-06-25 10:46:17 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
|
|
|
|
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,
|
2021-07-01 15:28:06 +00:00
|
|
|
langutil::CharStreamProvider const& _charStreamProvider,
|
2020-02-12 01:04:25 +00:00
|
|
|
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
|
2020-11-02 20:20:20 +00:00
|
|
|
ModelCheckerSettings _settings = ModelCheckerSettings{},
|
2021-05-19 15:35:19 +00:00
|
|
|
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback()
|
2019-09-17 14:06:43 +00:00
|
|
|
);
|
2019-06-25 10:46:17 +00:00
|
|
|
|
2021-03-31 15:09:37 +00:00
|
|
|
// TODO This should be removed for 0.9.0.
|
2022-05-15 15:45:43 +00:00
|
|
|
static bool isPragmaPresent(std::vector<std::shared_ptr<SourceUnit>> const& _sources);
|
2021-03-31 15:09:37 +00:00
|
|
|
|
2021-04-15 10:31:45 +00:00
|
|
|
/// Generates error messages if the requested sources and contracts
|
|
|
|
/// do not exist.
|
|
|
|
void checkRequestedSourcesAndContracts(std::vector<std::shared_ptr<SourceUnit>> const& _sources);
|
|
|
|
|
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
|
|
|
|
2022-05-15 15:45:43 +00:00
|
|
|
/// @returns the intersection of the enabled and available solvers,
|
|
|
|
/// reporting warnings when a solver is enabled but not available.
|
|
|
|
static smtutil::SMTSolverChoice checkRequestedSolvers(smtutil::SMTSolverChoice _enabled, langutil::ErrorReporter& _errorReporter);
|
|
|
|
|
2019-06-25 10:46:17 +00:00
|
|
|
private:
|
2021-08-27 09:40:20 +00:00
|
|
|
/// Error reporter from CompilerStack.
|
|
|
|
/// We need to append m_uniqueErrorReporter
|
|
|
|
/// to this one when the analysis is done.
|
2021-03-31 15:09:37 +00:00
|
|
|
langutil::ErrorReporter& m_errorReporter;
|
|
|
|
|
2021-08-27 09:40:20 +00:00
|
|
|
/// Used by ModelChecker, SMTEncoder, BMC and CHC to avoid duplicates.
|
|
|
|
/// This is local to ModelChecker, so needs to be appended
|
|
|
|
/// to m_errorReporter at the end of the analysis.
|
|
|
|
langutil::UniqueErrorReporter m_uniqueErrorReporter;
|
|
|
|
|
2023-03-06 13:19:58 +00:00
|
|
|
/// Used by SMTEncoder, BMC and CHC to accumulate unsupported
|
|
|
|
/// warnings and avoid duplicates.
|
|
|
|
/// This is local to ModelChecker, so needs to be appended
|
|
|
|
/// to m_errorReporter at the end of the analysis.
|
|
|
|
langutil::UniqueErrorReporter m_unsupportedErrorReporter;
|
|
|
|
|
2020-11-02 20:20:20 +00:00
|
|
|
ModelCheckerSettings m_settings;
|
2020-10-14 15:44:40 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|