Merge pull request #13139 from ethereum/lvalueBytesPushWarning

Warn about multiple assignments to storage byte pushes.
This commit is contained in:
Daniel Kirchner
2022-06-15 14:39:46 +02:00
committed by GitHub
9 changed files with 141 additions and 25 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.
@@ -4,6 +4,11 @@ contract C {
function f() public {
(x, y) = (y, x);
}
function g() public {
uint z;
((x, y), z) = ((y, x), 0);
}
}
// ----
// Warning 7238: (79-94): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first.
// Warning 7238: (134-159): This assignment performs two copies to storage. Since storage copies do not first copy to a temporary location, one of them might be overwritten before the second is executed and thus may have unexpected effects. It is safer to perform the copies separately or assign to storage pointers first.