[SMTChecker] Fix internal error when array.push() is used as LHS of assignment

This commit is contained in:
Leonardo Alt
2020-11-02 13:32:53 +00:00
parent 1e812e7acc
commit e38d0db683
15 changed files with 245 additions and 15 deletions
@@ -0,0 +1,21 @@
pragma experimental SMTChecker;
contract C {
uint[] b;
function f() public {
require(b.length == 0);
b.push() = 1;
assert(b[0] == 1);
}
function g() public {
b.push() = 1;
assert(b[b.length - 1] == 1);
// Fails
assert(b[b.length - 1] == 100);
}
}
// ----
// Warning 6328: (232-262): CHC: Assertion violation happens here.
@@ -0,0 +1,24 @@
pragma experimental SMTChecker;
contract C {
uint[][] c;
function f() public {
require(c.length == 0);
c.push().push() = 2;
assert(c.length == 1);
assert(c[0].length == 1);
assert(c[0][0] == 2);
}
function g() public {
c.push().push() = 2;
assert(c.length > 0);
assert(c[c.length - 1].length == 1);
assert(c[c.length - 1][c[c.length - 1].length - 1] == 2);
// Fails
assert(c[c.length - 1][c[c.length - 1].length - 1] == 200);
}
}
// ----
// Warning 6328: (395-453): CHC: Assertion violation happens here.
@@ -0,0 +1,9 @@
pragma experimental SMTChecker;
contract C {
int[][] array2d;
function s() public returns (int[] memory) {
array2d.push() = array2d.push();
assert(array2d[array2d.length - 1].length == array2d[array2d.length - 2].length);
return array2d[2];
}
}
@@ -0,0 +1,30 @@
pragma experimental SMTChecker;
contract C {
uint[][][] c;
function f() public {
require(c.length == 0);
c.push().push().push() = 2;
assert(c.length == 1);
assert(c[0].length == 1);
assert(c[0][0].length == 1);
assert(c[0][0][0] == 2);
}
function g() public {
c.push().push().push() = 2;
uint length1 = c.length;
uint length2 = c[length1 - 1].length;
uint length3 = c[length1 - 1][length2 - 1].length;
assert(length1 > 0);
assert(length2 == 1);
assert(length3 == 1);
assert(c[length1 - 1][length2 - 1][length3 - 1] == 2);
// Fails
assert(c[length1 - 1][length2 - 1][length3 - 1] == 200);
}
}
// ----
// Warning 6328: (570-625): CHC: Assertion violation might happen here.
// Warning 4661: (570-625): BMC: Assertion violation happens here.
@@ -0,0 +1,16 @@
pragma experimental SMTChecker;
contract C {
uint[] b;
function f() public {
b.push() = b.push();
uint length = b.length;
assert(length >= 2);
assert(b[length - 1] == 0);
assert(b[length - 1] == b[length - 2]);
// Fails
assert(b[length - 1] == 1);
}
}
// ----
// Warning 6328: (237-263): CHC: Assertion violation happens here.
@@ -0,0 +1,19 @@
pragma experimental SMTChecker;
contract C {
uint[][] b;
function f() public {
require(b.length == 0);
b.push().push() = b.push().push();
assert(b.length == 2);
assert(b[0].length == 1);
assert(b[0].length == 1);
assert(b[0][0] == 0);
assert(b[1][0] == 0);
assert(b[0][0] == b[1][0]);
// Fails
assert(b[0][0] != b[1][0]);
}
}
// ----
// Warning 6328: (317-343): CHC: Assertion violation happens here.
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C {
uint[][] b;
function f() public {
b.push().push() = b.push().push();
uint length = b.length;
assert(length >= 2);
uint length1 = b[length - 1].length;
uint length2 = b[length - 2].length;
assert(length1 == 1);
assert(length2 == 1);
assert(b[length - 1][length1 - 1] == 0);
}
}
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C {
struct S {
int[] b;
}
S s;
struct T {
S s;
}
T t;
function f() public {
s.b.push() = t.s.b.push();
assert(s.b[s.b.length -1] == t.s.b[t.s.b.length - 1]);
}
}
@@ -0,0 +1,20 @@
pragma experimental SMTChecker;
contract C {
int[][] array2d;
function s() public returns (int[] memory) {
delete array2d.push();
assert(array2d[array2d.length - 1].length == 0);
// Fails
assert(array2d[array2d.length - 1].length != 0);
delete array2d.push().push();
uint length = array2d.length;
uint length2 = array2d[length - 1].length;
assert(array2d[length - 1][length2 - 1] == 0);
// Fails
assert(array2d[length - 1][length2 - 1] != 0);
return array2d[2];
}
}
// ----
// Warning 6328: (198-245): CHC: Assertion violation happens here.
// Warning 6328: (418-463): CHC: Assertion violation happens here.
@@ -0,0 +1,7 @@
pragma experimental SMTChecker;
contract A{
function f() public pure {
delete ([""][0]);
}
}