-
Notifications
You must be signed in to change notification settings - Fork 12k
Add _reentrancyGuardStorageSlot() #5688
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
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 750a60b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Approved, I consider allowing storage slot overridability while keeping the formula |
While this looks good, I'd like to consider a different approach. See #5681 (comment) |
'openzeppelin-solidity': patch | ||
--- | ||
|
||
Add `_reentrancyGuardStorageSlot()` to `ReentrancyGuardTransient` as a `pure virtual` function to allow slot overrides for diamond-compatible modular usage. Related to #5681. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add `_reentrancyGuardStorageSlot()` to `ReentrancyGuardTransient` as a `pure virtual` function to allow slot overrides for diamond-compatible modular usage. Related to #5681. | |
`ReentrancyGuardTransient`: Add `_reentrancyGuardStorageSlot()`, a `pure virtual` function, that can be overriden to allow slot customization. |
return _reentrancyGuardStorageSlot().asBoolean().tload(); | ||
} | ||
|
||
function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that be
_reentrancyGuardStorageSlot()
_reentrancyGuardTransientSlot()
_reentrancyGuardTransientStorageSlot()
Here, the contract only uses transient, but what if a contract combined transient and normal storage ? Would we want the two types to use the same slot, or would we allow separating the two ?
Fixes #5681 for ReentrancyGuardTransient.
This PR introduces a pure virtual function
_reentrancyGuardStorageSlot()
inReentrancyGuardTransient.sol
, mirroring the pattern used in the upgradeable Initializable.solMotivation
As discussed in #5681, storage slot collisions can occur when using OpenZeppelin contracts in delegatecall-based modular systems (e.g., the Diamond Standard). While this issue was originally raised in the context of upgradeable contracts,
ReentrancyGuardTransient.sol
in the non-upgradeable repo is in fact already upgrade-safe due to its use of a named storage slot.Adding
_reentrancyGuardStorageSlot()
as apure virtual
function allows advanced users to override the default slot location safely in derived contracts, which is essential when using multiple delegatecall modules that each instantiateReentrancyGuardTransient
.Summary of Changes
_reentrancyGuardStorageSlot()
, markedinternal pure virtual
REENTRANCY_GUARD_STORAGE
with calls to this new function