-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add a Slots library, and a transient variant of ReentrancyGuard #4955
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
747bd76
add a TranscientStorage library, and a transcient variant of Reentran…
Amxx 3de225b
fix lint
Amxx 5198ffe
changeset
Amxx 3e986b5
Update TranscientReentrancyGuard.sol
Amxx 6873685
Update scripts/generate/templates/TranscientStorage.js
Amxx bfa7bea
typo
Amxx 2bceb18
fix typo
Amxx 59019ca
doc
Amxx cf64e0a
fix more typo + update warning ignore
Amxx f49f92a
test transient storage library
Amxx 50e1e1f
don't fail test, emit a warning instead
Amxx e21494e
enable cancun in foundry
Amxx 5a40786
Update scripts/generate/templates/TransientStorage.js
Amxx aa59ca8
Update scripts/generate/templates/TransientStorage.js
Amxx 592d884
Update contracts/utils/TransientReentrancyGuard.sol
Amxx 2e96527
finish rename & fix testst
Amxx 480afed
fix lint
Amxx ac8037e
refactor TransientStorage → Slots
Amxx 2c5000c
Update .changeset/honest-planets-sell.md
Amxx f861639
Update .changeset/hungry-oranges-travel.md
Amxx 60cf023
Apply suggestions from code review
Amxx fa9a7a5
Apply suggestions from code review
Amxx 64f5096
doc
Amxx 1de3873
up
Amxx 0e8db95
add erc1967 and erc7201 slot derivation + fuzzing
Amxx f206c76
up
Amxx 5a77bc5
fix lint
Amxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add erc1967 and erc7201 slot derivation + fuzzing
- Loading branch information
commit 0e8db95c4c1756c1f80f7d09397fe0219a56ab98
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| import {Test} from "forge-std/Test.sol"; | ||
|
|
||
| import {Slots} from "@openzeppelin/contracts/utils/Slots.sol"; | ||
|
|
||
| contract SlotsTest is Test { | ||
| using Slots for *; | ||
|
|
||
| // Variable declarations | ||
| uint256 private _variable; | ||
| uint256[] private _array; | ||
| mapping(address => uint256) private _mapping; | ||
|
|
||
| // Tests | ||
| function testValue1(uint256 value) public { | ||
| // set in solidity | ||
| _variable = value; | ||
| // read using Slots | ||
| assertEq(_getVariableSlot().asUint256Slot().sload(), value); | ||
| } | ||
|
|
||
| function testValue2(uint256 value) public { | ||
| // set using Slots | ||
| _getVariableSlot().asUint256Slot().sstore(value); | ||
| // read in solidity | ||
| assertEq(_variable, value); | ||
| } | ||
|
|
||
| function testArray1(uint256[] calldata values) public { | ||
| // set in solidity | ||
| _array = values; | ||
| // read using Slots | ||
| assertEq(_getArraySlot().asUint256Slot().sload(), values.length); | ||
| for (uint256 i = 0; i < values.length; ++i) { | ||
| assertEq(_getArraySlot().derivateArray().offset(i).asUint256Slot().sload(), values[i]); | ||
| } | ||
| } | ||
|
|
||
| function testArray2(uint256[] calldata values) public { | ||
| // set using Slots | ||
| _getArraySlot().asUint256Slot().sstore(values.length); | ||
| for (uint256 i = 0; i < values.length; ++i) { | ||
| _getArraySlot().derivateArray().offset(i).asUint256Slot().sstore(values[i]); | ||
| } | ||
| // read in solidity | ||
| assertEq(_array, values); | ||
| } | ||
|
|
||
| function testMapping1(address key, uint256 value) public { | ||
| // set in solidity | ||
| _mapping[key] = value; | ||
| // read using Slots | ||
| assertEq(_getMappingSlot().derivateMapping(key).asUint256Slot().sload(), value); | ||
| } | ||
|
|
||
| function testMapping2(address key, uint256 value) public { | ||
| // set using Slots | ||
| _getMappingSlot().derivateMapping(key).asUint256Slot().sstore(value); | ||
| // read in solidity | ||
| assertEq(_mapping[key], value); | ||
| } | ||
|
|
||
| // Slot extraction | ||
| function _getVariableSlot() public pure returns (bytes32 slot) { | ||
| assembly { slot := _variable.slot } | ||
| } | ||
|
|
||
| function _getArraySlot() public pure returns (bytes32 slot) { | ||
| assembly { slot := _array.slot } | ||
| } | ||
|
|
||
| function _getMappingSlot() public pure returns (bytes32 slot) { | ||
| assembly { slot := _mapping.slot } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@ernestognw @frangio Like this new approach?