Skip to content
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

feat(genesis): use OPCM for deployments #176

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ checkout-optimism-monorepo:
cd lib/optimism && \
git init && \
git remote add origin https://github.com/ethereum-optimism/optimism.git && \
git fetch --depth=1 origin 52d0e60c16498ad4efec8798e3fc1b36b13f46a2 && \
git fetch --depth=1 origin $(cat ../../monorepo-commit-hash) && \
git reset --hard FETCH_HEAD && \
git submodule update --init --recursive && \
make cannon-prestate
git submodule update --init --recursive --progress --depth=1

generate-genesis: checkout-optimism-monorepo
python3 scripts/generate-genesis.py
calculate-artifact-url:
#!/usr/bin/env bash
cd lib/optimism/packages/contracts-bedrock && \
checksum=$(bash scripts/ops/calculate-checksum.sh) && \
echo "https://storage.googleapis.com/oplabs-contract-artifacts/artifacts-v1-$checksum.tar.gz"

generate-genesis: build-contracts checkout-optimism-monorepo
go run ./genesis/cmd/main.go --monorepo-artifacts $(just calculate-artifact-url) --periphery-artifacts ./contracts/out --outdir ./genesis/generated
2 changes: 1 addition & 1 deletion contracts/lib/optimism
Submodule optimism updated 698 files
14 changes: 10 additions & 4 deletions docs/src/getting-started/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ To see it in practice, let's first try sending some ETH from the L1 to the L2.

## Deposit ETH from the L1 into the L2 (L1 to L2 message passing)

### 1. Call `bridgeETH` function on the `L1StandardBridgeProxy` contract on the L1 (chain 900)
**1. Check initial balance on the L2 (chain 901)**

Grab the balance of the sender account on L2:

```sh
cast balance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9545
```

**2. Call `bridgeETH` function on the `L1StandardBridgeProxy` contract on the L1 (chain 900)**

Initiate a bridge transaction on the L1:

