Optimism 백서

Optimism

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 39쪽

the implementation details of the deployment are abstracted away, and allows complex configurations to be expressed cleanly without concern for the underlying deployment process. ### Portable OP Deployer is designed to be small, portable, and easily installed. As such it is distributed as a standalone binary with no additional dependencies. This allows it to be used in a variety of contexts, including as a CLI tool, in CI pipelines, and as part of local development environments like [Kurtosis](https://github.com/ethpandaops/optimism-package). ### Standard, But Extensible OP Deployer aims to make doing the right thing easy, and doing dangerous things hard. As such its configuration and API are optimized for deploying and upgrading Standard OP Chains. However, it also exposes a lower-level set of primitives and configuration directives which users can use to deploy more complex configurations if the need arises. ## Development Status <Warning> OP Deployer is undergoing active development and has been used for several mainnet deployments. It is considered production-ready. However, please keep in mind that **OP Deployer has not been audited** and that any chains deployed using OP Deployer should be checked thoroughly for correctness prior to launch. </Warning> ## Next Steps * [Install op-deployer](/chain-operators/tools/op-deployer/installation) - Install from pre-built binaries or from source * [Bootstrap](/chain-operators/tools/op-deployer/usage/bootstrap) - Deploy global singletons and implementation contracts * [Architecture](/chain-operators/tools/op-deployer/reference/architecture/overview) - Understand OP Deployer's architecture # Scripting Engine Source: https://docs.optimism.io/chain-operators/tools/op-deployer/reference/architecture/engine Understand OP Deployer's in-memory EVM scripting engine: what it enables, why on-chain interactions run through Solidity scripts, and how Go code communicates with scripts inside the simulated EVM. One of OP Deployer's most powerful features is its in-memory EVM scripting engine. The scripting engine provides similar capabilities to Forge: * It runs all on-chain calls in a simulated environment first, which allows the effects of on-chain calls to be validated before they cost gas. * It exposes Foundry cheatcodes, which allow for deep instrumentation and customization of the EVM environment. These cheatcodes in turn allow OP Deployer to call into Solidity scripts. The scripting engine is really the heart of OP Deployer. Without it, OP Deployer would be nothing more than a thin wrapper over Forge. The scripting engine enables: * Easy integration with existing Solidity-based tooling. * Detailed stack traces when deployments fail. * Fast feedback loops that prevent sending on-chain transactions that may fail. * Live chain forking. For these reasons and more, the scripting engine is a critical part of OP Deployer's architecture. You will see that almost all on-chain interactions initiated by OP Deployer use the scripting engine to call into a Solidity script. The script then uses `vm.broadcast` to signal a transaction that should be sent on-chain. ## Why Use Solidity Scripts? Solidity scripts are much more ergonomic than Go code for complex on-chain interactions. They allow for: * Easy integration with existing Solidity-based tooling and libraries. * Simple ABI encoding/decoding. * Clear separation of concerns between inter-contract calls, and the underlying RPC calls that drive them. The alternative is to encode all on-chain interactions in Go code. This is possible, but it is much more verbose and requires writing bindings between Go and the Solidity ABI. These bindings are error-prone and difficult to maintain. ## Engine Implementation The scripting engine is implemented in the `op-chain-ops/script` package. It extends Geth's EVM implementation with Forge cheatcodes, and defines some tools that allow Go structs to be etched into the EVM's memory. Geth exposes hooks that drive most of the engine's behavior. The best way to understand these further is to read the code. ## Using the Engine OP Deployer uses the etching tooling described above to communicate between OP Deployer and the scripting engine. Most Solidity scripts define an input contract, an output contract, and the script itself. The script reads data from fields on the input contract, then sets fields on the output contract as it runs. OP Deployer defines the input and output contracts as Go structs, like this: ```go theme={null} package foo_script type FooInput struct { Number uint64 Bytes []byte } type FooOutput struct { Result uint64 Bytes []byte } ``` The input and output contracts are then "etched" into the EVM's memory, like this: ```go theme={null} package foo_script // ... struct defs elided func Run(host *script.Host, input FooInput) (FooOutput, error) { // Create a variable to hold our output var output FooOutput // Make new addresses for our input/output contracts inputAddr := host.NewScriptAddress() outputAddr := host.NewScriptAddress() // Inject the input/output contracts into the EVM as precompiles cleanupInput, err := script.WithPrecompileAtAddress[*FooInput](host, inputAddr, &input) if err != nil { return output, fmt.Errorf("failed to insert input precompile: %w", err) } defer cleanupInput() cleanupOutput, err := script.WithPrecompileAtAddress[*FooOutput](host, outputAddr, &output, script.WithFieldSetter[*FooOutput]) if err != nil { return output, fmt.Errorf("failed to insert output precompile: %w", err) } defer cleanupOutput() // ... do stuff with the input/output contracts ... } ``` The script engine will automatically generate getters and setters for the fields on the input and output contracts. You can use the `evm:` struct tag to customize the behavior of these getters and setters. Finally, the script itself gets etched into the EVM's memory and executed, like this: ```go theme={null} package foo_script type FooScript struct { Run func(input, output common.Address) error } func Run(host *script.Host, input FooInput) (FooOutput, error) { // .. see implementation above... deployScript, cleanupDeploy, err := script.WithScript[FooScript](host, "FooScript.s.sol", "FooScript") if err != nil { return output, fmt.Errorf("failed to load %s script: %w", scriptFile, err) } defer cleanupDeploy() if err := deployScript.Run(inputAddr, outputAddr); err != nil { return output, fmt.Errorf("failed to run %s script: %w", scriptFile, err) } return output, nil } ``` You may notice that the script is loaded from a file. To run the scripting engine, contract artifacts (**not** source code) must exist somewhere on disk for the scripting engine to use. For more information on that, see the [Artifacts Locators](/chain-operators/tools/op-deployer/reference/artifacts-locators) page. # Architecture Source: https://docs.optimism.io/chain-operators/tools/op-deployer/reference/architecture/overview Understand OP Deployer's architecture and internals. This section details OP Deployer's architecture and internals. Unless you're contributing directly to OP Deployer, you don't need to read this. * [Deployment Pipeline](/chain-operators/tools/op-deployer/reference/architecture/pipeline): Describes the stages of the deployment pipeline. * [Scripting Engine](/chain-operators/tools/op-deployer/reference/architecture/engine): Describes the scripting engine that OP Deployer uses to interact with the EVM. <img alt="Full architecture diagram" /> *Full architecture diagram ([source](https://www.figma.com/board/bbp16y6ZwIkxzOoKhDu9kk/op-deployer-architecture?node-id=0-1\&p=f\&t=1Eg9JBP0RuVmdtsM-0))* # Deployment Pipeline Source: https://docs.optimism.io/chain-operators/tools/op-deployer/reference/architecture/pipeline Understand how OP Deployer's pipeline is architected: the intent and state files it consumes and produces, and what each deployment stage is responsible for. This page explains how OP Deployer is architected: a pipeline in which each stage is responsible for a single piece of the deployment process. The pipeline consumes a configuration called an *intent* which describes the desired state of the chain, and produces a file called the *state* which describes the current state of the chain during and after the deployment. The steps of the pipeline are: 1. Initialization 2. Shared Contracts Deployment 3. Implementations Deployment 4. OP Chain Deployment 5. Alt-DA Deployment 6. Dispute Game Deployment 7. L2 Genesis Generation 8. Setting Start Block State is written to disk after each state. This allows the pipeline to be restarted from any point in the event of a recoverable error. We'll cover each of these stages in more detail below. ## Initialization During this step, OP Deployer sets initial values for the pipeline based on the user's intent. These values will be used by downstream stages. For example, if the user is deploying using an existing set of shared contracts, those contracts will be inserted into the state during this step. ## Shared Contracts/Implementations Deployment Next, the base contracts for the chain are deployed. This includes shared management contracts like `SuperchainConfig`, as well as implementation contracts that will be used for the OP Chain deployment in the future like the OP Contracts Manager (OPCM). Most chains will be configured to use existing implementations. In this case, these steps will be skipped. ## OP Chain Deployment The OP Chain itself is deployed during this step. Multiple chains will be deployed if they are specified in the intent. The deployment works by calling into the OPCM, which will emit an event for each successfully-deployed chain. ## Customizations Deployment The next two steps (Alt-DA and Dispute Game) deploy customizations. As their names imply, they deploy Alt-DA and additional dispute game contracts. Typically, these steps will be skipped as they are mostly useful in testing. ## L2 Genesis Generation This step generates the L2 Genesis file which is used to initialize the chain. This file is generated by calling into `L2Genesis.sol`, and dumping the outputted state. ## Setting Start Block Lastly, the start block is set to the current block number on L1. This is done last to ensure that the start block is relatively recent, since the deployment process can take arbitrarily long. # Artifacts Locators Source: https://docs.optimism.io/chain-operators/tools/op-deployer/reference/artifacts-locators Learn how OP Deployer uses artifacts locators to point to contract artifacts. OP Deployer calls into precompiled contract artifacts. To make this work, OP Deployer uses artifacts locators to point to the location of contract artifacts. While locators are nothing more than URLs, they do encode some additional behaviors which are described here. ## Locator Types Locators can be one of three types: * `tag://` locators, which point to a versioned contracts release. These resolve to a known URL. Artifacts downloaded using a tagged locator are validated against a hardcoded checksum in the OP Deployer implementation. This prevents tampering with the contract artifacts once they have been tagged. Additionally, tagged locators are cached on disk to avoid repeated downloads. * ex: `tag://op-contracts/v1.8.0-rc.4` * `https://` locators, which point to a tarball of contract artifacts somewhere on the web. HTTP locators are cached just like tagged locators are, but they are not validated against a checksum. * ex: `https://<url-to-remote-forge-artifacts>` * `file://` locators, which point to a directory on local disk containing the artifacts. * ex: `file://<path-to-repo-root>/packages/contracts-bedrock/forge-artifacts` # op-deployer versioning and releases Source: https://docs.optimism.io/chain-operators/tools/op-deployer/reference/releases Reference for where to find OP Deployer releases and how each OP Deployer version maps to a supported contract release. ## Latest Releases The latest version of OP Deployer is always available at [releases](https://github.com/ethereum-optimism/optimism/releases?q=op-deployer\&expanded=true). You should search for `op-deployer` to exclude other packages. ## Versioning For all releases after `v0.0.11`, each minor version of OP Deployer will support a single release of the governance-approved smart contracts. If you want to deploy an earlier version of the contracts (which may be dangerous!), you should use an earlier version of OP Deployer. This setup allows our smart contract developers to make breaking changes on `develop`, while still allowing new chains to be deployed and upgraded using production-ready smart contracts. If you deploy from an HTTPS or file [locator](/chain-operators/tools/op-deployer/reference/artifacts-locators), the deployment behavior will match the contract's tag. For example, if version `v0.2.0` supports `v2.0.0` then the deployment will work as if you were deploying `op-contracts/v2.0.0`. Typically, errors like `unknown selector: <some hex>` imply that you're using the wrong version of OP Deployer for your contract artifacts. If this happens, we recommend trying different versions until you get one that works. Note that this workflow is **not recommended** for production chains. ## Contributor Workflows Step-by-step procedures for backporting fixes onto earlier OP Deployer versions and adding support for new contract versions live in [Release Workflows](/chain-operators/tools/op-deployer/usage/release-workflows). # Apply Command Source: https://docs.optimism.io/chain-operators/tools/op-deployer/usage/apply Learn how to deploy your OP Chain based on the intent file. Once you have [initialized](/chain-operators/tools/op-deployer/usage/init) your intent and state files, you can use the `apply` command to perform the deployment. ## Usage You can call the `apply` command like this: ```shell theme={null} op-deployer apply \ --workdir <directory containing the intent and state files> \ <... additional arguments ...> ``` You will need to specify additional arguments depending on what you're trying to do. See below for a reference of each supported CLI arg. ## CLI Arguments ### `--deployment-target` **Default:** `live` `--deployment-target` specifies where each chain should be deployed to. It can be one of the following values: * `live`: Deploys to a live L1. Concretely, this means that OP Deployer will send transactions identified by `vm.broadcast` calls to L1. `--l1-rpc-url` and `--private-key` must be specified when using this target. * `genesis`: Deploys to an L1 genesis file. This is useful for testing or local development purposes. You do not need to specify any additional arguments when using this target. * `calldata`: Deploys to a calldata file. This is useful for generating inputs to multisig wallets for future execution. * `noop`: Doesn't deploy anything. This is useful for performing a dry-run of the deployment process prior to another deployment target. ### `--l1-rpc-url` Defines the RPC URL of the L1 chain to deploy to. ### `--private-key` Defines the private key to use for signing transactions. This is only required for deployment targets that involve sending live transactions. Note that ownership over each L2 is transferred to the proxy admin owner specified in the intent after the deployment completes, so it's OK to use a hot key for this purpose. # Bootstrap Commands Source: https://docs.optimism.io/chain-operators/tools/op-deployer/usage/bootstrap Learn how to deploy global singletons and implementation contracts for new OP Stack deployments. <Info> If you are joining an existing OP Stack deployment, you can skip to the [`init`](/chain-operators/tools/op-deployer/usage/init) and [`apply`](/chain-operators/tools/op-deployer/usage/apply) commands to create your L2 chain(s). </Info> Bootstrap commands are used to deploy global singletons and implementation contracts for new OP Stack deployments. The deployed contracts can then be used with future invocations of `apply` so that new L2 chains can join that deployment. Most users won't need to use these commands, since `op-deployer apply` will automatically use standard predeployed contracts for the L1/settlement-layer you are deploying on. However, you will need to use bootstrap commands if you're creating a new standalone deployment. There are several bootstrap commands available, which you can view by running `op-deployer bootstrap --help`. We'll focus on the most important ones, which should be run in the sequence listed below. **It is safe to call these commands from a hot wallet.** None of the contracts deployed by these command are "ownable," so the deployment address has no further control over the system. ## Bootstrap Shared Contracts ```shell theme={null} op-deployer bootstrap superchain \ --l1-rpc-url="<rpc url>" \ --private-key="<contract deployer private key>" \ --outfile="./.deployer/bootstrap_superchain.json" \ --superchain-proxy-admin-owner="<role address>" \ --guardian="<role address>" ``` ### CLI Arguments #### `--superchain-proxy-admin-owner`, `--guardian` In a dev environment, these can all be hot wallet EOAs. In a production environment, `--guardian` should be an HSM (hardware security module) protected hot wallet and `--superchain-proxy-admin-owner` should be a multisig cold-wallet (e.g. Gnosis Safe). ### Output This command will deploy several contracts, and output a JSON like the one below: ```json theme={null} { "proxyAdminAddress": "0x269b95a33f48a9055b82ce739b0c105a83edd64a", "superchainConfigImplAddress": "0x2f4c87818d67fc3c365ea10051b94f98893f3c64", "superchainConfigProxyAddress": "0xd0c74806fa114c0ec176c0bf2e1e84ff0a8f91a1" } ``` ## Bootstrap Implementations ```shell theme={null} op-deployer bootstrap implementations \ --l1-rpc-url="<rpc url>" \ --outfile="./.deployer/bootstrap_implementations.json" \ --private-key="<contract deployer private key>" \ --superchain-config-proxy="<contract address output from bootstrap superchain>" \ --superchain-proxy-admin="<contract address from bootstrap superchain>" \ --challenger="<role address for the superchain's challenger>" \ --upgrade-controller="<superchain-proxy-admin-owner used in bootstrap superchain>" ``` ### Output This command will deploy implementations, blueprints, and the OPCM. Deployments are (for the most part) deterministic, so contracts will only be deployed once per chain as long as the implementation and constructor args remain the same. This applies to the `op-deployer apply` pipeline - that is, if someone else ran `op-deployer bootstrap implementations` at some point on a given L1 chain, then the `apply` pipeline will re-use those implementations. The command will output a JSON like the one below: ```json theme={null} { "opcmAddress": "0x82879934658738b6d5e8f781933ae7bbae05ba31", "opcmContractsContainerAddress": "0x1e8de1574a2e085b7a292c760d90cf982d3c1a11", "opcmGameTypeAdderAddress": "0xcab868d42d9088b86598a96d010db5819c19b847", "opcmDeployerAddress": "0xf8b6718b28fa36b430334e78adaf97174fed818c", "opcmUpgraderAddress": "0xa4d0a44890fafce541bdc4c1ca36fca1b5d22f56", "opcmInteropMigratorAddress": "0xf0fca53bb450dd2230c7eb58a39a5dbfc8492fb6", "opcmStandardValidatorAddress": "0x1364a02f64f03cd990f105058b8cc93a9a0ab2a1", "delayedWETHImplAddress": "0x570da3694c06a250aea4855b4adcd09505801f9a", "optimismPortalImplAddress": "0x1aa1d3fc9b39d7edd7ca69f54a35c66dcf1168f1", "ethLockboxImplAddress": "0xe6e51fa10d481002301534445612c61bae6b3258", "preimageOracleSingletonAddress": "0x1fb8cdfc6831fc866ed9c51af8817da5c287add3", "mipsSingletonAddress": "0x7a8456ba22df0cb303ae1c93d3cf68ea3a067006", "systemConfigImplAddress": "0x9f2b1fffd8a7aeef7aeeb002fd8477a4868e7e0a", "l1CrossDomainMessengerImplAddress": "0x085952eb0f0c3d1ca82061e20e0fe8203cdd630a", "l1ERC721BridgeImplAddress": "0xbafd2cae054ddf69af27517c6bea912de6b7eb
프로젝트로 돌아가기