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

Remove Unnecessary Initialisation of _paused #5448

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

pcaversaccio
Copy link
Contributor

This PR removes the unnecessary initialisation of _paused. The state variable is already set at compile-time to false here:

Not sure if this requires a changeset. Feel free to push one.

Copy link

changeset-bot bot commented Jan 21, 2025

🦋 Changeset detected

Latest commit: 5184b31

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

@pcaversaccio pcaversaccio changed the title ♻️ Remove Unnecessary Initialisation of paused Remove Unnecessary Initialisation of _paused Jan 21, 2025
@ernestognw
Copy link
Member

Hi @pcaversaccio,

This change makes sense but the code pre-dates me so I wonder if I'm missing something. Also, this is strictly breaking but I wouldn't worry too much since it's easy to workaround and doesn't break smart contract upgrades.

Let's see if @Amxx has something to add.

@ernestognw ernestognw requested review from Amxx and a team January 21, 2025 15:53
@Amxx
Copy link
Collaborator

Amxx commented Jan 23, 2025

It also pre-dates me 😄

To me there are 2 things to consider:

  • "normal" contracts: the storage should definitelly be empty at construction, so setting it to false should have no effect. A good optimiser may remove that sstore, though I'm not sure it is the case.
    • The price of warming up the slot, an writting 0 to it, when it already contains 0, is 2200 gas (if the slot is not shared)
  • upgradeable contracts: if Pausing is added during an upgrade, the slot may be non-zero. In that case an initializer would do the clean up so that there is no risk the contract is paused by default.
    • With namespace storage, the likelyhood of this happening is extremelly low !

I'd be ok with that change. But I'm also curious if @frangio knows more about what we have that in the first place ?

@Amxx
Copy link
Collaborator

Amxx commented Jan 23, 2025

CI confirms, the optimizer doesn't remove that, so the change indeed saves +2k gas on deployment

Capture d’écran du 2025-01-23 10-44-21

@pcaversaccio
Copy link
Contributor Author

I did some research. The PR that added the change: #1403 & the issue from Nico: #1391. Previously it was like:

bool private _paused = false;

And since we all like memes and we should have more fun in life, I simply drop this here 😄:

image

@ernestognw
Copy link
Member

upgradeable contracts: if Pausing is added during an upgrade, the slot may be non-zero. In that case an initializer would do the clean up so that there is no risk the contract is paused by default.
With namespace storage, the likelyhood of this happening is extremelly low !

I was thinking something similar but I also don't see it happening with namespace storage.

@frangio
Copy link
Contributor

frangio commented Jan 23, 2025

bool private _paused = false;

Yeah this was the original code and it was just meant to be explicit and carried over until today. I think it's fine to remove it.

@arr00 arr00 merged commit a55fabc into OpenZeppelin:master Jan 23, 2025
18 checks passed
@pcaversaccio pcaversaccio deleted the refactor/pausable branch January 23, 2025 17:41
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.

5 participants