mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Refactor VariableUsage
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
uint x;
|
||||
uint y;
|
||||
uint z;
|
||||
|
||||
function f() public {
|
||||
if (x == 1)
|
||||
x = 2;
|
||||
else
|
||||
x = 1;
|
||||
g();
|
||||
assert(y == 1);
|
||||
}
|
||||
|
||||
function g() public {
|
||||
y = 1;
|
||||
h();
|
||||
assert(z == 1);
|
||||
}
|
||||
|
||||
function h() public {
|
||||
z = 1;
|
||||
x = 1;
|
||||
f();
|
||||
// This fails for the following calls to the contract:
|
||||
// h()
|
||||
// g() h()
|
||||
// It does not fail for f() g() h() because in that case
|
||||
// h() will not inline f() since it already is in the callstack.
|
||||
assert(x == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (271-274): Assertion checker does not support recursive function calls.
|
||||
// Warning: (140-143): Assertion checker does not support recursive function calls.
|
||||
// Warning: (483-497): Assertion violation happens here
|
||||
// Warning: (201-204): Assertion checker does not support recursive function calls.
|
||||
// Warning: (483-497): Assertion violation happens here
|
||||
@@ -0,0 +1,19 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C
|
||||
{
|
||||
uint x;
|
||||
address owner;
|
||||
|
||||
modifier onlyOwner {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function f() public onlyOwner {
|
||||
}
|
||||
|
||||
function g(uint y) public {
|
||||
y = 1;
|
||||
if (y > x) f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
address owner;
|
||||
modifier onlyOwner {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
function g() public onlyOwner {
|
||||
}
|
||||
function f(uint x) public {
|
||||
if (x > 0) g();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint x;
|
||||
address owner;
|
||||
|
||||
modifier onlyOwner {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function f() public onlyOwner {
|
||||
x = 0;
|
||||
}
|
||||
function g(uint y) public {
|
||||
x = 1;
|
||||
if (y > 0)
|
||||
f();
|
||||
// Fails for {y = >0, msg.sender == owner, x = 0}.
|
||||
assert(x > 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (287-300): Assertion violation happens here
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint x;
|
||||
address owner;
|
||||
|
||||
modifier onlyOwner {
|
||||
if (msg.sender == owner) {
|
||||
require(x > 0);
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public onlyOwner {
|
||||
// Condition is always true due to `require(x > 0)` in the modifier.
|
||||
if (x > 0)
|
||||
x -= 1;
|
||||
}
|
||||
function g(uint y) public {
|
||||
x = 2;
|
||||
if (y > 0)
|
||||
f();
|
||||
assert(x > 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (266-271): Condition is always true.
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint x;
|
||||
address owner;
|
||||
|
||||
modifier onlyOwner {
|
||||
if (msg.sender == owner) {
|
||||
require(x > 0);
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public onlyOwner {
|
||||
x -= 1;
|
||||
h();
|
||||
}
|
||||
function h() public onlyOwner {
|
||||
require(x < 10000);
|
||||
x += 2;
|
||||
}
|
||||
function g(uint y) public {
|
||||
require(y > 0 && y < 10000);
|
||||
require(msg.sender == owner);
|
||||
x = y;
|
||||
if (y > 1) {
|
||||
f();
|
||||
assert(x == y + 1);
|
||||
}
|
||||
// Fails for {y = 0, x = 0}.
|
||||
assert(x == 0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (461-475): Assertion violation happens here
|
||||
Reference in New Issue
Block a user