Use .slot and .offest to access storage items.

This commit is contained in:
chriseth
2020-07-13 14:59:22 +02:00
parent 8eee3ed3a2
commit fc2e9ec2ff
60 changed files with 158 additions and 133 deletions
@@ -4,28 +4,28 @@ contract C {
function f() internal pure {
S storage c;
assembly {
for {} eq(0,0) { c_slot := s_slot } {}
for {} eq(0,0) { c.slot := s.slot } {}
}
c;
}
function g() internal pure {
S storage c;
assembly {
for {} eq(0,1) { c_slot := s_slot } {}
for {} eq(0,1) { c.slot := s.slot } {}
}
c;
}
function h() internal pure {
S storage c;
assembly {
for {} eq(0,0) {} { c_slot := s_slot }
for {} eq(0,0) {} { c.slot := s.slot }
}
c;
}
function i() internal pure {
S storage c;
assembly {
for {} eq(0,1) {} { c_slot := s_slot }
for {} eq(0,1) {} { c.slot := s.slot }
}
c;
}
@@ -4,14 +4,14 @@ contract C {
function f() internal pure {
S storage c;
assembly {
for { c_slot := s_slot } iszero(0) {} {}
for { c.slot := s.slot } iszero(0) {} {}
}
c;
}
function g() internal pure {
S storage c;
assembly {
for { c_slot := s_slot } iszero(1) {} {}
for { c.slot := s.slot } iszero(1) {} {}
}
c;
}
@@ -4,7 +4,7 @@ contract C {
function f(bool flag) internal pure {
S storage c;
assembly {
if flag { c_slot := s_slot }
if flag { c.slot := s.slot }
}
c;
}
@@ -7,7 +7,7 @@ contract C {
assembly {
function f() { return(0, 0) }
f()
c_slot := s_slot
c.slot := s.slot
}
c;
}
@@ -4,7 +4,7 @@ contract C {
function f() internal pure {
S storage c;
assembly {
c_slot := s_slot
c.slot := s.slot
}
c;
}
@@ -5,7 +5,7 @@ contract C {
S storage c;
assembly {
switch a
case 0 { c_slot := s_slot }
case 0 { c.slot := s.slot }
}
c;
}
@@ -13,8 +13,8 @@ contract C {
S storage c;
assembly {
switch flag
case 0 { c_slot := s_slot }
case 1 { c_slot := s_slot }
case 0 { c.slot := s.slot }
case 1 { c.slot := s.slot }
}
c;
}
@@ -22,7 +22,7 @@ contract C {
S storage c;
assembly {
switch a
case 0 { c_slot := s_slot }
case 0 { c.slot := s.slot }
default { return(0,0) }
}
c;
@@ -5,8 +5,8 @@ contract C {
S storage c;
assembly {
switch flag
case 0 { c_slot := s_slot }
default { c_slot := s_slot }
case 0 { c.slot := s.slot }
default { c.slot := s.slot }
}
c;
}
@@ -15,7 +15,7 @@ contract C {
assembly {
switch a
case 0 { revert(0, 0) }
default { c_slot := s_slot }
default { c.slot := s.slot }
}
c;
}
@@ -3,22 +3,22 @@ contract C {
S s;
function f() internal pure returns (S storage c) {
assembly {
for {} eq(0,0) { c_slot := s_slot } {}
for {} eq(0,0) { c.slot := s.slot } {}
}
}
function g() internal pure returns (S storage c) {
assembly {
for {} eq(0,1) { c_slot := s_slot } {}
for {} eq(0,1) { c.slot := s.slot } {}
}
}
function h() internal pure returns (S storage c) {
assembly {
for {} eq(0,0) {} { c_slot := s_slot }
for {} eq(0,0) {} { c.slot := s.slot }
}
}
function i() internal pure returns (S storage c) {
assembly {
for {} eq(0,1) {} { c_slot := s_slot }
for {} eq(0,1) {} { c.slot := s.slot }
}
}
}
@@ -3,12 +3,12 @@ contract C {
S s;
function f() internal pure returns (S storage c) {
assembly {
for { c_slot := s_slot } iszero(0) {} {}
for { c.slot := s.slot } iszero(0) {} {}
}
}
function g() internal pure returns (S storage c) {
assembly {
for { c_slot := s_slot } iszero(1) {} {}
for { c.slot := s.slot } iszero(1) {} {}
}
}
}
@@ -3,7 +3,7 @@ contract C {
S s;
function f(bool flag) internal pure returns (S storage c) {
assembly {
if flag { c_slot := s_slot }
if flag { c.slot := s.slot }
}
}
}
@@ -6,7 +6,7 @@ contract C {
assembly {
function f() { return(0, 0) }
f()
c_slot := s_slot
c.slot := s.slot
}
}
}
@@ -3,7 +3,7 @@ contract C {
S s;
function f() internal pure returns (S storage c) {
assembly {
c_slot := s_slot
c.slot := s.slot
}
}
}
@@ -4,20 +4,20 @@ contract C {
function f(uint256 a) internal pure returns (S storage c) {
assembly {
switch a
case 0 { c_slot := s_slot }
case 0 { c.slot := s.slot }
}
}
function g(bool flag) internal pure returns (S storage c) {
assembly {
switch flag
case 0 { c_slot := s_slot }
case 1 { c_slot := s_slot }
case 0 { c.slot := s.slot }
case 1 { c.slot := s.slot }
}
}
function h(uint256 a) internal pure returns (S storage c) {
assembly {
switch a
case 0 { c_slot := s_slot }
case 0 { c.slot := s.slot }
default { return(0,0) }
}
}
@@ -4,15 +4,15 @@ contract C {
function f(bool flag) internal pure returns (S storage c) {
assembly {
switch flag
case 0 { c_slot := s_slot }
default { c_slot := s_slot }
case 0 { c.slot := s.slot }
default { c.slot := s.slot }
}
}
function g(uint256 a) internal pure returns (S storage c) {
assembly {
switch a
case 0 { revert(0, 0) }
default { c_slot := s_slot }
default { c.slot := s.slot }
}
}
}
@@ -4,7 +4,7 @@ contract C {
function f(uint256 a) internal pure returns (S storage c) {
assembly {
switch a
default { c_slot := s_slot }
default { c.slot := s.slot }
}
}
}
@@ -1,7 +1,7 @@
contract C {
uint[] r;
function f() internal view returns (uint[] storage s) {
assembly { pop(s_slot) }
assembly { pop(s.slot) }
s = r;
}
}
@@ -2,9 +2,9 @@ contract test {
uint constant x = 2;
function f() pure public {
assembly {
let r := x_offset
let r := x.offset
}
}
}
// ----
// TypeError 6617: (112-120): The suffixes _offset and _slot can only be used on non-constant storage variables.
// TypeError 6617: (112-120): The suffixes .offset and .slot can only be used on non-constant storage variables.
@@ -3,7 +3,7 @@ contract test {
function f() public {
uint[] storage a = r;
assembly {
function g() -> x { x := a_offset }
function g() -> x { x := a.offset }
}
}
}
@@ -7,4 +7,4 @@ contract test {
}
}
// ----
// TypeError 1408: (89-90): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes.
// TypeError 1408: (89-90): Only local variables are supported. To access storage variables, use the .slot and .offset suffixes.
@@ -10,4 +10,4 @@ contract test {
}
}
// ----
// TypeError 1408: (80-81): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes.
// TypeError 1408: (80-81): Only local variables are supported. To access storage variables, use the .slot and .offset suffixes.
@@ -2,7 +2,7 @@ contract test {
uint a;
function f() pure public {
assembly {
function g() -> x { x := a_slot }
function g() -> x { x := a.slot }
}
}
}
@@ -5,4 +5,4 @@ contract c {
}
}
// ----
// TypeError 1408: (75-76): Only local variables are supported. To access storage variables, use the _slot and _offset suffixes.
// TypeError 1408: (75-76): Only local variables are supported. To access storage variables, use the .slot and .offset suffixes.
@@ -1,15 +1,11 @@
contract C {
function f() public pure {
assembly {
let x_offset := 1
let x_slot := 1
let _offset := 1
let _slot := 1
let x.offset := 1
let x.slot := 1
}
}
}
// ----
// DeclarationError 9155: (79-87): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError 9155: (109-115): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError 9155: (137-144): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError 9155: (166-171): In variable declarations _slot and _offset can not be used as a suffix.
// DeclarationError 3927: (79-87): User-defined identifiers in inline assembly cannot contain '.'.
// DeclarationError 3927: (109-115): User-defined identifiers in inline assembly cannot contain '.'.
@@ -16,4 +16,3 @@ contract B {
// ----
// DeclarationError 3859: (b:105-106): This declaration shadows a declaration outside the inline assembly block.
// DeclarationError 3927: (b:128-131): User-defined identifiers in inline assembly cannot contain '.'.
// DeclarationError 3859: (b:128-131): The prefix of this declaration conflicts with a declaration outside the inline assembly block.
@@ -11,6 +11,4 @@ contract C {
}
// ----
// DeclarationError 3927: (115-118): User-defined identifiers in inline assembly cannot contain '.'.
// DeclarationError 3859: (115-118): The prefix of this declaration conflicts with a declaration outside the inline assembly block.
// DeclarationError 3927: (140-143): User-defined identifiers in inline assembly cannot contain '.'.
// DeclarationError 3859: (140-143): The prefix of this declaration conflicts with a declaration outside the inline assembly block.
@@ -8,4 +8,4 @@ contract C {
}
}
// ----
// TypeError 9068: (118-119): You have to use the _slot or _offset suffix to access storage reference variables.
// TypeError 9068: (118-119): You have to use the .slot or .offset suffix to access storage reference variables.
@@ -3,10 +3,10 @@ contract C {
fallback() external {
uint[] storage y = x;
assembly {
y_slot := 1
y_offset := 2
y.slot := 1
y.offset := 2
}
}
}
// ----
// TypeError 9739: (138-146): Only _slot can be assigned to.
// TypeError 9739: (138-146): Only .slot can be assigned to.
@@ -2,8 +2,8 @@ contract C {
uint[] x;
fallback() external {
assembly {
x_slot := 1
x_offset := 2
x.slot := 1
x.offset := 2
}
}
}
@@ -1,9 +1,9 @@
contract C {
function f() public pure {
assembly {
let x := _offset
let x := .offset
}
}
}
// ----
// DeclarationError 4794: (84-91): In variable names _slot and _offset can only be used as a suffix.
// ParserError 1856: (84-85): Literal or identifier expected.
@@ -1,9 +1,9 @@
contract C {
function f() public pure {
assembly {
let x := _slot
let x := .slot
}
}
}
// ----
// DeclarationError 4794: (84-89): In variable names _slot and _offset can only be used as a suffix.
// ParserError 1856: (84-85): Literal or identifier expected.
@@ -3,8 +3,8 @@ contract C {
fallback() external {
uint[] storage y = x;
assembly {
pop(y_slot)
pop(y_offset)
pop(y.slot)
pop(y.offset)
}
}
}
@@ -0,0 +1,13 @@
contract C {
uint[] x;
fallback() external {
uint[] storage y = x;
assembly {
pop(y_slot)
pop(y_offset)
}
}
}
// ----
// DeclarationError 9467: (118-124): Identifier not found. Use ``.slot`` and ``.offset`` to access storage variables.
// DeclarationError 9467: (142-150): Identifier not found. Use ``.slot`` and ``.offset`` to access storage variables.
@@ -0,0 +1,14 @@
contract C {
uint[] x;
fallback() external {
uint y_slot = 2;
uint y_offset = 3;
uint[] storage y = x;
assembly {
pop(y_slot)
pop(y_offset)
}
y[0] = 2;
}
}
// ----
@@ -1,9 +1,9 @@
contract C {
function f() pure public {
assembly {
let x := f_slot
let x := f.slot
}
}
}
// ----
// TypeError 7944: (84-90): The suffixes _offset and _slot can only be used on storage variables.
// TypeError 7944: (84-90): The suffixes .offset and .slot can only be used on storage variables.
@@ -3,11 +3,11 @@ contract C {
fallback() external {
uint[] memory y = x;
assembly {
pop(y_slot)
pop(y_offset)
pop(y.slot)
pop(y.offset)
}
}
}
// ----
// TypeError 3622: (117-123): The suffixes _offset and _slot can only be used on storage variables.
// TypeError 3622: (141-149): The suffixes _offset and _slot can only be used on storage variables.
// TypeError 3622: (117-123): The suffixes .offset and .slot can only be used on storage variables.
// TypeError 3622: (141-149): The suffixes .offset and .slot can only be used on storage variables.
@@ -3,10 +3,10 @@ contract C {
fallback() external {
uint[] storage y = x;
assembly {
y_slot := 1
y_offset := 2
y.slot := 1
y.offset := 2
}
}
}
// ----
// TypeError 9739: (138-146): Only _slot can be assigned to.
// TypeError 9739: (138-146): Only .slot can be assigned to.
@@ -2,7 +2,7 @@ contract C {
struct S { uint x; }
S s;
function e() pure public {
assembly { mstore(keccak256(0, 20), mul(s_slot, 2)) }
assembly { mstore(keccak256(0, 20), mul(s.slot, 2)) }
}
function f() pure public {
uint x;