Skip to content

Commit ee6285d

Browse files
author
Leo Alt
committed
Do not create VCs for underoverflow by default for Sol >=0.8
1 parent 6ec711b commit ee6285d

File tree

28 files changed

+321
-309
lines changed

28 files changed

+321
-309
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Compiler Features:
1111
* Commandline Interface: option ``--pretty-json`` works also with ``--standard--json``.
1212
* SMTChecker: Unproved targets are hidden by default, and the SMTChecker only states how many unproved targets there are. They can be listed using the command line option ``--model-checker-show-unproved`` or the JSON option ``settings.modelChecker.showUnproved``.
1313
* SMTChecker: new setting to enable/disable encoding of division and modulo with slack variables. The command line option is ``--model-checker-div-mod-slacks`` and the JSON option is ``settings.modelChecker.divModWithSlacks``.
14+
* SMTChecker: Do not check underflow and overflow by default.
1415

1516

1617
Bugfixes:

docs/smtchecker.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ The other verification targets that the SMTChecker checks at compile time are:
3434
- Out of bounds index access.
3535
- Insufficient funds for a transfer.
3636

37+
All the targets above are automatically checked by default if all engines are
38+
enabled, except underflow and overflow for Solidity >=0.8.7.
39+
3740
The potential warnings that the SMTChecker reports are:
3841

3942
- ``<failing property> happens here.``. This means that the SMTChecker proved that a certain property fails. A counterexample may be given, however in complex situations it may also not show a counterexample. This result may also be a false positive in certain cases, when the SMT encoding adds abstractions for Solidity code that is either hard or impossible to express.
@@ -93,8 +96,10 @@ Overflow
9396
}
9497
9598
The contract above shows an overflow check example.
96-
The SMTChecker will, by default, check every reachable arithmetic operation
97-
in the contract for potential underflow and overflow.
99+
The SMTChecker does not check underflow and overflow by default for Solidity >=0.8.7,
100+
so we need to use the command line option ``--model-checker-targets "underflow,overflow"``
101+
or the JSON option ``settings.modelChecker.targets = ["underflow", "overflow"]``.
102+
See :ref:`this section for targets configuration<smtchecker_targets>`.
98103
Here, it reports the following:
99104

100105
.. code-block:: text
@@ -447,6 +452,8 @@ If the SMTChecker does not manage to solve the contract properties with the defa
447452
a timeout can be given in milliseconds via the CLI option ``--model-checker-timeout <time>`` or
448453
the JSON option ``settings.modelChecker.timeout=<time>``, where 0 means no timeout.
449454

455+
.. _smtchecker_targets:
456+
450457
Verification Targets
451458
====================
452459

@@ -471,6 +478,8 @@ The keywords that represent the targets are:
471478
A common subset of targets might be, for example:
472479
``--model-checker-targets assert,overflow``.
473480

481+
All targets are checked by default, except underflow and overflow for Solidity >=0.8.7.
482+
474483
There is no precise heuristic on how and when to split verification targets,
475484
but it can be useful especially when dealing with large contracts.
476485

docs/using-the-compiler.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ Input Description
415415
"solvers": ["cvc4", "smtlib2", "z3"],
416416
// Choose which targets should be checked: constantCondition,
417417
// underflow, overflow, divByZero, balance, assert, popEmptyArray, outOfBounds.
418-
// If the option is not given all targets are checked by default.
418+
// If the option is not given all targets are checked by default,
419+
// except underflow/overflow for Solidity >=0.8.7.
419420
// See the Formal Verification section for the targets description.
420421
"targets": ["underflow", "overflow", "assert"],
421422
// Timeout for each SMT query in milliseconds.

