-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into upgradeToAndCallHardhat
- Loading branch information
Showing
72 changed files
with
3,480 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
* xref:index.adoc[Overview] | ||
* xref:truffle-upgrades.adoc[Using with Truffle] | ||
* xref:hardhat-upgrades.adoc[Using with Hardhat] | ||
** xref:defender-deploy.adoc[OpenZeppelin Defender integration] | ||
* xref:truffle-upgrades.adoc[Using with Truffle] | ||
* xref:writing-upgradeable.adoc[Writing Upgradeable Contracts] | ||
* xref:proxies.adoc[Proxy Upgrade Pattern] | ||
* xref:network-files.adoc[Network Files] | ||
* xref:faq.adoc[Frequently Asked Questions] | ||
.API Reference | ||
* xref:api-truffle-upgrades.adoc[Truffle Upgrades] | ||
* xref:api-hardhat-upgrades.adoc[Hardhat Upgrades] | ||
* xref:api-truffle-upgrades.adoc[Truffle Upgrades] | ||
* xref:api-core.adoc[Upgrades Core & CLI] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract Example { | ||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
uint256 x; | ||
uint256 y; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant MAIN_STORAGE_LOCATION = | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; | ||
|
||
function _getMainStorage() private pure returns (MainStorage storage $) { | ||
assembly { | ||
$.slot := MAIN_STORAGE_LOCATION | ||
} | ||
} | ||
|
||
function _getXTimesY() internal view returns (uint256) { | ||
MainStorage storage $ = _getMainStorage(); | ||
return $.x * $.y; | ||
} | ||
} | ||
|
||
contract MultipleNamespaces { | ||
/// @custom:storage-location erc7201:one | ||
struct S1 { | ||
uint256 a; | ||
} | ||
|
||
/// @custom:storage-location erc7201:two | ||
struct S2 { | ||
uint128 a; | ||
} | ||
} | ||
|
||
contract ExampleV2_Ok { | ||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
uint256 x; | ||
uint256 y; | ||
uint256 z; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant MAIN_STORAGE_LOCATION = | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; | ||
|
||
function _getMainStorage() private pure returns (MainStorage storage $) { | ||
assembly { | ||
$.slot := MAIN_STORAGE_LOCATION | ||
} | ||
} | ||
|
||
function _getXTimesYPlusZ() internal view returns (uint256) { | ||
MainStorage storage $ = _getMainStorage(); | ||
return $.x * $.y + $.z; | ||
} | ||
} | ||
|
||
contract ExampleV2_Bad { | ||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
uint256 y; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant MAIN_STORAGE_LOCATION = | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; | ||
|
||
function _getMainStorage() private pure returns (MainStorage storage $) { | ||
assembly { | ||
$.slot := MAIN_STORAGE_LOCATION | ||
} | ||
} | ||
|
||
function _getYSquared() internal view returns (uint256) { | ||
MainStorage storage $ = _getMainStorage(); | ||
return $.y * $.y; | ||
} | ||
} | ||
|
||
contract RecursiveStruct { | ||
struct MyStruct { | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
MyStruct s; | ||
uint256 y; | ||
} | ||
} | ||
|
||
contract RecursiveStructV2_Outer_Ok { | ||
struct MyStruct { | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
MyStruct s; | ||
uint256 y; | ||
uint256 z; | ||
} | ||
} | ||
|
||
contract RecursiveStructV2_Bad { | ||
struct MyStruct { | ||
uint128 a; | ||
uint256 b; | ||
uint256 c; | ||
} | ||
|
||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
MyStruct s; | ||
uint256 y; | ||
} | ||
} | ||
|
||
contract MultipleNamespacesAndRegularVariables { | ||
/// @custom:storage-location erc7201:one | ||
struct S1 { | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:two | ||
struct S2 { | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
uint128 public a; | ||
uint256 public b; | ||
} | ||
|
||
contract MultipleNamespacesAndRegularVariablesV2_Ok { | ||
/// @custom:storage-location erc7201:one | ||
struct S1 { | ||
uint128 a; | ||
uint256 b; | ||
uint256 c; | ||
} | ||
|
||
/// @custom:storage-location erc7201:two | ||
struct S2 { | ||
uint128 a; | ||
uint256 b; | ||
uint256 c; | ||
} | ||
|
||
uint128 public a; | ||
uint256 public b; | ||
uint256 public c; | ||
} | ||
|
||
contract MultipleNamespacesAndRegularVariablesV2_Bad { | ||
/// @custom:storage-location erc7201:one | ||
struct S1 { | ||
uint256 c; | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:two | ||
struct S2 { | ||
uint256 c; | ||
uint128 a; | ||
uint256 b; | ||
} | ||
|
||
uint256 public c; | ||
uint128 public a; | ||
uint256 public b; | ||
} |
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,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract DuplicateNamespace { | ||
function foo() public pure returns (uint256) { | ||
return 0; | ||
} | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting1 { | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting2 { | ||
uint256 c; | ||
} | ||
|
||
function foo2() public pure returns (uint256) { | ||
return 0; | ||
} | ||
} | ||
|
||
contract Parent { | ||
function foo5() public pure returns (uint256) { | ||
return 0; | ||
} | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting0 { | ||
uint256 a; | ||
} | ||
|
||
function foo6() public pure returns (uint256) { | ||
return 0; | ||
} | ||
} | ||
|
||
contract ConflictsWithParent is Parent { | ||
function foo3() public pure returns (uint256) { | ||
return 0; | ||
} | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting { | ||
uint256 a; | ||
} | ||
|
||
function foo4() public pure returns (uint256) { | ||
return 0; | ||
} | ||
} | ||
|
||
contract ConflictsInBothParents is DuplicateNamespace, ConflictsWithParent { | ||
uint256 a; | ||
} | ||
|
||
contract InheritsDuplicate is DuplicateNamespace { | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/core/contracts/test/NamespacedConflictsLayout.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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract DuplicateNamespace { | ||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting1 { | ||
uint256 b; | ||
} Conflicting1 $Conflicting1; | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting2 { | ||
uint256 c; | ||
} Conflicting2 $Conflicting2; | ||
} | ||
|
||
contract Parent { | ||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting0 { | ||
uint256 a; | ||
} Conflicting0 $Conflicting0; | ||
} | ||
|
||
contract ConflictsWithParent is Parent { | ||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting { | ||
uint256 a; | ||
} Conflicting $Conflicting; | ||
} | ||
|
||
contract ConflictsInBothParents is DuplicateNamespace, ConflictsWithParent { | ||
uint256 a; | ||
} | ||
|
||
contract InheritsDuplicate is DuplicateNamespace { | ||
} |
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract Example { | ||
MainStorage $MainStorage; | ||
|
||
/// @custom:storage-location erc7201:example.main | ||
struct MainStorage { | ||
uint256 x; | ||
uint256 y; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant MAIN_STORAGE_LOCATION = | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; | ||
} |
Oops, something went wrong.