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

op-deployer: Add more FP deploy scripts #13325

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
4 changes: 4 additions & 0 deletions op-chain-ops/script/script.go
Original file line number Diff line number Diff line change
@@ -440,6 +440,10 @@ func (h *Host) ImportAccount(addr common.Address, account types.Account) {
}
}

func (h *Host) SetStorage(addr common.Address, key common.Hash, value common.Hash) {
h.state.SetState(addr, key, value)
}

// getPrecompile overrides any accounts during runtime, to insert special precompiles, if activated.
func (h *Host) getPrecompile(rules params.Rules, original vm.PrecompiledContract, addr common.Address) vm.PrecompiledContract {
if p, ok := h.precompiles[addr]; ok {
27 changes: 27 additions & 0 deletions op-deployer/pkg/deployer/opcm/alphabet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package opcm

import (
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum/go-ethereum/common"
)

type DeployAlphabetVMInput struct {
AbsolutePrestate common.Hash
PreimageOracle common.Address
}

type DeployAlphabetVMOutput struct {
AlphabetVM common.Address
}

func DeployAlphabetVM(
host *script.Host,
input DeployAlphabetVMInput,
) (DeployAlphabetVMOutput, error) {
return RunScriptSingle[DeployAlphabetVMInput, DeployAlphabetVMOutput](
host,
input,
"DeployAlphabetVM.s.sol",
"DeployAlphabetVM",
)
}
37 changes: 37 additions & 0 deletions op-deployer/pkg/deployer/opcm/alphabet_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package opcm

import (
"testing"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/testutil"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)

func TestDeployAlphabetVM(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
broadcaster.NoopBroadcaster(),
testlog.Logger(t, log.LevelInfo),
common.Address{'D'},
artifacts,
)
require.NoError(t, err)

input := DeployAlphabetVMInput{
AbsolutePrestate: common.Hash{'A'},
PreimageOracle: common.Address{'O'},
}

output, err := DeployAlphabetVM(host, input)
require.NoError(t, err)

require.NotEmpty(t, output.AlphabetVM)
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/alt_da_test.go
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ import (
)

func TestDeployAltDA(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/asterisc.go
Original file line number Diff line number Diff line change
@@ -26,5 +26,5 @@ func DeployAsterisc(
host *script.Host,
input DeployAsteriscInput,
) (DeployAsteriscOutput, error) {
return RunBasicScript[DeployAsteriscInput, DeployAsteriscOutput](host, input, "DeployAsterisc.s.sol", "DeployAsterisc")
return RunScriptSingle[DeployAsteriscInput, DeployAsteriscOutput](host, input, "DeployAsterisc.s.sol", "DeployAsterisc")
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/asterisc_test.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ import (
)

func TestDeployAsterisc(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/delayed_weth.go
Original file line number Diff line number Diff line change
@@ -34,5 +34,5 @@ func DeployDelayedWETH(
host *script.Host,
input DeployDelayedWETHInput,
) (DeployDelayedWETHOutput, error) {
return RunBasicScript[DeployDelayedWETHInput, DeployDelayedWETHOutput](host, input, "DeployDelayedWETH.s.sol", "DeployDelayedWETH")
return RunScriptSingle[DeployDelayedWETHInput, DeployDelayedWETHOutput](host, input, "DeployDelayedWETH.s.sol", "DeployDelayedWETH")
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/delayed_weth_test.go
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ import (
)

func TestDeployDelayedWETH(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

testCases := []struct {
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/dispute_game.go
Original file line number Diff line number Diff line change
@@ -44,5 +44,5 @@ func DeployDisputeGame(
host *script.Host,
input DeployDisputeGameInput,
) (DeployDisputeGameOutput, error) {
return RunBasicScript[DeployDisputeGameInput, DeployDisputeGameOutput](host, input, "DeployDisputeGame.s.sol", "DeployDisputeGame")
return RunScriptSingle[DeployDisputeGameInput, DeployDisputeGameOutput](host, input, "DeployDisputeGame.s.sol", "DeployDisputeGame")
}
24 changes: 24 additions & 0 deletions op-deployer/pkg/deployer/opcm/dispute_game_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package opcm

import (
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum/go-ethereum/common"
)

type SetDisputeGameImplInput struct {
Factory common.Address
Impl common.Address
GameType uint32
}

func SetDisputeGameImpl(
h *script.Host,
input SetDisputeGameImplInput,
) error {
return RunScriptVoid[SetDisputeGameImplInput](
h,
input,
"SetDisputeGameImpl.s.sol",
"SetDisputeGameImpl",
)
}
55 changes: 55 additions & 0 deletions op-deployer/pkg/deployer/opcm/dispute_game_factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package opcm

import (
"context"
"os"
"testing"
"time"

"github.com/ethereum/go-ethereum/rpc"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/testutil"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)

func TestSetDisputeGameImpl(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

l1RPCUrl := os.Getenv("SEPOLIA_RPC_URL")
require.NotEmpty(t, l1RPCUrl, "SEPOLIA_RPC_URL must be set")

l1RPC, err := rpc.Dial(l1RPCUrl)
require.NoError(t, err)

// OP Sepolia DGF owner
deployer := common.HexToAddress("0x1Eb2fFc903729a0F03966B917003800b145F56E2")

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
host, err := env.DefaultForkedScriptHost(
ctx,
broadcaster.NoopBroadcaster(),
testlog.Logger(t, log.LevelInfo),
deployer,
artifacts,
l1RPC,
)
require.NoError(t, err)

// Use OP Sepolia's dispute game factory
factoryAddr := common.HexToAddress("0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1")

input := SetDisputeGameImplInput{
Factory: factoryAddr,
Impl: common.Address{'I'},
GameType: 999,
}
require.NoError(t, SetDisputeGameImpl(host, input))
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/dispute_game_test.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import (
)

func TestDeployDisputeGame(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/mips.go
Original file line number Diff line number Diff line change
@@ -31,5 +31,5 @@ func DeployMIPS(
host *script.Host,
input DeployMIPSInput,
) (DeployMIPSOutput, error) {
return RunBasicScript[DeployMIPSInput, DeployMIPSOutput](host, input, "DeployMIPS.s.sol", "DeployMIPS")
return RunScriptSingle[DeployMIPSInput, DeployMIPSOutput](host, input, "DeployMIPS.s.sol", "DeployMIPS")
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/mips_test.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ import (
)

func TestDeployMIPS(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/opchain.go
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ func DeployOPChainIsthmus(host *script.Host, input DeployOPChainInputIsthmus) (D
}

func deployOPChain[T any](host *script.Host, input T) (DeployOPChainOutput, error) {
return RunBasicScript[T, DeployOPChainOutput](host, input, "DeployOPChain.s.sol", "DeployOPChain")
return RunScriptSingle[T, DeployOPChainOutput](host, input, "DeployOPChain.s.sol", "DeployOPChain")
}

type ReadImplementationAddressesInput struct {
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/opcm.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ func DeployOPCM(
host *script.Host,
input DeployOPCMInput,
) (DeployOPCMOutput, error) {
out, err := RunBasicScript[DeployOPCMInput, DeployOPCMOutput](host, input, "DeployOPCM.s.sol", "DeployOPCM")
out, err := RunScriptSingle[DeployOPCMInput, DeployOPCMOutput](host, input, "DeployOPCM.s.sol", "DeployOPCM")
if err != nil {
return DeployOPCMOutput{}, fmt.Errorf("failed to deploy OPCM: %w", err)
}
29 changes: 29 additions & 0 deletions op-deployer/pkg/deployer/opcm/preimage_oracle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package opcm

import (
"math/big"

"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum/go-ethereum/common"
)

type DeployPreimageOracleInput struct {
MinProposalSize *big.Int
ChallengePeriod *big.Int
}

type DeployPreimageOracleOutput struct {
PreimageOracle common.Address
}

func DeployPreimageOracle(
host *script.Host,
input DeployPreimageOracleInput,
) (DeployPreimageOracleOutput, error) {
return RunScriptSingle[DeployPreimageOracleInput, DeployPreimageOracleOutput](
host,
input,
"DeployPreimageOracle.s.sol",
"DeployPreimageOracle",
)
}
38 changes: 38 additions & 0 deletions op-deployer/pkg/deployer/opcm/preimage_oracle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package opcm

import (
"math/big"
"testing"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/testutil"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)

func TestDeployPreimageOracle(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
broadcaster.NoopBroadcaster(),
testlog.Logger(t, log.LevelInfo),
common.Address{'D'},
artifacts,
)
require.NoError(t, err)

input := DeployPreimageOracleInput{
MinProposalSize: big.NewInt(123),
ChallengePeriod: big.NewInt(456),
}

output, err := DeployPreimageOracle(host, input)
require.NoError(t, err)

require.NotEmpty(t, output.PreimageOracle)
}
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/proxy.go
Original file line number Diff line number Diff line change
@@ -26,5 +26,5 @@ func DeployProxy(
host *script.Host,
input DeployProxyInput,
) (DeployProxyOutput, error) {
return RunBasicScript[DeployProxyInput, DeployProxyOutput](host, input, "DeployProxy.s.sol", "DeployProxy")
return RunScriptSingle[DeployProxyInput, DeployProxyOutput](host, input, "DeployProxy.s.sol", "DeployProxy")
}
2 changes: 2 additions & 0 deletions op-deployer/pkg/deployer/opcm/proxy_test.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ import (
)

func TestDeployProxy(t *testing.T) {
t.Parallel()

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
37 changes: 34 additions & 3 deletions op-deployer/pkg/deployer/opcm/script.go
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ import (
"github.com/ethereum/go-ethereum/common"
)

type BasicScriptIO struct {
type SingleScript struct {
Run func(input, output common.Address) error
}

func RunBasicScript[I any, O any](
func RunScriptSingle[I any, O any](
host *script.Host,
input I,
scriptFile string,
@@ -34,7 +34,7 @@ func RunBasicScript[I any, O any](
}
defer cleanupOutput()

deployScript, cleanupDeploy, err := script.WithScript[BasicScriptIO](host, scriptFile, contractName)
deployScript, cleanupDeploy, err := script.WithScript[SingleScript](host, scriptFile, contractName)
if err != nil {
return output, fmt.Errorf("failed to load %s script: %w", scriptFile, err)
}
@@ -46,3 +46,34 @@ func RunBasicScript[I any, O any](

return output, nil
}

type VoidScript struct {
Run func(common.Address) error
}

func RunScriptVoid[I any](
host *script.Host,
input I,
scriptFile string,
contractName string,
) error {
inputAddr := host.NewScriptAddress()

cleanupInput, err := script.WithPrecompileAtAddress[*I](host, inputAddr, &input)
if err != nil {
return fmt.Errorf("failed to insert input precompile: %w", err)
}
defer cleanupInput()

deployScript, cleanupDeploy, err := script.WithScript[VoidScript](host, scriptFile, contractName)
if err != nil {
return fmt.Errorf("failed to load %s script: %w", scriptFile, err)
}
defer cleanupDeploy()

if err := deployScript.Run(inputAddr); err != nil {
return fmt.Errorf("failed to run %s script: %w", scriptFile, err)
}

return nil
}
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/superchain.go
Original file line number Diff line number Diff line change
@@ -52,5 +52,5 @@ type DeploySuperchainOpts struct {
}

func DeploySuperchain(h *script.Host, input DeploySuperchainInput) (DeploySuperchainOutput, error) {
return RunBasicScript[DeploySuperchainInput, DeploySuperchainOutput](h, input, "DeploySuperchain.s.sol", "DeploySuperchain")
return RunScriptSingle[DeploySuperchainInput, DeploySuperchainOutput](h, input, "DeploySuperchain.s.sol", "DeploySuperchain")
}
Loading