Skip to content

Commit 4cf4cca

Browse files
author
Leo Alt
committed
New tests
1 parent 85378b1 commit 4cf4cca

18 files changed

+303
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract C {
2+
constructor() payable {
3+
assert(address(this).balance == 0); // should fail
4+
assert(address(this).balance > 0); // should fail
5+
}
6+
}
7+
// ====
8+
// SMTEngine: all
9+
// ----
10+
// Warning 6328: (40-74): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()
11+
// Warning 6328: (93-126): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
contract C {
2+
constructor() payable {
3+
require(msg.value > 100);
4+
}
5+
function f() public view {
6+
assert(address(this).balance > 100); // should hold
7+
assert(address(this).balance > 200); // should fail
8+
}
9+
}
10+
// ====
11+
// SMTEngine: all
12+
// ----
13+
// Warning 6328: (153-188): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor(){ value: 101 }\nC.f()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
contract C {
2+
uint prevBalance;
3+
constructor() payable {
4+
prevBalance = address(this).balance;
5+
}
6+
function f() public payable {
7+
assert(address(this).balance == prevBalance + msg.value); // should fail because there might be funds from selfdestruct/block.coinbase
8+
assert(address(this).balance < prevBalance + msg.value); // should fail
9+
assert(address(this).balance >= prevBalance + msg.value); // should hold
10+
prevBalance = address(this).balance;
11+
}
12+
}
13+
// ====
14+
// SMTEngine: all
15+
// ----
16+
// Warning 6328: (132-188): CHC: Assertion violation happens here.\nCounterexample:\nprevBalance = 0\n\nTransaction trace:\nC.constructor()\nState: prevBalance = 0\nC.f(){ value: 168 }
17+
// Warning 6328: (269-324): CHC: Assertion violation happens here.\nCounterexample:\nprevBalance = 0\n\nTransaction trace:\nC.constructor()\nState: prevBalance = 0\nC.f(){ value: 1201 }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
contract C {
2+
uint x;
3+
bool once;
4+
constructor() payable {
5+
x = address(this).balance;
6+
}
7+
function f() public payable {
8+
require(!once);
9+
once = true;
10+
require(msg.value > 0);
11+
assert(address(this).balance > x); // should hold
12+
assert(address(this).balance > x + 10); // should fail
13+
}
14+
}
15+
// ====
16+
// SMTEngine: all
17+
// ----
18+
// Warning 4984: (266-272): CHC: Overflow (resulting value larger than 2**256 - 1) happens here.\nCounterexample:\nx = 115792089237316195423570985008687907853269984665640564039457584007913129639926, once = true\n\nTransaction trace:\nC.constructor(){ value: 28100 }\nState: x = 115792089237316195423570985008687907853269984665640564039457584007913129639926, once = false\nC.f(){ value: 8 }
19+
// Warning 6328: (235-273): CHC: Assertion violation happens here.\nCounterexample:\nx = 0, once = true\n\nTransaction trace:\nC.constructor()\nState: x = 0, once = false\nC.f(){ value: 8 }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
contract C {
2+
constructor() payable {
3+
assert(address(this).balance == msg.value); // should fail because there might be funds from before deployment
4+
}
5+
}
6+
// ====
7+
// SMTEngine: all
8+
// ----
9+
// Warning 6328: (40-82): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
contract C {
2+
uint c;
3+
function f() public payable {
4+
require(msg.value > 10);
5+
++c;
6+
}
7+
function inv() public view {
8+
assert(address(this).balance >= c * 10); // should hold
9+
assert(address(this).balance >= c * 12); // should fail
10+
}
11+
}
12+
// ====
13+
// SMTEngine: all
14+
// ----
15+
// Warning 4984: (82-85): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
16+
// Warning 4984: (154-160): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
17+
// Warning 4984: (212-218): CHC: Overflow (resulting value larger than 2**256 - 1) might happen here.
18+
// Warning 6328: (180-219): CHC: Assertion violation happens here.\nCounterexample:\nc = 1\n\nTransaction trace:\nC.constructor()\nState: c = 0\nC.f(){ value: 11 }\nState: c = 1\nC.inv()
19+
// Warning 2661: (82-85): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
20+
// Warning 2661: (154-160): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
21+
// Warning 2661: (212-218): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contract C {
2+
uint sum = msg.value;
3+
function f() public payable {
4+
sum += msg.value;
5+
}
6+
function inv() public view {
7+
assert(address(this).balance == sum); // should fail
8+
assert(address(this).balance >= sum); // should hold
9+
}
10+
}
11+
// ====
12+
// SMTEngine: all
13+
// ----
14+
// Warning 6328: (122-158): CHC: Assertion violation happens here.\nCounterexample:\nsum = 0\n\nTransaction trace:\nC.constructor()\nState: sum = 0\nC.inv()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
contract C {
2+
bool once;
3+
function f() public payable {
4+
require(!once);
5+
once = true;
6+
require(msg.value == 10);
7+
assert(address(this).balance >= 10); // should hold
8+
assert(address(this).balance >= 20); // should fail
9+
g();
10+
}
11+
function g() internal view {
12+
assert(address(this).balance >= 10); // should hold
13+
assert(address(this).balance >= 20); // should fail
14+
h();
15+
}
16+
function h() internal view {
17+
assert(address(this).balance >= 10); // should hold
18+
assert(address(this).balance >= 20); // should fail
19+
}
20+
}
21+
// ====
22+
// SMTEngine: all
23+
// ----
24+
// Warning 6328: (173-208): CHC: Assertion violation happens here.\nCounterexample:\nonce = true\n\nTransaction trace:\nC.constructor()\nState: once = false\nC.f(){ value: 10 }
25+
// Warning 6328: (321-356): CHC: Assertion violation happens here.\nCounterexample:\nonce = true\n\nTransaction trace:\nC.constructor()\nState: once = false\nC.f(){ value: 10 }\n C.g(){ value: 10 } -- internal call
26+
// Warning 6328: (469-504): CHC: Assertion violation happens here.\nCounterexample:\nonce = true\n\nTransaction trace:\nC.constructor()\nState: once = false\nC.f(){ value: 10 }\n C.g(){ value: 10 } -- internal call\n C.h(){ value: 10 } -- internal call
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
interface I {
2+
function ext() external;
3+
}
4+
5+
contract C {
6+
function f(I _i) public {
7+
uint x = address(this).balance;
8+
_i.ext();
9+
assert(address(this).balance == x); // should fail
10+
assert(address(this).balance >= x); // should hold
11+
}
12+
}
13+
// ====
14+
// SMTEngine: all
15+
// ----
16+
// Warning 1218: (131-165): CHC: Error trying to invoke SMT solver.
17+
// Warning 6328: (131-165): CHC: Assertion violation might happen here.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
contract C {
2+
function f(address _a) public {
3+
uint x = address(this).balance;
4+
_a.call("");
5+
assert(address(this).balance == x); // should fail
6+
assert(address(this).balance >= x); // should hold
7+
}
8+
}
9+
// ====
10+
// SMTEngine: all
11+
// ----
12+
// Warning 9302: (82-93): Return value of low-level calls not used.
13+
// Warning 6328: (97-131): CHC: Assertion violation happens here.\nCounterexample:\n\n_a = 0\nx = 5921\n\nTransaction trace:\nC.constructor()\nC.f(0)\n _a.call("") -- untrusted external call, synthesized as:\n C.f(0) -- reentrant call\n _a.call("") -- untrusted external call

0 commit comments

Comments
 (0)