forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 3
feat(l2cm): add transaction generation script & L2ContractsManager #656
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
0xiamflux
merged 8 commits into
sc-feat/l2contracts-manager
from
poc/l2cu-tx-gen-scripts
Nov 14, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a2fc29
feat: add NUT lib
0xniha 2a982e0
refactor: makes txn artifact lib to produce array instead of using keys
0xiamflux 0313e64
refactor: rename "artifactPath" to "forgeArtifactPath"
0xiamflux 0e0ab61
test: add test that checks the file is generated correctly
0xiamflux 57e0d8f
refactor: rename UpgradeTxn to NetworkUpgradeTxn
0xiamflux 3aeac9a
feat: add readArtifact to lib & fix writeArtifact test
0xniha 0ea582e
feat(l2cm): add a generation script using NUT library, add sample L2C…
0xiamflux 3516df7
feat: l2cm poc fixes (#674)
0xniha 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
44 changes: 44 additions & 0 deletions
44
packages/contracts-bedrock/interfaces/preinstalls/ICreate2Deployer.sol
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,44 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.15; | ||
|
|
||
| interface ICreate2Deployer { | ||
| /** | ||
| * @dev Deploys a contract using `CREATE2`. The address where the | ||
| * contract will be deployed can be known in advance via {computeAddress}. | ||
| * | ||
| * The bytecode for a contract can be obtained from Solidity with | ||
| * `type(contractName).creationCode`. | ||
| * | ||
| * Requirements: | ||
| * - `bytecode` must not be empty. | ||
| * - `salt` must have not been used for `bytecode` already. | ||
| * - the factory must have a balance of at least `value`. | ||
| * - if `value` is non-zero, `bytecode` must have a `payable` constructor. | ||
| */ | ||
| function deploy(uint256 value, bytes32 salt, bytes memory code) external; | ||
| /** | ||
| * @dev Deployment of the {ERC1820Implementer}. | ||
| * Further information: https://eips.ethereum.org/EIPS/eip-1820 | ||
| */ | ||
| function deployERC1820Implementer(uint256 value, bytes32 salt) external; | ||
| /** | ||
| * @dev Returns the address where a contract will be stored if deployed via {deploy}. | ||
| * Any change in the `bytecodeHash` or `salt` will result in a new destination address. | ||
| */ | ||
| function computeAddress(bytes32 salt, bytes32 codeHash) external view returns (address); | ||
| /** | ||
| * @dev Returns the address where a contract will be stored if deployed via {deploy} from a | ||
| * contract located at `deployer`. If `deployer` is this contract's address, returns the | ||
| * same value as {computeAddress}. | ||
| */ | ||
| function computeAddressWithDeployer( | ||
| bytes32 salt, | ||
| bytes32 codeHash, | ||
| address deployer | ||
| ) | ||
| external | ||
| pure | ||
| returns (address); | ||
|
|
||
| receive() external payable; | ||
| } |
165 changes: 165 additions & 0 deletions
165
packages/contracts-bedrock/scripts/deploy/PredeployHelper.sol
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,165 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.15; | ||
|
|
||
| import { Script } from "forge-std/Script.sol"; | ||
| import { Predeploys } from "src/libraries/Predeploys.sol"; | ||
| import { console } from "forge-std/console.sol"; | ||
| import { Preinstalls } from "src/libraries/Preinstalls.sol"; | ||
| import { ICreate2Deployer } from "interfaces/preinstalls/ICreate2Deployer.sol"; | ||
| import { TransactionGeneration } from "scripts/deploy/TransactionGeneration.s.sol"; | ||
|
|
||
| /// @title PredeployHelper | ||
| /// @notice Helper script for managing predeploy configurations during network upgrades. | ||
| /// This contract collects all predeploys that need to be deployed, computes their | ||
| /// CREATE2 addresses, and handles special cases requiring constructor arguments. | ||
| contract PredeployHelper is Script { | ||
| /// @notice Address of the Create2Deployer predeploy. | ||
| address payable immutable CREATE2_DEPLOYER = payable(Preinstalls.Create2Deployer); | ||
|
|
||
| /// @notice Represents a predeploy contract to be deployed during a network upgrade. | ||
| /// @param proxy The address of the proxy contract that will be upgraded. | ||
| /// @param name The name of the predeploy contract. | ||
| /// @param initCode The initialization code (bytecode + constructor args) for deployment. | ||
| /// @param implementation The computed CREATE2 address where the implementation will be deployed. | ||
| struct Predeploy { | ||
| address proxy; | ||
| string name; | ||
| bytes initCode; | ||
| address implementation; | ||
| } | ||
|
|
||
| /// @notice Array storing all predeploys to be deployed. | ||
| Predeploy[17] private predeploys; | ||
|
|
||
| /// @notice Constructor for the PredeployHelper. | ||
| constructor() { | ||
| predeploys[0].proxy = Predeploys.LEGACY_MESSAGE_PASSER; // 0: LegacyMessagePasser | ||
| predeploys[1].proxy = Predeploys.DEPLOYER_WHITELIST; // 1: DeployerWhitelist | ||
| predeploys[2].proxy = Predeploys.L2_CROSS_DOMAIN_MESSENGER; // 2: L2CrossDomainMessenger | ||
| predeploys[3].proxy = Predeploys.GAS_PRICE_ORACLE; // 3: GasPriceOracle | ||
| predeploys[4].proxy = Predeploys.L2_STANDARD_BRIDGE; // 4: L2StandardBridge | ||
| predeploys[5].proxy = Predeploys.SEQUENCER_FEE_WALLET; // 5: SequencerFeeWallet | ||
| predeploys[6].proxy = Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY; // 6: OptimismMintableERC20Factory | ||
| predeploys[7].proxy = Predeploys.L1_BLOCK_NUMBER; // 7: L1BlockNumber | ||
| predeploys[8].proxy = Predeploys.L2_ERC721_BRIDGE; // 8: L2ERC721Bridge | ||
| predeploys[9].proxy = Predeploys.L1_BLOCK_ATTRIBUTES; // 9: L1BlockAttributes | ||
| predeploys[10].proxy = Predeploys.L2_TO_L1_MESSAGE_PASSER; // 10: L2ToL1MessagePasser | ||
| predeploys[11].proxy = Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY; // 11: OptimismMintableERC721Factory | ||
| predeploys[12].proxy = Predeploys.BASE_FEE_VAULT; // 12: BaseFeeVault | ||
| predeploys[13].proxy = Predeploys.L1_FEE_VAULT; // 13: L1FeeVault | ||
| predeploys[14].proxy = Predeploys.OPERATOR_FEE_VAULT; // 14: OperatorFeeVault | ||
| predeploys[15].proxy = Predeploys.SCHEMA_REGISTRY; // 15: SchemaRegistry | ||
| predeploys[16].proxy = Predeploys.EAS; // 16: EAS | ||
| } | ||
|
|
||
| /// @notice Collects all predeploys that need to be deployed for the configured fork. | ||
| /// @param _input The input struct containing chain configuration and deployment parameters. | ||
| /// @return Array of Predeploy structs containing deployment information for each predeploy. | ||
| function getPredeploys(TransactionGeneration.Input memory _input) external returns (Predeploy[] memory) { | ||
| for (uint256 i = 0; i < predeploys.length; i++) { | ||
| // Skip if not supported or not proxied or needs constructor args | ||
| if (_needsConstructorArgs(predeploys[i].proxy)) { | ||
| _addPredeploysWithArgs(_input, i, predeploys[i].proxy); | ||
| } else { | ||
| _addPredeploy(i, predeploys[i].proxy, bytes("")); | ||
| } | ||
| } | ||
|
|
||
| // Copy storage array to memory for return | ||
| Predeploy[] memory result = new Predeploy[](predeploys.length); | ||
| for (uint256 i = 0; i < predeploys.length; i++) { | ||
| result[i] = predeploys[i]; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /// @notice Adds a predeploy to the deployment list with optional constructor arguments. | ||
| /// @param _addr The proxy address of the predeploy contract. | ||
| /// @param _args ABI-encoded constructor arguments (empty bytes for no-arg constructors). | ||
| function _addPredeploy(uint256 _index, address _addr, bytes memory _args) internal { | ||
| string memory _name = Predeploys.getName(_addr); | ||
| bytes memory initCode = abi.encodePacked(vm.getCode(_name), _args); | ||
| bytes32 salt = keccak256(abi.encode(_name)); | ||
| address implementation = ICreate2Deployer(CREATE2_DEPLOYER).computeAddress(salt, keccak256(initCode)); | ||
|
|
||
| predeploys[_index] = | ||
| Predeploy({ proxy: _addr, name: _name, initCode: initCode, implementation: implementation }); | ||
| } | ||
|
|
||
| /// @notice Checks if a predeploy requires constructor arguments or special handling. | ||
| /// @param _proxy The address of the proxy contract to check. | ||
| /// @return True if the predeploy requires constructor arguments, false otherwise. | ||
| function _needsConstructorArgs(address _proxy) private pure returns (bool) { | ||
| return _proxy == Predeploys.SEQUENCER_FEE_WALLET || _proxy == Predeploys.BASE_FEE_VAULT | ||
| || _proxy == Predeploys.L1_FEE_VAULT || _proxy == Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY; | ||
| } | ||
|
|
||
| /// @notice Adds predeploys with constructor arguments to the deployment list. | ||
| /// @param _input The input struct containing configuration parameters. | ||
| function _addPredeploysWithArgs( | ||
| TransactionGeneration.Input memory _input, | ||
| uint256 _index, | ||
| address _proxy | ||
| ) | ||
| internal | ||
| { | ||
| if (_proxy == Predeploys.SEQUENCER_FEE_WALLET) { | ||
| _addFeeVault( | ||
| _index, | ||
| Predeploys.SEQUENCER_FEE_WALLET, | ||
| _input.sequencerFeeVaultRecipient, | ||
| _input.sequencerFeeVaultMinimumWithdrawalAmount, | ||
| _input.sequencerFeeVaultWithdrawalNetwork | ||
| ); | ||
| } else if (_proxy == Predeploys.BASE_FEE_VAULT) { | ||
| _addFeeVault( | ||
| _index, | ||
| Predeploys.BASE_FEE_VAULT, | ||
| _input.baseFeeVaultRecipient, | ||
| _input.baseFeeVaultMinimumWithdrawalAmount, | ||
| _input.baseFeeVaultWithdrawalNetwork | ||
| ); | ||
| } else if (_proxy == Predeploys.L1_FEE_VAULT) { | ||
| _addFeeVault( | ||
| _index, | ||
| Predeploys.L1_FEE_VAULT, | ||
| _input.l1FeeVaultRecipient, | ||
| _input.l1FeeVaultMinimumWithdrawalAmount, | ||
| _input.l1FeeVaultWithdrawalNetwork | ||
| ); | ||
| } else if (_proxy == Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY) { | ||
| _addOptimismMintableERC721Factory(_index, _input); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Adds a fee vault to the deployment list with its constructor arguments. | ||
| /// @param _feeVault The address of the fee vault contract to add. | ||
| /// @param _feeVaultRecipient The recipient of the fee vault. | ||
| /// @param _feeVaultMinimumWithdrawalAmount The minimum withdrawal amount for the fee vault. | ||
| /// @param _feeVaultWithdrawalNetwork The withdrawal network for the fee vault. | ||
| function _addFeeVault( | ||
| uint256 _index, | ||
| address _feeVault, | ||
| address _feeVaultRecipient, | ||
| uint256 _feeVaultMinimumWithdrawalAmount, | ||
| uint256 _feeVaultWithdrawalNetwork | ||
| ) | ||
| internal | ||
| { | ||
| _addPredeploy( | ||
| _index, | ||
| _feeVault, | ||
| abi.encode(_feeVaultRecipient, _feeVaultMinimumWithdrawalAmount, _feeVaultWithdrawalNetwork) | ||
| ); | ||
| } | ||
|
|
||
| /// @notice Adds the OptimismMintableERC721Factory predeploy with its constructor arguments | ||
| /// @param _input The input struct containing configuration parameters | ||
| function _addOptimismMintableERC721Factory(uint256 _index, TransactionGeneration.Input memory _input) internal { | ||
| _addPredeploy( | ||
| _index, | ||
| Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY, | ||
| abi.encode(_input.l1ERC721BridgeProxy, _input.l2ChainID) | ||
| ); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.