Skip to content

Commit

Permalink
op-deployer: Add more FP deploy scripts
Browse files Browse the repository at this point in the history
Adds additional op-deployer scripts to support alternative fault proof implementations. This is a prerequisite to deleting the allocs files, since many tests need a fast dispute game and an alphabet VM.
  • Loading branch information
mslipper committed Dec 10, 2024
1 parent 70e71c2 commit 3cecdcd
Show file tree
Hide file tree
Showing 28 changed files with 803 additions and 11 deletions.
4 changes: 4 additions & 0 deletions op-chain-ops/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
Expand Up @@ -14,6 +14,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/asterisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -13,6 +13,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/delayed_weth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -14,6 +14,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

testCases := []struct {
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/dispute_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -15,6 +15,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/mips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -13,6 +13,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/opchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/opcm/opcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
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
Expand Up @@ -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
Expand Up @@ -13,6 +13,8 @@ import (
)

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

_, artifacts := testutil.LocalArtifacts(t)

host, err := env.DefaultScriptHost(
Expand Down
37 changes: 34 additions & 3 deletions op-deployer/pkg/deployer/opcm/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand All @@ -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
Expand Up @@ -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

0 comments on commit 3cecdcd

Please sign in to comment.