Skip to content

Commit 550b207

Browse files
committed
Add tests
1 parent 0552458 commit 550b207

4 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
contract C {
2+
uint256 y = 42;
3+
4+
function getArray() internal returns (uint256[10][1] storage x) {
5+
assembly {
6+
x.slot := sub(0, 1)
7+
}
8+
}
9+
10+
function f() public returns (uint256[10] memory) {
11+
uint256[10][1] storage x = getArray();
12+
for (uint i = 0; i < 10; i++)
13+
x[0][i] = i;
14+
delete x[0];
15+
return x[0];
16+
}
17+
18+
function g() public view returns (uint256) {
19+
return y;
20+
}
21+
}
22+
23+
// ----
24+
// g() -> 42
25+
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
26+
// gas irOptimized: 168243
27+
// gas legacy: 170463
28+
// gas legacyOptimized: 168219
29+
// g() -> 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
contract C {
2+
mapping(string => uint256[256][2**240]) m;
3+
4+
function f() public returns (uint256[256] memory) {
5+
uint256[256][2**240] storage a = m["v 2.2.3"]; // storage slot at: 115727151504557284028719796883655996022159813646012550228975965253679287557055
6+
uint256 slot;
7+
assembly {
8+
slot := a.slot
9+
}
10+
11+
// Pick the largest k such that `slot + 256 * k` <= `2**256 - 1`
12+
uint240 k = uint240((type(uint256).max - slot) / 256);
13+
require(k <= type(uint240).max);
14+
15+
a[k] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
16+
delete a[k];
17+
return a[k];
18+
}
19+
}
20+
21+
// ----
22+
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
23+
// gas irOptimized: 723216
24+
// gas legacyOptimized: 717881
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
contract C {
2+
function getArray() internal returns (uint256[10][1] storage x) {
3+
assembly {
4+
x.slot := sub(0, 1)
5+
}
6+
}
7+
function f() public returns (uint256[10] memory) {
8+
uint256[10][1] storage x = getArray();
9+
for (uint i = 0; i < 10; i++)
10+
x[0][i] = i;
11+
x[0] = [11, 12, 13];
12+
return x[0];
13+
}
14+
}
15+
// ----
16+
// f() -> 11, 12, 13, 0, 0, 0, 0, 0, 0, 0
17+
// gas irOptimized: 198025
18+
// gas legacy: 200268
19+
// gas legacyOptimized: 198039
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
contract C layout at 2**256 - 2 {
2+
uint256 a;
3+
4+
function getArray() internal returns (uint256[10][1] storage x) {
5+
assembly {
6+
x.slot := a.slot
7+
}
8+
}
9+
10+
function f() public returns (uint256[10] memory) {
11+
uint256[10][1] storage x = getArray();
12+
for (uint i = 0; i < 10; i++)
13+
x[0][i] = i;
14+
delete x[0];
15+
return x[0];
16+
}
17+
}
18+
// ----
19+
// f() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
20+
// gas irOptimized: 181930
21+
// gas legacy: 184143
22+
// gas legacyOptimized: 181900

0 commit comments

Comments
 (0)