-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat(forge): add accessList and cold/warm cheatcodes #10112
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,55 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "cheats/Vm.sol"; | ||
|
||
contract AccessListIsolatedTest is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function test_access_list() public { | ||
Write anotherWrite = new Write(); | ||
Write write = new Write(); | ||
|
||
uint256 initial = gasleft(); | ||
write.setNumber(1); | ||
assertEq(initial - gasleft(), 26762); | ||
|
||
// set access list to anotherWrite address, hence becoming more expensive | ||
Vm.AccessListItem[] memory accessList = new Vm.AccessListItem[](1); | ||
bytes32[] memory readKeys = new bytes32[](0); | ||
accessList[0] = Vm.AccessListItem(address(anotherWrite), readKeys); | ||
vm.accessList(accessList); | ||
|
||
uint256 initial1 = gasleft(); | ||
write.setNumber(2); | ||
assertEq(initial1 - gasleft(), 29162); | ||
|
||
uint256 initial2 = gasleft(); | ||
write.setNumber(3); | ||
assertEq(initial2 - gasleft(), 29162); | ||
|
||
// reset access list, should take same gas as before setting | ||
vm.noAccessList(); | ||
uint256 initial4 = gasleft(); | ||
write.setNumber(4); | ||
assertEq(initial4 - gasleft(), 26762); | ||
|
||
uint256 initial5 = gasleft(); | ||
write.setNumber(5); | ||
assertEq(initial5 - gasleft(), 26762); | ||
|
||
vm.accessList(accessList); | ||
uint256 initial6 = gasleft(); | ||
write.setNumber(6); | ||
assertEq(initial6 - gasleft(), 29162); | ||
} | ||
} | ||
|
||
contract Write { | ||
uint256 public number = 10; | ||
|
||
function setNumber(uint256 _number) external { | ||
number = _number; | ||
} | ||
} |
Oops, something went wrong.
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.
I'm not exactly sure if this has the desired effect, because idk when the evm does respect the configured accesslist, which could be already be before execution starts?@rakita
so maybe in order to get the desired effect here we'd need to replicate how accesslists are actually handled in the evm
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.
would be great to have some insights @rakita, I assumed they're applied because the test below (included in PR) shows different gas usage (access list consist of single address, no storage slot, so the difference of 2400 sums up. If adding another address there's another 2400 of gas, if adding also a storage slot, an additional 1900 is added)
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.
looks like it, I think we can proceed with this as is and change in case this isn't actually the case
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.
Yeah, they are loaded in execution, this is okay.