Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
Amxx committed Mar 20, 2024
commit 644597333ab33d3ae8ed7620c0ee390b1ceb2022
2 changes: 1 addition & 1 deletion .changeset/gorgeous-badgers-vanish.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'openzeppelin-solidity': minor
---

`SlotDerivation`: Add library for storage slot derivation.
`SlotDerivation`: Add a library of methods for derivating common storage slots.
12 changes: 6 additions & 6 deletions contracts/utils/TransientSlot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {TypedSlot} from "./types/TypedSlot.sol";
*
* Example usage:
* ```solidity
* contract ReentrancyGuard {
* contract Lock {
* using TypedSlot for bytes32;
* using TransientSlot for *;
*
* bytes32 internal constant _REENTRANCY_SLOT = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier nonReentrant() {
* require(!_REENTRANCY_SLOT.asBooleanSlot().tload());
* modifier locked() {
* require(!_LOCK_SLOT.asBooleanSlot().tload());
*
* _REENTRANCY_SLOT.asBooleanSlot().tstore(true);
* _LOCK_SLOT.asBooleanSlot().tstore(true);
* _;
* _REENTRANCY_SLOT.asBooleanSlot().tstore(false);
* _LOCK_SLOT.asBooleanSlot().tstore(false);
* }
* }
* ```
Expand Down
12 changes: 6 additions & 6 deletions scripts/generate/templates/TransientSlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import {TypedSlot} from "./types/TypedSlot.sol";
*
* Example usage:
* \`\`\`solidity
* contract ReentrancyGuard {
* contract Lock {
* using TypedSlot for bytes32;
* using TransientSlot for *;
*
* bytes32 internal constant _REENTRANCY_SLOT = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier nonReentrant() {
* require(!_REENTRANCY_SLOT.asBooleanSlot().tload());
* modifier locked() {
* require(!_LOCK_SLOT.asBooleanSlot().tload());
*
* _REENTRANCY_SLOT.asBooleanSlot().tstore(true);
* _LOCK_SLOT.asBooleanSlot().tstore(true);
* _;
* _REENTRANCY_SLOT.asBooleanSlot().tstore(false);
* _LOCK_SLOT.asBooleanSlot().tstore(false);
* }
* }
* \`\`\`
Expand Down