Skip to content

Remove Unnecessary Initialisation of _paused #5448

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

Merged
merged 2 commits into from
Jan 23, 2025
Merged

Remove Unnecessary Initialisation of _paused #5448

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
Dargon789 added a commit to Dargon789/openzeppelin-contracts that referenced this pull request Feb 15, 2025
* Update ReentrancyGuardTransient documentation (OpenZeppelin#5417)

* Optimize `MerkleTree` for loops by using `uint256` iterators (OpenZeppelin#5415)

Co-authored-by: Ernesto García <[email protected]>

* Update `_revokeRole` documentation in AccessControl (OpenZeppelin#5321)

Co-authored-by: Ernesto García <[email protected]>

* Merge release-v5.2 branch (OpenZeppelin#5424)

Signed-off-by: Hadrien Croubois <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Sam Bugs <[email protected]>
Co-authored-by: Ernesto García <[email protected]>
Co-authored-by: Arr00 <[email protected]>
Co-authored-by: wizard <[email protected]>
Co-authored-by: leopardracer <[email protected]>
Co-authored-by: cairo <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Francisco Giordano <[email protected]>
Co-authored-by: Simka <[email protected]>
Co-authored-by: Voronor <[email protected]>

* Add a Calldata library with `emptyBytes` and `emptyString` functions (OpenZeppelin#5422)

Co-authored-by: Ernesto García <[email protected]>

* Update governor docs (OpenZeppelin#5420)

* Add missing `Calldata`, `Bytes`, `CAIP2` and `CAIP10` API references (OpenZeppelin#5428)

* Expose `_isTrustedByTarget` internally in ERC2771Forwarder (OpenZeppelin#5416)

* Update LICENSE (OpenZeppelin#5434)

* Refactor EnumerableSet.behavior.js for reuse in the community repo (OpenZeppelin#5441)

* Replace `overriden` with `overridden` in GovernorCountingOverridable.sol (OpenZeppelin#5446)

Co-authored-by: Arr00 <[email protected]>
Co-authored-by: ernestognw <[email protected]>

* Remove Unnecessary Initialisation of `_paused` (OpenZeppelin#5448)

Co-authored-by: Ernesto García <[email protected]>

* Fix Broken Docs References (OpenZeppelin#5436)

* Update actions/upload-artifact action to v4 (OpenZeppelin#4826)

* Remove unused `setBaseURI` tests (OpenZeppelin#5456)

Co-authored-by: Hadrien Croubois <[email protected]>

* Group typographical errors (OpenZeppelin#5443)

Co-authored-by: futreall <[email protected]>
Co-authored-by: Marco <[email protected]>
Co-authored-by: Dmitry <[email protected]>
Co-authored-by: Dmytrol <[email protected]>
Co-authored-by: Noisy <[email protected]>
Co-authored-by: Danil <[email protected]>
Co-authored-by: CrazyFrog <[email protected]>
Co-authored-by: Bryer <[email protected]>
Co-authored-by: Viktor Pavlik <[email protected]>
Co-authored-by: Skylar Ray <[email protected]>
Co-authored-by: Brawn <[email protected]>
Co-authored-by: fuder.eth <[email protected]>
Co-authored-by: FT <[email protected]>
Co-authored-by: Ann Wagner <[email protected]>
Co-authored-by: Hopium <[email protected]>
Co-authored-by: Arr00 <[email protected]>
Co-authored-by: Hadrien Croubois <[email protected]>

* Fix interface docs ordering and add missing interface (OpenZeppelin#5460)

* Add a governor extension that implements a proposal guardian (OpenZeppelin#5303)

Co-authored-by: Arr00 <[email protected]>
Co-authored-by: Ernesto García <[email protected]>

* Fix the CLI output of formal verification runs (OpenZeppelin#5445)

* Update dependency halmos to v0.2.4 (OpenZeppelin#5461)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Use stable foundry version in CI (OpenZeppelin#5465)

* Add stake management function to ERC4337Utils (OpenZeppelin#5471)

* Add forum badge correct link (OpenZeppelin#5481)

* SafeERC20.trySafeTransfer{,from} (OpenZeppelin#5483)

* Improve promise rejections handling in hardhat/async-test-sanity.js (OpenZeppelin#5429)

Co-authored-by: Arr00 <[email protected]>

* Use slither v0.10.4 (OpenZeppelin#5488)

* Add ERC6909 Implementation along with extensions (OpenZeppelin#5394)

Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Ernesto García <[email protected]>

* Rename ERC4337Utils ENTRYPOINT to ENTRYPOINT_V07 (OpenZeppelin#5472)

Co-authored-by: Hadrien Croubois <[email protected]>

* Add Bytes32x2Set (OpenZeppelin#5442)

Co-authored-by: Ernesto García <[email protected]>

* Add clear function to Enumerable{Set,Map} (OpenZeppelin#5486)

Co-authored-by: Hadrien Croubois <[email protected]>

* Make set-max-old-space-size.sh compatible with sh (OpenZeppelin#5493)

Co-authored-by: Hadrien Croubois <[email protected]>

* Update FUNDING.json (OpenZeppelin#5496)

Co-authored-by: Hadrien Croubois <[email protected]>

* Update FUNDING.json hierarchy (OpenZeppelin#5500)

Co-authored-by: Hadrien Croubois <[email protected]>

* Test behavior of SignatureChecker against the identity precompile (0x4) (OpenZeppelin#5501)

* Treat code-size warnings as errors (OpenZeppelin#5101)

Co-authored-by: Hadrien Croubois <[email protected]>

* Make `TimelockController` receive function virtual (OpenZeppelin#5506)

Co-authored-by: Arr00 <[email protected]>
Co-authored-by: Hadrien Croubois <[email protected]>

---------

Signed-off-by: Hadrien Croubois <[email protected]>
Co-authored-by: Ernesto García <[email protected]>
Co-authored-by: Michael <[email protected]>
Co-authored-by: Maks <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Sam Bugs <[email protected]>
Co-authored-by: Arr00 <[email protected]>
Co-authored-by: wizard <[email protected]>
Co-authored-by: leopardracer <[email protected]>
Co-authored-by: cairo <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Francisco Giordano <[email protected]>
Co-authored-by: Simka <[email protected]>
Co-authored-by: Voronor <[email protected]>
Co-authored-by: Eric Lau <[email protected]>
Co-authored-by: planetBoy <[email protected]>
Co-authored-by: sudo rm -rf --no-preserve-root / <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renan Souza <[email protected]>
Co-authored-by: futreall <[email protected]>
Co-authored-by: Marco <[email protected]>
Co-authored-by: Dmitry <[email protected]>
Co-authored-by: Dmytrol <[email protected]>
Co-authored-by: Noisy <[email protected]>
Co-authored-by: Danil <[email protected]>
Co-authored-by: CrazyFrog <[email protected]>
Co-authored-by: Bryer <[email protected]>
Co-authored-by: Viktor Pavlik <[email protected]>
Co-authored-by: Skylar Ray <[email protected]>
Co-authored-by: Brawn <[email protected]>
Co-authored-by: fuder.eth <[email protected]>
Co-authored-by: FT <[email protected]>
Co-authored-by: Ann Wagner <[email protected]>
Co-authored-by: Hopium <[email protected]>
Co-authored-by: Yan Victor SN <[email protected]>
Co-authored-by: Ursula <[email protected]>
Co-authored-by: Michalis Kargakis <[email protected]>
Co-authored-by: luca <[email protected]>
Co-authored-by: Jonas <[email protected]>
Co-authored-by: Joseph Delong <[email protected]>
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