Warn about multiple assignments to storage byte pushes and fix warnings about multiple storage to storage copies.

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Daniel Kirchner
2022-06-15 13:53:05 +02:00
co-authored by Kamil Śliwak
parent d30b04674e
commit 16245f7b9b
9 changed files with 129 additions and 24 deletions
@@ -0,0 +1,14 @@
contract C {
bytes1[] x;
bytes1[] z;
function f() public {
(x.push(), x.push()) = (0, 0);
(((x.push())), (x.push())) = (0, 0);
((x.push(), x.push()), x.push()) = ((0, 0), 0);
(x.push(), x[0]) = (0, 0);
bytes1[] storage y = x;
(x.push(), y.push()) = (0, 0);
(x.push(), z.push()) = (0, 0);
}
}
// ----
@@ -0,0 +1,8 @@
contract C {
bytes x;
function f() public {
(x[0], x[1]) = (0, 0);
(x[0], x[1]) = (x[1], x[0]);
}
}
// ----
@@ -0,0 +1,21 @@
contract C {
bytes x;
bytes z;
function f() public {
(x.push(), x.push()) = (0, 0);
(((x.push())), (x.push())) = (0, 0);
((x.push(), x.push()), x.push()) = ((0, 0), 0);
(x.push(), x[0]) = (0, 0);
bytes storage y = x;
(x.push(), y.push()) = (0, 0);
// The following is a false positive.
(x.push(), z.push()) = (0, 0);
}
}
// ----
// Warning 7239: (73-102): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.
// Warning 7239: (112-147): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.
// Warning 7239: (157-203): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.
// Warning 7239: (213-238): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.
// Warning 7239: (277-306): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.
// Warning 7239: (362-391): This assignment involves multiple accesses to a bytes array in storage while simultaneously enlarging it. When a bytes array is enlarged, it may transition from short storage layout to long storage layout, which invalidates all references to its elements. It is safer to only enlarge byte arrays in a single operation, one element at a time.