[SMTChecker] Support modifiers

This commit is contained in:
Leonardo Alt
2019-03-20 11:32:20 +01:00
parent 556d11dae0
commit 9659f40c8d
17 changed files with 374 additions and 8 deletions
@@ -0,0 +1,22 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
require(x > 0);
_;
// Fails because of overflow behavior.
// Overflow is not reported because this assertion prevents
// it from reaching the end of the function.
assert(x > 1);
}
function f() m public {
assert(x > 0);
x = x + 1;
}
}
// ----
// Warning: (245-258): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
if (x == 0)
_;
}
function f() m public view {
assert(x == 0);
assert(x > 1);
}
}
// ----
// Warning: (144-157): Assertion violation happens here
@@ -0,0 +1,25 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
require(x > 0);
require(x < 10000);
_;
}
modifier n {
x = x + 1;
_;
assert(x > 2);
assert(x > 8);
}
function f() m n public {
x = x + 1;
}
}
// ----
// Warning: (170-183): Assertion violation happens here
@@ -0,0 +1,26 @@
pragma experimental SMTChecker;
contract C
{
modifier m(uint a, uint b) {
require(g(a, b));
_;
}
modifier notZero(uint x) {
require(x > 0);
_;
}
function g(uint a, uint b) notZero(a) internal pure returns (bool) {
return a > b;
}
function f(uint x) m(x, 0) public pure {
assert(x > 0);
assert(x > 1);
}
}
// ----
// Warning: (86-93): Condition is always true.
// Warning: (311-324): Assertion violation happens here
@@ -0,0 +1,24 @@
pragma experimental SMTChecker;
contract C
{
modifier m(uint a, uint b) {
require(g(a, b));
_;
}
function g(uint a, uint b) m(a, b) internal pure returns (bool) {
return a > b;
}
function f(uint x) m(x, 0) public pure {
assert(x > 0);
assert(x > 1);
}
}
// ----
// Warning: (86-93): Assertion checker does not support recursive function calls.
// Warning: (86-93): Internal error: Expression undefined for SMT solver.
// Warning: (86-93): Assertion checker does not support recursive function calls.
// Warning: (86-93): Internal error: Expression undefined for SMT solver.
// Warning: (253-266): Assertion violation happens here
@@ -0,0 +1,16 @@
pragma experimental SMTChecker;
contract C
{
modifier m(uint a, uint b) {
require(a > b);
_;
}
function f(uint x) m(x, 0) public pure {
assert(x > 0);
assert(x > 1);
}
}
// ----
// Warning: (164-177): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
require(x > 0);
_;
}
function f() m public {
assert(x > 0);
x = x + 1;
}
}
// ----
// Warning: (145-150): Overflow (resulting value larger than 2**256 - 1) happens here
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C
{
modifier m(uint x) {
x == 2;
_;
}
function f(uint x) m(x) public pure {
assert(x == 2);
}
}
// ----
// Warning: (128-142): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C
{
uint s;
modifier m(uint a) {
// Condition is always true for m(2).
require(a > 0);
_;
}
function f(uint x) m(x) m(2) m(s) public view {
assert(x > 0);
assert(s > 0);
}
}
// ----
// Warning: (127-132): Condition is always true.
@@ -0,0 +1,21 @@
pragma experimental SMTChecker;
contract C
{
modifier m(uint x) {
require(x == 2);
_;
return;
}
modifier n(uint x) {
require(x == 3);
_;
}
function f(uint x) m(x) n(x) public pure {
assert(x == 3);
}
}
// ----
// Warning: (138-144): Condition is always false.
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C
{
modifier m {
uint x = 2;
_;
}
function f(uint x) m public pure {
assert(x == 2);
}
}
// ----
// Warning: (121-135): Assertion violation happens here
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
require(x > 0);
_;
}
function f() m public view {
assert(x > 0);
}
}
@@ -0,0 +1,21 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
// Condition is always true for the second invocation.
require(x > 0);
require(x < 10000);
_;
assert(x > 1);
}
function f() m m public {
x = x + 1;
}
}
// ----
// Warning: (137-142): Condition is always true.
// Warning: (155-164): Condition is always true.
@@ -0,0 +1,22 @@
pragma experimental SMTChecker;
contract C
{
uint x;
modifier m {
require(x > 0);
require(x < 10000);
_;
assert(x > 1);
_;
assert(x > 2);
assert(x > 10);
}
function f() m public {
x = x + 1;
}
}
// ----
// Warning: (156-170): Assertion violation happens here