```sh
cast send 0xa01ae68902e205B420FD164435F299E07b0C778b "bridgeETH(uint32 _minGasLimit, bytes calldata _extraData)" 50000 0x --value 0.1ether --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 2. Check the balance on the L2 (chain 901)
**3. Check the balance on the L2 (chain 901)**

Verify that the ETH balance of the sender has increased on the L2:

```sh
cast balance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9545
```

Now that you know how to pass messages from the L1 to the L2, let's try a sending an L2 to L2 message!

## Send an interoperable SuperchainERC20 token from chain 901 to 902 (L2 to L2 message passing)

In a typical L2 to L2 cross-chain transfer, two transactions are required:
Expand Down
103 changes: 103 additions & 0 deletions genesis/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"fmt"
"os"
"path"

"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/pipeline"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/state"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/supersim/genesis/worldgen"
"github.com/urfave/cli/v2"
)

func main() {
oplog.SetupDefaults()

app := cli.NewApp()
app.Name = "supersim-worldgen"
app.Usage = "Supersim Genesis Generator"
app.Description = "Generate genesis files for supersim"
app.Action = worldgenMain
app.Flags = worldgen.CLIFlags()

if err := app.Run(os.Args); err != nil {
fmt.Println(err)
}
}

func worldgenMain(ctx *cli.Context) error {
logger := oplog.NewLogger(oplog.AppOut(nil), oplog.DefaultCLIConfig())

cliConfig, err := worldgen.ParseCLIConfig(ctx)
if err != nil {
return fmt.Errorf("failed to parse cli config: %w", err)
}

// Download monorepo contract artifacts
monorepoProgressor := func(curr, total int64) {
logger.Info("monorepo artifacts download progress", "current", curr, "total", total)
}

monorepoArtifactsFS, monorepoArtifactsCleanup, err := pipeline.DownloadArtifacts(ctx.Context, (*state.ArtifactsURL)(cliConfig.MonorepoArtifactsURL), monorepoProgressor)
if err != nil {
return fmt.Errorf("failed to download monorepo artifacts: %w", err)
}
defer func() {
if err := monorepoArtifactsCleanup(); err != nil {
logger.Warn("failed to clean up monorepo artifacts", "err", err)
}
}()

// Download periphery contract artifacts
peripheryProgressor := func(curr, total int64) {
logger.Info("monorepo artifacts download progress", "current", curr, "total", total)
}

peripheryArtifactsFS, peripheryArtifactsCleanup, err := pipeline.DownloadArtifacts(ctx.Context, (*state.ArtifactsURL)(cliConfig.PeripheryArtifactsURL), peripheryProgressor)
if err != nil {
return fmt.Errorf("failed to download periphery artifacts: %w", err)
}
defer func() {
if err := peripheryArtifactsCleanup(); err != nil {
logger.Warn("failed to clean up periphery artifacts", "err", err)
}
}()

worldDeployment, worldOutput, err := worldgen.GenerateWorld(ctx.Context, logger, &foundry.ArtifactsFS{FS: monorepoArtifactsFS}, &foundry.ArtifactsFS{FS: peripheryArtifactsFS})

if err != nil {
return fmt.Errorf("failed to generate world: %w", err)
}

logger.Info("Successfully generated world")

logger.Info("writing L1 genesis")
outfile := fmt.Sprintf("%s-l1-genesis.json", worldOutput.L1.Genesis.Config.ChainID)
if err := jsonutil.WriteJSON(worldOutput.L1.Genesis, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write L1 genesis: %w", err)
}

for l2ChainID, l2Deployment := range worldDeployment.L2s {
logger.Info("writing addresses for l2", "chain_id", l2ChainID)
outfile := fmt.Sprintf("%s-l2-addresses.json", l2ChainID)
if err := jsonutil.WriteJSON(l2Deployment, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write addresses: %w", err)
}
}

for l2ChainID, l2Output := range worldOutput.L2s {
logger.Info("writing genesis for l2", "chain_id", l2ChainID)
outfile := fmt.Sprintf("%s-l2-genesis.json", l2ChainID)
l2Genesis := l2Output.Genesis
if err := jsonutil.WriteJSON(l2Genesis, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write genesis: %w", err)
}
}

return nil
}
22 changes: 11 additions & 11 deletions genesis/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ type Alloc struct {
/*******************
L1 Genesis files
*******************/
//go:embed generated/l1-genesis.json
//go:embed generated/900-l1-genesis.json
var l1GenesisJSON []byte

/*******************
L2 Genesis files
*******************/
//go:embed generated/l2-genesis/901-l2-genesis.json
//go:embed generated/901-l2-genesis.json
var l2Genesis901JSON []byte

//go:embed generated/l2-genesis/902-l2-genesis.json
//go:embed generated/902-l2-genesis.json
var l2Genesis902JSON []byte

//go:embed generated/l2-genesis/903-l2-genesis.json
//go:embed generated/903-l2-genesis.json
var l2Genesis903JSON []byte

//go:embed generated/l2-genesis/904-l2-genesis.json
//go:embed generated/904-l2-genesis.json
var l2Genesis904JSON []byte

//go:embed generated/l2-genesis/905-l2-genesis.json
//go:embed generated/905-l2-genesis.json
var l2Genesis905JSON []byte

/*******************
L2 Addresses files
*******************/
//go:embed generated/addresses/901-addresses.json
//go:embed generated/901-l2-addresses.json
var addresses901JSON []byte

//go:embed generated/addresses/902-addresses.json
//go:embed generated/902-l2-addresses.json
var addresses902JSON []byte

//go:embed generated/addresses/903-addresses.json
//go:embed generated/903-l2-addresses.json
var addresses903JSON []byte

//go:embed generated/addresses/904-addresses.json
//go:embed generated/904-l2-addresses.json
var addresses904JSON []byte

//go:embed generated/addresses/905-addresses.json
//go:embed generated/905-l2-addresses.json
var addresses905JSON []byte

var GeneratedGenesisDeployment = &GenesisDeployment{
Expand Down
1,350 changes: 1,350 additions & 0 deletions genesis/generated/900-l1-genesis.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions genesis/generated/901-l2-addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"OpChainProxyAdmin": "0x0c2405b5f131d7fe2e1f49e41e8a20d8e4179e7e",
"AddressManager": "0x42a906372a5761dddf8477fa24122caef0b305d1",
"L1ERC721BridgeProxy": "0xcc2ce1a81a754389eb1f93cde7a999db9c68ecf2",
"SystemConfigProxy": "0xfd19a33f8d757b8ea93bb2b40b1cde946c1e1f4d",
"OptimismMintableERC20FactoryProxy": "0x021ec3112045a0de18fb419f6560e243f576cfdb",
"L1StandardBridgeProxy": "0x8d515eb0e5f293b16b6bbca8275c060bae0056b0",
"L1CrossDomainMessengerProxy": "0xcd712b03bc6424bf45ce6c29fc90ffdece228f6e",
"OptimismPortalProxy": "0x37a418800d0c812a9de83bc80e993a6b76511b57",
"DisputeGameFactoryProxy": "0x124efba5858a36f53726e107481e71d9060d84e0",
"AnchorStateRegistryProxy": "0xd4589582d87eb7de8f473656068bb149ae215389",
"AnchorStateRegistryImpl": "0x50ab95ded64106f980cd72c38f9b4990abb52481",
"FaultDisputeGame": "0x0000000000000000000000000000000000000000",
jakim929 marked this conversation as resolved.
Show resolved Hide resolved
"PermissionedDisputeGame": "0x4ed0f56787c51cf50bd695105ec2afbda6ff1cc9",
"DelayedWETHPermissionedGameProxy": "0x65b4322cde0ac9d47196bd2e0ecf31c2e462722a",
"DelayedWETHPermissionlessGameProxy": "0x0000000000000000000000000000000000000000"
}

Loading
Loading