-
Notifications
You must be signed in to change notification settings - Fork 128
feat: add SetBatcherAndSigner template #1393
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0012dd
feat: add SetBatcherAndSigner template
donoso-eth 17ad2e3
feat(SetBatcherAndSigner): guard against misconfig and redundant writes
donoso-eth b0533d6
style: apply forge fmt to SetBatcherAndSigner
donoso-eth 9a890b8
Merge branch 'main' into jd/template-system-config-batcher-signer
Wazabie de4801b
Merge branch 'main' into jd/template-system-config-batcher-signer
Wazabie 655b652
refactor(SetBatcherAndOrSigner): rename and apply review nits
donoso-eth 3c9fac0
Merge branch 'main' into jd/template-system-config-batcher-signer
Wazabie 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
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,123 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.15; | ||
|
|
||
| import {VmSafe} from "forge-std/Vm.sol"; | ||
| import {stdToml} from "lib/forge-std/src/StdToml.sol"; | ||
|
|
||
| import {L2TaskBase} from "src/tasks/types/L2TaskBase.sol"; | ||
| import {SuperchainAddressRegistry} from "src/SuperchainAddressRegistry.sol"; | ||
| import {Action} from "src/libraries/MultisigTypes.sol"; | ||
|
|
||
| interface ISystemConfig { | ||
| function setBatcherHash(bytes32 _batcherHash) external; | ||
| function setUnsafeBlockSigner(address _unsafeBlockSigner) external; | ||
| function batcherHash() external view returns (bytes32); | ||
| function unsafeBlockSigner() external view returns (address); | ||
| } | ||
|
|
||
| /// @notice Template for updating the batcher hash and unsafe block signer on SystemConfig. | ||
| /// Both calls are batched into a single Multicall3 transaction from the SystemConfig owner. | ||
| contract SetBatcherAndOrSigner is L2TaskBase { | ||
| using stdToml for string; | ||
|
|
||
| /// @notice Configuration for each chain's batcher and signer update. | ||
| struct TaskInputs { | ||
| bytes32 batcherHash; | ||
| address unsafeBlockSigner; | ||
| bool updateBatcher; | ||
| bool updateSigner; | ||
| } | ||
|
|
||
| /// @notice Mapping of chain ID to configuration for the task. | ||
| mapping(uint256 => TaskInputs) public cfg; | ||
|
|
||
| /// @notice Returns the safe address string identifier. | ||
| function safeAddressString() public pure override returns (string memory) { | ||
| return "FoundationUpgradeSafe"; | ||
| } | ||
|
|
||
| /// @notice Returns the storage write permissions required for this task. | ||
| function _taskStorageWrites() internal pure virtual override returns (string[] memory) { | ||
| string[] memory storageWrites = new string[](2); | ||
| storageWrites[0] = "SystemConfigProxy"; | ||
| storageWrites[1] = safeAddressString(); | ||
| return storageWrites; | ||
| } | ||
|
|
||
| /// @notice Sets up the template with configuration from a TOML file. | ||
| function _templateSetup(string memory _taskConfigFilePath, address _rootSafe) internal override { | ||
| super._templateSetup(_taskConfigFilePath, _rootSafe); | ||
|
|
||
| string memory tomlContent = vm.readFile(_taskConfigFilePath); | ||
| SuperchainAddressRegistry.ChainInfo[] memory _chains = superchainAddrRegistry.getChains(); | ||
|
|
||
| address batcherAddress = tomlContent.readAddress(".sequencerConfig.batcherAddress"); | ||
| address unsafeBlockSigner = tomlContent.readAddress(".sequencerConfig.unsafeBlockSigner"); | ||
| require(batcherAddress != address(0), "SetBatcherAndOrSigner: batcherAddress is zero address"); | ||
| require(unsafeBlockSigner != address(0), "SetBatcherAndOrSigner: unsafeBlockSigner is zero address"); | ||
| bytes32 batcherHash = bytes32(uint256(uint160(batcherAddress))); | ||
|
|
||
| for (uint256 i = 0; i < _chains.length; i++) { | ||
| uint256 chainId = _chains[i].chainId; | ||
| ISystemConfig systemConfig = ISystemConfig(superchainAddrRegistry.getAddress("SystemConfigProxy", chainId)); | ||
| bool updateBatcher = batcherHash != systemConfig.batcherHash(); | ||
| bool updateSigner = unsafeBlockSigner != systemConfig.unsafeBlockSigner(); | ||
| require( | ||
| updateBatcher || updateSigner, "SetBatcherAndOrSigner: no-op (both fields already match current values)" | ||
| ); | ||
| cfg[chainId] = TaskInputs({ | ||
| batcherHash: batcherHash, | ||
| unsafeBlockSigner: unsafeBlockSigner, | ||
| updateBatcher: updateBatcher, | ||
| updateSigner: updateSigner | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Builds the batched transaction, calling only the setters for fields that actually change. | ||
| function _build(address) internal override { | ||
| SuperchainAddressRegistry.ChainInfo[] memory chains = superchainAddrRegistry.getChains(); | ||
| for (uint256 i = 0; i < chains.length; i++) { | ||
| uint256 chainId = chains[i].chainId; | ||
| TaskInputs memory taskInput = cfg[chainId]; | ||
| address systemConfigProxy = superchainAddrRegistry.getAddress("SystemConfigProxy", chainId); | ||
| if (taskInput.updateBatcher) { | ||
| ISystemConfig(systemConfigProxy).setBatcherHash(taskInput.batcherHash); | ||
| } | ||
| if (taskInput.updateSigner) { | ||
| ISystemConfig(systemConfigProxy).setUnsafeBlockSigner(taskInput.unsafeBlockSigner); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// @notice Validates that the batcher hash and unsafe block signer were updated correctly. | ||
| function _validate(VmSafe.AccountAccess[] memory, Action[] memory, address) internal view override { | ||
| SuperchainAddressRegistry.ChainInfo[] memory chains = superchainAddrRegistry.getChains(); | ||
| for (uint256 i = 0; i < chains.length; i++) { | ||
| uint256 chainId = chains[i].chainId; | ||
| address systemConfigProxy = superchainAddrRegistry.getAddress("SystemConfigProxy", chainId); | ||
| TaskInputs memory taskInput = cfg[chainId]; | ||
| require( | ||
| ISystemConfig(systemConfigProxy).batcherHash() == taskInput.batcherHash, | ||
| "SetBatcherAndOrSigner: batcher hash mismatch" | ||
| ); | ||
| require( | ||
| ISystemConfig(systemConfigProxy).unsafeBlockSigner() == taskInput.unsafeBlockSigner, | ||
| "SetBatcherAndOrSigner: unsafe block signer mismatch" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Whitelists for each chain's Batcher and UnsafeBlockSigner since batcher and signer addresses are EOAs. | ||
| function _getCodeExceptions() internal view virtual override returns (address[] memory) { | ||
| SuperchainAddressRegistry.ChainInfo[] memory chains = superchainAddrRegistry.getChains(); | ||
| address[] memory exceptions = new address[](chains.length * 2); | ||
| for (uint256 i = 0; i < chains.length; i++) { | ||
| uint256 chainId = chains[i].chainId; | ||
| TaskInputs memory taskInput = cfg[chainId]; | ||
|
Ethnical marked this conversation as resolved.
|
||
| exceptions[i * 2] = address(uint160(uint256(taskInput.batcherHash))); | ||
| exceptions[i * 2 + 1] = taskInput.unsafeBlockSigner; | ||
| } | ||
| return exceptions; | ||
| } | ||
| } | ||
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 @@ | ||
| FORK_BLOCK_NUMBER=10624099 |
13 changes: 13 additions & 0 deletions
13
test/tasks/example/sep/035-set-batcher-and-signer/config.toml
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,13 @@ | ||
| templateName = "SetBatcherAndOrSigner" | ||
|
|
||
| l2chains = [{name = "OP Sepolia Testnet", chainId = 11155420}] | ||
|
|
||
| [sequencerConfig] | ||
| batcherAddress = "0x1234567890AbcdEF1234567890aBcdef12345678" | ||
| unsafeBlockSigner = "0xAbCdEf0123456789AbCdEf0123456789AbCdEf01" | ||
|
|
||
| [stateOverrides] | ||
| # Override SystemConfig owner (slot 0x33) to FoundationUpgradeSafe on Sepolia | ||
| 0x034edD2A225f7f429A63E0f1D2084B9E0A93b538 = [ | ||
| { key = "0x0000000000000000000000000000000000000000000000000000000000000033", value = "0x000000000000000000000000DEe57160aAfCF04c34C887B5962D0a69676d3C8B" } | ||
| ] |
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.
Uh oh!
There was an error while loading. Please reload this page.