OpenZeppelin / OpenZeppelin/openzeppelin-contracts

`Pausable` can be more gas efficient using a similar mechanism as in the `ReentrancyGuard`

Open
#4,650 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

breaking change
Dominant language
Solidity
Stars
27.2k
Forks
12.4k
Avg merge
2d 19h
Merged PRs (30d)
33

Description

I noticed that the Pausable contract can be optimized for gas usage by adopting a similar mechanism used in the ReentrancyGuard contract.

💻 Environment

OpenZeppelin Contracts 4.9.3

📝 Details

The ReentrancyGuard contract uses uint256 constants to avoid the extra gas costs associated with boolean operations. This mechanism can be applied to the Pausable contract to make it more gas-efficient.

🔢 Code to reproduce bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the Pausable and ReentrancyGuard contracts in OpenZeppelin Contracts 4.9.3, starting with how each represents and checks its state. Compare the gas impact of the existing Pausable mechanism with the proposed uint256-constant approach, then verify that pause and unpause behavior remains unchanged and gas usage improves.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain, performance, security
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.