Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade-safe storage for Initializable contract #10

Closed
Ramarti opened this issue Jun 23, 2023 · 0 comments · Fixed by #28
Closed

Upgrade-safe storage for Initializable contract #10

Ramarti opened this issue Jun 23, 2023 · 0 comments · Fixed by #28
Assignees

Comments

@Ramarti
Copy link
Contributor

Ramarti commented Jun 23, 2023

Remove _gaps in favor of namespaced storage, following https://eips.ethereum.org/EIPS/eip-7201

contract AbcUpgradeable {
  // keccak256(keccak256("storyprotocol.storage.Abc") - 1) = 0x123...
  bytes32 private AbcStorageLocation = 0x123...;

	/// @custom:oz-unsafe-allow immutable
  uint immutable z;

  /// @custom:storage-location ercXXXX:openzeppelin.storage.Abc
  struct AbcStorage {
    uint x;
    uint y;
  }

	function _getAbcStorage() private pure returns (AbcStorage storage $) {
    assembly {
      $.slot := AbcStorageLocation
    }
  }

  function _foo() internal view {
    AbcStorage storage $ = _getAbcStorage();
    $.x.sendValue($.y);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant