Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
107948cc
Unverified
Commit
107948cc
authored
Jan 15, 2025
by
Maurelian
Committed by
GitHub
Jan 15, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add ForgeArtifacts.getSlot() (#13787)
parent
dd502b9a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
ForgeArtifacts.sol
...es/contracts-bedrock/scripts/libraries/ForgeArtifacts.sol
+26
-2
L1CrossDomainMessenger.t.sol
...es/contracts-bedrock/test/L1/L1CrossDomainMessenger.t.sol
+7
-1
CrossDomainMessenger.t.sol
...tracts-bedrock/test/invariants/CrossDomainMessenger.t.sol
+3
-1
No files found.
packages/contracts-bedrock/scripts/libraries/ForgeArtifacts.sol
View file @
107948cc
...
@@ -152,8 +152,6 @@ library ForgeArtifacts {
...
@@ -152,8 +152,6 @@ library ForgeArtifacts {
/// @notice Pulls the `_initialized` storage slot information from the Forge artifacts for a given contract.
/// @notice Pulls the `_initialized` storage slot information from the Forge artifacts for a given contract.
function getInitializedSlot(string memory _contractName) internal returns (StorageSlot memory slot_) {
function getInitializedSlot(string memory _contractName) internal returns (StorageSlot memory slot_) {
string memory storageLayout = getStorageLayout(_contractName);
// FaultDisputeGame and PermissionedDisputeGame use a different name for the initialized storage slot.
// FaultDisputeGame and PermissionedDisputeGame use a different name for the initialized storage slot.
string memory slotName = "_initialized";
string memory slotName = "_initialized";
string memory slotType = "t_uint8";
string memory slotType = "t_uint8";
...
@@ -162,6 +160,7 @@ library ForgeArtifacts {
...
@@ -162,6 +160,7 @@ library ForgeArtifacts {
slotType = "t_bool";
slotType = "t_bool";
}
}
string memory storageLayout = getStorageLayout(_contractName);
bytes memory rawSlot = vm.parseJson(
bytes memory rawSlot = vm.parseJson(
Process.bash(
Process.bash(
string.concat(
string.concat(
...
@@ -186,6 +185,31 @@ library ForgeArtifacts {
...
@@ -186,6 +185,31 @@ library ForgeArtifacts {
});
});
}
}
/// @notice Returns the storage slot for a given contract and slot name
function getSlot(
string memory _contractName,
string memory _slotName
)
internal
returns (StorageSlot memory slot_)
{
string memory storageLayout = getStorageLayout(_contractName);
bytes memory rawSlot = vm.parseJson(
Process.bash(
string.concat("echo '", storageLayout, "' | jq '.storage[] | select(.label == \"", _slotName, "\")'")
)
);
ForgeStorageSlot memory slot = abi.decode(rawSlot, (ForgeStorageSlot));
slot_ = StorageSlot({
astId: slot.astId,
_contract: slot._contract,
label: slot.label,
offset: slot.offset,
slot: vm.parseUint(slot.slot),
_type: slot._type
});
}
/// @notice Returns whether or not a contract is initialized.
/// @notice Returns whether or not a contract is initialized.
/// Needs the name to get the storage layout.
/// Needs the name to get the storage layout.
function isInitialized(string memory _name, address _address) internal returns (bool initialized_) {
function isInitialized(string memory _name, address _address) internal returns (bool initialized_) {
...
...
packages/contracts-bedrock/test/L1/L1CrossDomainMessenger.t.sol
View file @
107948cc
...
@@ -11,6 +11,7 @@ import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
...
@@ -11,6 +11,7 @@ import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol";
// Target contract dependencies
// Target contract dependencies
import { IL1CrossDomainMessenger } from "interfaces/L1/IL1CrossDomainMessenger.sol";
import { IL1CrossDomainMessenger } from "interfaces/L1/IL1CrossDomainMessenger.sol";
...
@@ -22,7 +23,12 @@ contract L1CrossDomainMessenger_Test is CommonTest {
...
@@ -22,7 +23,12 @@ contract L1CrossDomainMessenger_Test is CommonTest {
address recipient = address(0xabbaacdc);
address recipient = address(0xabbaacdc);
/// @dev The storage slot of the l2Sender
/// @dev The storage slot of the l2Sender
uint256 constant senderSlotIndex = 50;
uint256 senderSlotIndex;
function setUp() public override {
super.setUp();
senderSlotIndex = ForgeArtifacts.getSlot("OptimismPortal2", "l2Sender").slot;
}
/// @dev Tests that the implementation is initialized correctly.
/// @dev Tests that the implementation is initialized correctly.
/// @notice Marked virtual to be overridden in
/// @notice Marked virtual to be overridden in
...
...
packages/contracts-bedrock/test/invariants/CrossDomainMessenger.t.sol
View file @
107948cc
...
@@ -10,10 +10,11 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
...
@@ -10,10 +10,11 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
import { Constants } from "src/libraries/Constants.sol";
import { Constants } from "src/libraries/Constants.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol";
contract RelayActor is StdUtils {
contract RelayActor is StdUtils {
// Storage slot of the l2Sender
// Storage slot of the l2Sender
uint256
constant senderSlotIndex = 50
;
uint256
senderSlotIndex
;
uint256 public numHashes;
uint256 public numHashes;
bytes32[] public hashes;
bytes32[] public hashes;
...
@@ -29,6 +30,7 @@ contract RelayActor is StdUtils {
...
@@ -29,6 +30,7 @@ contract RelayActor is StdUtils {
xdm = _xdm;
xdm = _xdm;
vm = _vm;
vm = _vm;
doFail = _doFail;
doFail = _doFail;
senderSlotIndex = ForgeArtifacts.getSlot("OptimismPortal2", "l2Sender").slot;
}
}
/// @notice Relays a message to the `L1CrossDomainMessenger` with a random `version`,
/// @notice Relays a message to the `L1CrossDomainMessenger` with a random `version`,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment