#pragma once
#include <libsmtutil/SolverInterface.h>
#include <optional>
#include <set>
namespace solidity::frontend
{
struct ModelCheckerContracts
{
static ModelCheckerContracts Default() { return {}; }
static std::optional<ModelCheckerContracts> fromString(std::string const& _contracts);
bool isDefault() const { return contracts.empty(); }
bool has(std::string const& _source) const { return contracts.count(_source); }
bool has(std::string const& _source, std::string const& _contract) const
{
return has(_source) && contracts.at(_source).count(_contract);
}
bool operator!=(ModelCheckerContracts const& _other) const noexcept { return !(*this == _other); }
bool operator==(ModelCheckerContracts const& _other) const noexcept { return contracts == _other.contracts; }
std::map<std::string, std::set<std::string>> contracts;
};
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 {};
}
bool operator!=(ModelCheckerEngine const& _other) const noexcept { return !(*this == _other); }
bool operator==(ModelCheckerEngine const& _other) const noexcept { return bmc == _other.bmc && chc == _other.chc; }
};
enum class InvariantType { Contract, Reentrancy };
struct ModelCheckerInvariants
{
static ModelCheckerInvariants Default() { return *fromString("default"); }
static ModelCheckerInvariants All() { return *fromString("all"); }
static ModelCheckerInvariants None() { return {{}}; }
static std::optional<ModelCheckerInvariants> fromString(std::string const& _invs);
bool has(InvariantType _inv) const { return invariants.count(_inv); }
bool setFromString(std::string const& _target);
static std::map<std::string, InvariantType> const validInvariants;
bool operator!=(ModelCheckerInvariants const& _other) const noexcept { return !(*this == _other); }
bool operator==(ModelCheckerInvariants const& _other) const noexcept { return invariants == _other.invariants; }
std::set<InvariantType> invariants;
};
enum class VerificationTargetType { ConstantCondition, Underflow, Overflow, UnderOverflow, DivByZero, Balance, Assert, PopEmptyArray, OutOfBounds };
struct ModelCheckerTargets
{
static ModelCheckerTargets Default() { return *fromString("default"); }
static ModelCheckerTargets All() { return *fromString("all"); }
static std::optional<ModelCheckerTargets> fromString(std::string const& _targets);
bool has(VerificationTargetType _type) const { return targets.count(_type); }
bool setFromString(std::string const& _target);
static std::map<std::string, VerificationTargetType> const targetStrings;
static std::map<VerificationTargetType, std::string> const targetTypeToString;
bool operator!=(ModelCheckerTargets const& _other) const noexcept { return !(*this == _other); }
bool operator==(ModelCheckerTargets const& _other) const noexcept { return targets == _other.targets; }
std::set<VerificationTargetType> targets;
};
struct ModelCheckerSettings
{
ModelCheckerContracts contracts = ModelCheckerContracts::Default();
bool divModNoSlacks = false;
ModelCheckerEngine engine = ModelCheckerEngine::None();
ModelCheckerInvariants invariants = ModelCheckerInvariants::Default();
bool showUnproved = false;
smtutil::SMTSolverChoice solvers = smtutil::SMTSolverChoice::All();
ModelCheckerTargets targets = ModelCheckerTargets::Default();
std::optional<unsigned> timeout;
bool operator!=(ModelCheckerSettings const& _other) const noexcept { return !(*this == _other); }
bool operator==(ModelCheckerSettings const& _other) const noexcept
{
return
contracts == _other.contracts &&
divModNoSlacks == _other.divModNoSlacks &&
engine == _other.engine &&
invariants == _other.invariants &&
showUnproved == _other.showUnproved &&
solvers == _other.solvers &&
targets == _other.targets &&
timeout == _other.timeout;
}
};
}