Commit 107948cc authored by Maurelian's avatar Maurelian Committed by GitHub

feat: Add ForgeArtifacts.getSlot() (#13787)

parent dd502b9a
......@@ -152,8 +152,6 @@ library ForgeArtifacts {
/// @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_) {
string memory storageLayout = getStorageLayout(_contractName);
// FaultDisputeGame and PermissionedDisputeGame use a different name for the initialized storage slot.
string memory slotName = "_initialized";
string memory slotType = "t_uint8";
......@@ -162,6 +160,7 @@ library ForgeArtifacts {
slotType = "t_bool";
}
string memory storageLayout = getStorageLayout(_contractName);
bytes memory rawSlot = vm.parseJson(
Process.bash(
string.concat(
......@@ -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.
/// Needs the name to get the storage layout.
function isInitialized(string memory _name, address _address) internal returns (bool initialized_) {
......
......@@ -11,6 +11,7 @@ import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol";
// Target contract dependencies
import { IL1CrossDomainMessenger } from "interfaces/L1/IL1CrossDomainMessenger.sol";
......@@ -22,7 +23,12 @@ contract L1CrossDomainMessenger_Test is CommonTest {
address recipient = address(0xabbaacdc);
/// @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.
/// @notice Marked virtual to be overridden in
......
......@@ -10,10 +10,11 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
import { Constants } from "src/libraries/Constants.sol";
import { Encoding } from "src/libraries/Encoding.sol";
import { Hashing } from "src/libraries/Hashing.sol";
import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol";
contract RelayActor is StdUtils {
// Storage slot of the l2Sender
uint256 constant senderSlotIndex = 50;
uint256 senderSlotIndex;
uint256 public numHashes;
bytes32[] public hashes;
......@@ -29,6 +30,7 @@ contract RelayActor is StdUtils {
xdm = _xdm;
vm = _vm;
doFail = _doFail;
senderSlotIndex = ForgeArtifacts.getSlot("OptimismPortal2", "l2Sender").slot;
}
/// @notice Relays a message to the `L1CrossDomainMessenger` with a random `version`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment