Merge pull request #6055 from ethereum/smt_arrays

[SMTChecker] Add support to arrays
This commit is contained in:
chriseth
2019-03-06 18:00:23 +01:00
committed by GitHub
39 changed files with 548 additions and 29 deletions
@@ -7,6 +7,4 @@ contract C
int[3*1] x;
}
// ----
// Warning: (92-100): Assertion checker does not yet support the type of this variable.
// Warning: (149-159): Assertion checker does not yet support the type of this variable.
// Warning: (153-156): Assertion checker does not yet implement this operator on non-integer types.
@@ -8,6 +8,5 @@ contract C
}
// ----
// Warning: (86-101): Assertion checker does not yet support this expression.
// Warning: (86-94): Assertion checker does not yet support this global variable.
// Warning: (86-101): Internal error: Expression undefined for SMT solver.
// Warning: (79-106): Assertion violation happens here
@@ -0,0 +1,31 @@
pragma experimental SMTChecker;
contract C
{
function f(
uint[] memory a,
uint[] memory b,
uint[][] memory cc,
uint8[][] memory dd,
uint[][][] memory eee
) internal pure {
require(a[0] == 2);
require(cc[0][0] == 50);
require(dd[0][0] == 10);
require(eee[0][0][0] == 50);
b[0] = 1;
// Fails because b == a is possible.
assert(a[0] == 2);
// Fails because b == cc[0] is possible.
assert(cc[0][0] == 50);
// Should not fail since knowledge is erased only for uint[].
assert(dd[0][0] == 10);
// Fails because b == ee[0][0] is possible.
assert(eee[0][0][0] == 50);
assert(b[0] == 1);
}
}
// ----
// Warning: (345-362): Assertion violation happens here
// Warning: (409-431): Assertion violation happens here
// Warning: (571-597): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
function f(uint[] memory a, uint[] memory b) internal view {
require(array[0] == 42);
require(a[0] == 2);
b[0] = 1;
// Erasing knowledge about memory references should not
// erase knowledge about state variables.
assert(array[0] == 42);
assert(a[0] == 2);
assert(b[0] == 1);
}
}
// ----
// Warning: (314-331): Assertion violation happens here
@@ -0,0 +1,22 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
function f(uint[] memory a, uint[] memory b) internal view {
require(array[0] == 42);
uint[] storage c = array;
require(a[0] == 2);
b[0] = 1;
// Erasing knowledge about memory references should not
// erase knowledge about state variables.
assert(array[0] == 42);
// Erasing knowledge about memory references should not
// erase knowledge about storage references.
assert(c[0] == 42);
assert(a[0] == 2);
assert(b[0] == 1);
}
}
// ----
// Warning: (469-486): Assertion violation happens here
@@ -0,0 +1,45 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
uint[][] array2d;
uint8[] tinyArray;
function f(
uint[] storage a,
uint[] storage b,
uint[][] storage cc,
uint8[][] storage dd,
uint[][][] storage eee
) internal {
require(a[0] == 2);
require(array[0] == 42);
require(array2d[0][0] == 42);
require(tinyArray[0] == 42);
require(cc[0][0] == 42);
require(dd[0][0] == 42);
require(eee[0][0][0] == 42);
b[0] = 1;
// Fails because b == a is possible.
assert(a[0] == 2);
// Fails because b == array is possible.
assert(array[0] == 42);
// Fails because b == array2d[0] is possible.
assert(array2d[0][0] == 42);
// Should not fail since knowledge is erased only for uint[].
assert(tinyArray[0] == 42);
// Fails because b == cc[0] is possible.
assert(cc[0][0] == 42);
// Should not fail since knowledge is erased only for uint[].
assert(dd[0][0] == 42);
// Fails because b == ee[0][0] is possible.
assert(eee[0][0][0] == 42);
assert(b[0] == 1);
}
}
// ----
// Warning: (489-506): Assertion violation happens here
// Warning: (553-575): Assertion violation happens here
// Warning: (627-654): Assertion violation happens here
// Warning: (795-817): Assertion violation happens here
// Warning: (957-983): Assertion violation happens here
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C
{
function f(uint[] storage a, uint[] storage b, uint[] memory c) internal {
require(c[0] == 42);
require(a[0] == 2);
b[0] = 1;
// Erasing knowledge about storage references should not
// erase knowledge about memory references.
assert(c[0] == 42);
// Fails because b == a is possible.
assert(a[0] == 2);
assert(b[0] == 1);
}
}
// ----
// Warning: (347-364): Assertion violation happens here
@@ -0,0 +1,22 @@
pragma experimental SMTChecker;
contract C
{
function f(uint[] storage a, uint[] storage b, uint[] memory c) internal {
uint[] memory d = c;
require(c[0] == 42);
require(a[0] == 2);
b[0] = 1;
// Erasing knowledge about storage references should not
// erase knowledge about memory references.
assert(c[0] == 42);
// Erasing knowledge about storage references should not
// erase knowledge about memory references.
assert(d[0] == 42);
// Fails because b == a is possible.
assert(a[0] == 2);
assert(b[0] == 1);
}
}
// ----
// Warning: (497-514): Assertion violation happens here
@@ -0,0 +1,19 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
function f(uint[] storage a, uint[] storage b) internal {
require(a[0] == 2);
require(b[0] == 42);
array[0] = 1;
// Fails because array == a is possible.
assert(a[0] == 2);
// Fails because array == b is possible.
assert(b[0] == 42);
assert(array[0] == 1);
}
}
// ----
// Warning: (226-243): Assertion violation happens here
// Warning: (290-308): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
function f(uint x, uint y) public {
array[x] = 200;
require(x == y);
assert(array[y] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[] array;
function f(uint x, uint y) public {
array[x] = 200;
require(x == y);
assert(array[y] > 300);
}
}
// ----
// Warning: (137-159): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[][] array;
function f(uint x, uint y, uint z, uint t) public view {
require(array[x][y] == 200);
require(x == z && y == t);
assert(array[z][t] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[][] array;
function f(uint x, uint y, uint z, uint t) public view {
require(array[x][y] == 200);
require(x == z && y == t);
assert(array[z][t] > 300);
}
}
// ----
// Warning: (183-208): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[][][] array;
function f(uint x, uint y, uint z, uint t, uint w, uint v) public view {
require(array[x][y][z] == 200);
require(x == t && y == w && z == v);
assert(array[t][w][v] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[][][] array;
function f(uint x, uint y, uint z, uint t, uint w, uint v) public view {
require(array[x][y][z] == 200);
require(x == t && y == w && z == v);
assert(array[t][w][v] > 300);
}
}
// ----
// Warning: (214-242): Assertion violation happens here
@@ -0,0 +1,10 @@
pragma experimental SMTChecker;
contract C
{
function f(uint[] memory array, uint x, uint y) public pure {
array[x] = 200;
require(x == y);
assert(array[y] > 100);
}
}
@@ -0,0 +1,12 @@
pragma experimental SMTChecker;
contract C
{
function f(uint[] memory array, uint x, uint y) public pure {
array[x] = 200;
require(x == y);
assert(array[y] > 300);
}
}
// ----
// Warning: (148-170): Assertion violation happens here
@@ -0,0 +1,12 @@
pragma experimental SMTChecker;
contract C
{
function f() public pure {
uint[3] memory array = [uint(1), 2, 3];
}
}
// ----
// Warning: (76-96): Unused local variable.
// Warning: (99-114): Assertion checker does not yet implement tuples and inline arrays.
// Warning: (99-114): Internal error: Expression undefined for SMT solver.
@@ -0,0 +1,24 @@
pragma experimental SMTChecker;
contract C
{
mapping (uint => uint) singleMap;
mapping (uint => uint)[] severalMaps;
mapping (uint => uint8)[] severalMaps8;
mapping (uint => uint)[][] severalMaps3d;
function f(mapping (uint => uint) storage map) internal {
require(severalMaps[0][0] == 42);
require(severalMaps8[0][0] == 42);
require(severalMaps3d[0][0][0] == 42);
map[0] = 2;
// Should fail since map == severalMaps[0] is possible.
assert(severalMaps[0][0] == 42);
// Should not fail since knowledge is erase only for mapping (uint => uint).
assert(severalMaps8[0][0] == 42);
// Should fail since map == severalMaps3d[0][0] is possible.
assert(severalMaps3d[0][0][0] == 42);
}
}
// ----
// Warning: (451-482): Assertion violation happens here
// Warning: (664-700): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[10] array;
function f(uint x, uint y) public {
array[x] = 200;
require(x == y);
assert(array[y] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[10] array;
function f(uint x, uint y) public {
array[x] = 200;
require(x == y);
assert(array[y] > 300);
}
}
// ----
// Warning: (139-161): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[10][20] array;
function f(uint x, uint y, uint z, uint t) public view {
require(array[x][y] == 200);
require(x == z && y == t);
assert(array[z][t] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[10][20] array;
function f(uint x, uint y, uint z, uint t) public view {
require(array[x][y] == 200);
require(x == z && y == t);
assert(array[z][t] > 300);
}
}
// ----
// Warning: (187-212): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
uint[10][20][30] array;
function f(uint x, uint y, uint z, uint t, uint w, uint v) public view {
require(array[x][y][z] == 200);
require(x == t && y == w && z == v);
assert(array[t][w][v] > 100);
}
}
@@ -0,0 +1,13 @@
pragma experimental SMTChecker;
contract C
{
uint[10][20][30] array;
function f(uint x, uint y, uint z, uint t, uint w, uint v) public view {
require(array[x][y][z] == 200);
require(x == t && y == w && z == v);
assert(array[t][w][v] > 300);
}
}
// ----
// Warning: (220-248): Assertion violation happens here
@@ -9,8 +9,3 @@ contract C
}
// ----
// Warning: (113-127): Unused local variable.
// Warning: (113-127): Assertion checker does not yet support the type of this variable.
// Warning: (58-72): Assertion checker does not yet support the type of this variable.
// Warning: (95-107): Assertion checker does not yet support the type of this variable.
// Warning: (130-131): Internal error: Expression undefined for SMT solver.
// Warning: (130-131): Assertion checker does not yet implement this type.
@@ -0,0 +1,9 @@
pragma experimental SMTChecker;
contract C
{
function f(bytes memory b1, bytes memory b2) public pure {
b1 = b2;
assert(b1[1] == b2[1]);
}
}
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
function f(bytes memory b1, bytes memory b2) public pure {
b1 = b2;
assert(b1[1] == b2[2]);
}
}
// ----
// Warning: (119-141): Assertion violation happens here
@@ -0,0 +1,28 @@
pragma experimental SMTChecker;
contract C
{
mapping (uint => uint) a;
mapping (uint => mapping (uint => uint)) maps;
mapping (uint => mapping (uint => uint8)) maps8;
function f(mapping (uint => uint) storage map1, mapping (uint => uint) storage map2) internal {
require(map1[0] == 2);
require(a[0] == 42);
require(maps[0][0] == 42);
require(maps8[0][0] == 42);
map2[0] = 1;
// Fails because map2 == map1 is possible.
assert(map1[0] == 2);
// Fails because map2 == a is possible.
assert(a[0] == 42);
// Fails because map2 == maps[0] is possible.
assert(maps[0][0] == 42);
// Should not fail since knowledge is erased only for mapping (uint => uint).
assert(maps8[0][0] == 42);
assert(map2[0] == 1);
}
}
// ----
// Warning: (437-457): Assertion violation happens here
// Warning: (503-521): Assertion violation happens here
// Warning: (573-597): Assertion violation happens here
@@ -9,9 +9,3 @@ contract C
}
}
// ----
// Warning: (89-104): Assertion checker does not yet support the type of this variable.
// Warning: (129-130): Internal error: Expression undefined for SMT solver.
// Warning: (129-130): Assertion checker does not yet implement this type.
// Warning: (155-156): Internal error: Expression undefined for SMT solver.
// Warning: (155-156): Assertion checker does not yet implement this type.
// Warning: (139-158): Assertion violation happens here
@@ -0,0 +1,14 @@
pragma experimental SMTChecker;
contract C
{
function f(string memory s1, string memory s2) public pure {
assert(bytes(s1).length == bytes(s2).length);
}
}
// ----
// Warning: (117-133): Assertion checker does not yet support this expression.
// Warning: (137-153): Assertion checker does not yet support this expression.
// Warning: (117-133): Internal error: Expression undefined for SMT solver.
// Warning: (137-153): Internal error: Expression undefined for SMT solver.
// Warning: (110-154): Assertion violation happens here
@@ -0,0 +1,11 @@
pragma experimental SMTChecker;
contract C
{
function f() public pure {
string memory s = "Hello World";
}
}
// ----
// Warning: (76-91): Unused local variable.
// Warning: (94-107): Assertion checker does not yet support the type of this literal (literal_string "Hello World").