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

Add _initializableStorageSlot #5337

Merged

Conversation

ernestognw
Copy link
Member

@ernestognw ernestognw commented Dec 3, 2024

Fixes #4782

Adding _initializableStorageSlot seems like a good abstraction for developers who want to override the initializable storage slot. This makes sense in the context of Account Abstraction since some wallets might reuse the slot. For these case it may be better that each implementation has its own customized slot.

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

Copy link

changeset-bot bot commented Dec 3, 2024

🦋 Changeset detected

Latest commit: 8b4e292

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openzeppelin-solidity Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ernestognw ernestognw requested a review from a team December 3, 2024 23:25
@ernestognw
Copy link
Member Author

Alternatively, we can make _getInitializableStorage internal. Thoughts?

@Amxx Amxx added this to the 5.3 milestone Dec 4, 2024
Copy link
Collaborator

@Amxx Amxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned by line 63

     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable // <<== HERE !
     */
    struct InitializableStorage {

This comment will be wrong if the value is overriden. How will the plugin handle that ?

@Amxx
Copy link
Collaborator

Amxx commented Dec 11, 2024

function _getInitializableStorage() internal virtual pure returns (InitializableStorage storage $) {

Would be a smaller change, that we could easily generalize to all the upgradeable contracts. The downside is that overriding it would likely require the user writting assembly.

@arr00
Copy link
Contributor

arr00 commented Dec 13, 2024

function _getInitializableStorage() internal virtual pure returns (InitializableStorage storage $) {

Would be a smaller change, that we could easily generalize to all the upgradeable contracts. The downside is that overriding it would likely require the user writting assembly.

I imagine that most teams requiring this functionality won't have an issue writing minimal yul. Don't think it's worth the extra function call just to bypass that.

Amxx
Amxx previously approved these changes Feb 13, 2025
@Amxx Amxx dismissed their stale review February 13, 2025 16:55

lets discuss more

@Amxx
Copy link
Collaborator

Amxx commented Feb 13, 2025

function _getInitializableStorage() internal virtual pure returns (InitializableStorage storage $) {

Would be a smaller change, that we could easily generalize to all the upgradeable contracts. The downside is that overriding it would likely require the user writting assembly.

I'm just realizing that this would not really be "good" to generalize, because it gives the developper direct/easy access to the storage. Its basically like making the storage variables internal instead of private. I don't think its a good idea.

Right now I'd favor the current code.

@arr00 @ernestognw wdyt ? should we finally merge this ?

Amxx
Amxx previously approved these changes Feb 19, 2025
arr00
arr00 previously approved these changes Feb 19, 2025
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
@ernestognw ernestognw dismissed stale reviews from arr00 and Amxx via 8b4e292 February 24, 2025 01:24
@ernestognw
Copy link
Member Author

ernestognw commented Feb 24, 2025

Would be a smaller change, that we could easily generalize to all the upgradeable contracts. The downside is that overriding it would likely require the user writting assembly.

I agree with this concern. However, I don't see a way around It given you can't override the NatSpec struct annotation.
Theoretically, if a user overrides the storage pointer using ERC-7201 (which the function already recommends), then collision should not be a risk.

I'm merging this PR, but I think we can discuss exploring an special annotation like @custom:storage-location-renamed-from erc7201:openzeppelin.storage.Initializable <...>

EDIT: I can't merge. Need approval again

@ernestognw ernestognw enabled auto-merge (squash) February 24, 2025 01:50
@ernestognw ernestognw merged commit 2ed8956 into OpenZeppelin:master Feb 24, 2025
17 checks passed
Amxx pushed a commit to Amxx/openzeppelin-contracts that referenced this pull request Feb 24, 2025
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Amxx pushed a commit to Amxx/openzeppelin-contracts that referenced this pull request Feb 24, 2025
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
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 this pull request may close these issues.

Rigidity in Initializable's INITIALIZABLE_STORAGE slot
3 participants