-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix struct member read access (#1563)
Fixes a bug: `StorageLoad` after a struct member access is a storage read, this case was not considered in the mutability check. The regression in the EVM test is fine; it's caused by a [problem in solc](ethereum/solidity#11573) Signed-off-by: Cyrill Leutwiler <[email protected]> Signed-off-by: Sean Young <[email protected]>
- Loading branch information
Showing
10 changed files
with
133 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/contract_testcases/polkadot/functions/mutability_13.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
library StorageSlot { | ||
struct AddressSlot { | ||
address value; | ||
} | ||
|
||
function getAddressSlot( | ||
bytes32 slot | ||
) internal pure returns (AddressSlot storage r) { | ||
assembly { | ||
r.slot := slot | ||
} | ||
} | ||
} | ||
|
||
contract StorageKeys { | ||
function get(bytes32 key) public view returns (address a) { | ||
a = StorageSlot.getAddressSlot(key).value; | ||
} | ||
} | ||
|
||
// ---- Expect: diagnostics ---- |
15 changes: 15 additions & 0 deletions
15
tests/contract_testcases/polkadot/functions/mutability_14.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract Foo { | ||
address a; | ||
|
||
function r() internal view returns (address) { | ||
return msg.sender; | ||
} | ||
|
||
function foo() public pure { | ||
a = r(); | ||
} | ||
} | ||
|
||
// ---- Expect: diagnostics ---- | ||
// error: 9:9-10: function declared 'pure' but this expression writes to state | ||
// error: 9:13-16: function declared 'pure' but this expression reads from state |
16 changes: 16 additions & 0 deletions
16
tests/contract_testcases/polkadot/functions/mutability_15.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
contract C { | ||
string s; | ||
|
||
function test(string calldata x) public pure returns (string memory) { | ||
s = "foo"; | ||
s = x; | ||
print(s); | ||
return s; | ||
} | ||
} | ||
|
||
// ---- Expect: diagnostics ---- | ||
// error: 5:9-10: function declared 'pure' but this expression writes to state | ||
// error: 6:9-10: function declared 'pure' but this expression writes to state | ||
// error: 7:15-16: function declared 'pure' but this expression reads from state | ||
// error: 8:16-17: function declared 'pure' but this expression reads from state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters