2021-01-19 11:56:22 +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/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
#include <libsolidity/formal/ModelCheckerSettings.h>
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <range/v3/view.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
|
2021-04-14 10:56:43 +00:00
|
|
|
using TargetType = VerificationTargetType;
|
|
|
|
map<string, TargetType> const ModelCheckerTargets::targetStrings{
|
|
|
|
{"constantCondition", TargetType::ConstantCondition},
|
|
|
|
{"underflow", TargetType::Underflow},
|
|
|
|
{"overflow", TargetType::Overflow},
|
|
|
|
{"divByZero", TargetType::DivByZero},
|
|
|
|
{"balance", TargetType::Balance},
|
|
|
|
{"assert", TargetType::Assert},
|
|
|
|
{"popEmptyArray", TargetType::PopEmptyArray},
|
|
|
|
{"outOfBounds", TargetType::OutOfBounds}
|
|
|
|
};
|
|
|
|
|
2021-01-19 11:56:22 +00:00
|
|
|
std::optional<ModelCheckerTargets> ModelCheckerTargets::fromString(string const& _targets)
|
|
|
|
{
|
|
|
|
set<TargetType> chosenTargets;
|
2021-07-07 10:31:09 +00:00
|
|
|
if (_targets == "default" || _targets == "all")
|
|
|
|
{
|
|
|
|
bool all = _targets == "all";
|
2021-05-07 13:42:17 +00:00
|
|
|
for (auto&& v: targetStrings | ranges::views::values)
|
2021-07-07 10:31:09 +00:00
|
|
|
{
|
|
|
|
if (!all && (v == TargetType::Underflow || v == TargetType::Overflow))
|
|
|
|
continue;
|
2021-01-19 11:56:22 +00:00
|
|
|
chosenTargets.insert(v);
|
2021-07-07 10:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-19 11:56:22 +00:00
|
|
|
else
|
2021-05-07 13:42:17 +00:00
|
|
|
for (auto&& t: _targets | ranges::views::split(',') | ranges::to<vector<string>>())
|
2021-01-19 11:56:22 +00:00
|
|
|
{
|
|
|
|
if (!targetStrings.count(t))
|
|
|
|
return {};
|
|
|
|
chosenTargets.insert(targetStrings.at(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ModelCheckerTargets{chosenTargets};
|
|
|
|
}
|
2021-04-14 10:56:43 +00:00
|
|
|
|
|
|
|
bool ModelCheckerTargets::setFromString(string const& _target)
|
|
|
|
{
|
|
|
|
if (!targetStrings.count(_target))
|
|
|
|
return false;
|
|
|
|
targets.insert(targetStrings.at(_target));
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-15 10:31:45 +00:00
|
|
|
|
|
|
|
std::optional<ModelCheckerContracts> ModelCheckerContracts::fromString(string const& _contracts)
|
|
|
|
{
|
|
|
|
map<string, set<string>> chosen;
|
|
|
|
if (_contracts == "default")
|
|
|
|
return ModelCheckerContracts::Default();
|
|
|
|
|
2021-05-07 13:42:17 +00:00
|
|
|
for (auto&& sourceContract: _contracts | ranges::views::split(',') | ranges::to<vector<string>>())
|
2021-04-15 10:31:45 +00:00
|
|
|
{
|
2021-05-07 13:42:17 +00:00
|
|
|
auto&& names = sourceContract | ranges::views::split(':') | ranges::to<vector<string>>();
|
2021-04-15 10:31:45 +00:00
|
|
|
if (names.size() != 2 || names.at(0).empty() || names.at(1).empty())
|
|
|
|
return {};
|
|
|
|
chosen[names.at(0)].insert(names.at(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ModelCheckerContracts{chosen};
|
|
|
|
}
|