libsolidity/formal/ModelCheckerSettings.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ map<string, TargetType> const ModelCheckerTargets::targetStrings{
4040
std::optional<ModelCheckerTargets> ModelCheckerTargets::fromString(string const& _targets)
4141
{
4242
set<TargetType> chosenTargets;
43-
if (_targets == "default")
43+
if (_targets == "default" || _targets == "all")
44+
{
45+
bool all = _targets == "all";
4446
for (auto&& v: targetStrings | ranges::views::values)
47+
{
48+
if (!all && (v == TargetType::Underflow || v == TargetType::Overflow))
49+
continue;
4550
chosenTargets.insert(v);
51+
}
52+
}
4653
else
4754
for (auto&& t: _targets | ranges::views::split(',') | ranges::to<vector<string>>())
4855
{

libsolidity/formal/ModelCheckerSettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ enum class VerificationTargetType { ConstantCondition, Underflow, Overflow, Unde
9191

9292
struct ModelCheckerTargets
9393
{
94+
/// Adds the default targets, that is, all except underflow and overflow.
9495
static ModelCheckerTargets Default() { return *fromString("default"); }
96+
/// Adds all targets, including underflow and overflow.
97+
static ModelCheckerTargets All() { return *fromString("all"); }
9598

9699
static std::optional<ModelCheckerTargets> fromString(std::string const& _targets);
97100

solc/CommandLineParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ General Information)").c_str(),
743743
)
744744
(
745745
g_strModelCheckerTargets.c_str(),
746-
po::value<string>()->value_name("default,constantCondition,underflow,overflow,divByZero,balance,assert,popEmptyArray,outOfBounds")->default_value("default"),
746+
po::value<string>()->value_name("default,all,constantCondition,underflow,overflow,divByZero,balance,assert,popEmptyArray,outOfBounds")->default_value("default"),
747747
"Select model checker verification targets. "
748-
"Multiple targets can be selected at the same time, separated by a comma "
749-
"and no spaces."
748+
"Multiple targets can be selected at the same time, separated by a comma and no spaces."
749+
" By default all targets except underflow and overflow are selected."
750750
)
751751
(
752752
g_strModelCheckerTimeout.c_str(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--model-checker-engine all --model-checker-targets all

test/cmdlineTests/model_checker_targets_all/err renamed to test/cmdlineTests/model_checker_targets_all_all_engines/err

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Transaction trace:
88
test.constructor()
99
State: arr = []
1010
test.f(0, 0)
11-
--> model_checker_targets_all/input.sol:7:3:
11+
--> model_checker_targets_all_all_engines/input.sol:7:3:
1212
|
1313
7 | --x;
1414
| ^^^
@@ -23,7 +23,7 @@ Transaction trace:
2323
test.constructor()
2424
State: arr = []
2525
test.f(0, 2)
26-
--> model_checker_targets_all/input.sol:8:3:
26+
--> model_checker_targets_all_all_engines/input.sol:8:3:
2727
|
2828
8 | x + type(uint).max;
2929
| ^^^^^^^^^^^^^^^^^^
@@ -38,7 +38,7 @@ Transaction trace:
3838
test.constructor()
3939
State: arr = []
4040
test.f(0, 1)
41-
--> model_checker_targets_all/input.sol:9:3:
41+
--> model_checker_targets_all_all_engines/input.sol:9:3:
4242
|
4343
9 | 2 / x;
4444
| ^^^^^
@@ -53,7 +53,7 @@ Transaction trace:
5353
test.constructor()
5454
State: arr = []
5555
test.f(0, 1)
56-
--> model_checker_targets_all/input.sol:11:3:
56+
--> model_checker_targets_all_all_engines/input.sol:11:3:
5757
|
5858
11 | assert(x > 0);
5959
| ^^^^^^^^^^^^^
@@ -68,7 +68,7 @@ Transaction trace:
6868
test.constructor()
6969
State: arr = []
7070
test.f(0, 1)
71-
--> model_checker_targets_all/input.sol:12:3:
71+
--> model_checker_targets_all_all_engines/input.sol:12:3:
7272
|
7373
12 | arr.pop();
7474
| ^^^^^^^^^
@@ -83,20 +83,20 @@ Transaction trace:
8383
test.constructor()
8484
State: arr = []
8585
test.f(0, 1)
86-
--> model_checker_targets_all/input.sol:13:3:
86+
--> model_checker_targets_all_all_engines/input.sol:13:3:
8787
|
8888
13 | arr[x];
8989
| ^^^^^^
9090

9191
Warning: BMC: Condition is always true.
92-
--> model_checker_targets_all/input.sol:6:11:
92+
--> model_checker_targets_all_all_engines/input.sol:6:11:
9393
|
9494
6 | require(x >= 0);
9595
| ^^^^^^
9696
Note: Callstack:
9797

9898
Warning: BMC: Insufficient funds happens here.
99-
--> model_checker_targets_all/input.sol:10:3:
99+
--> model_checker_targets_all_all_engines/input.sol:10:3:
100100
|
101101
10 | a.transfer(x);
102102
| ^^^^^^^^^^^^^
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--model-checker-engine bmc --model-checker-targets default
1+
--model-checker-engine bmc --model-checker-targets all

0 commit comments

Comments
 (0)