diff --git a/op-deployer/pkg/deployer/upgrade/v7_0_0/testdata/config.json b/op-deployer/pkg/deployer/upgrade/embedded/testdata/config.json similarity index 100% rename from op-deployer/pkg/deployer/upgrade/v7_0_0/testdata/config.json rename to op-deployer/pkg/deployer/upgrade/embedded/testdata/config.json diff --git a/op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade_test.go b/op-deployer/pkg/deployer/upgrade/embedded/upgrade_test.go similarity index 73% rename from op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade_test.go rename to op-deployer/pkg/deployer/upgrade/embedded/upgrade_test.go index 560db6e67e6..a6e3e45bf83 100644 --- a/op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade_test.go +++ b/op-deployer/pkg/deployer/upgrade/embedded/upgrade_test.go @@ -1,4 +1,4 @@ -package v7_0_0 +package embedded import ( "encoding/hex" @@ -60,3 +60,29 @@ func TestUpgradeOPChainInput_UpgradeInput(t *testing.T) { require.Equal(t, expected, hex.EncodeToString(data)) } + +func TestUpgradeOPChainInput_OpChainConfigs(t *testing.T) { + input := &UpgradeOPChainInput{ + Prank: common.Address{0xaa}, + Opcm: common.Address{0xbb}, + ChainConfigs: []OPChainConfig{ + { + SystemConfigProxy: common.Address{0x01}, + CannonPrestate: common.Hash{0xaa}, + CannonKonaPrestate: common.Hash{0xbb}, + }, + }, + } + data, err := input.EncodedOpChainConfigs() + + require.NoError(t, err) + require.NotEmpty(t, data) + + expected := "0000000000000000000000000000000000000000000000000000000000000020" + // offset to array + "0000000000000000000000000000000000000000000000000000000000000001" + // array.length + "0000000000000000000000000100000000000000000000000000000000000000" + // systemConfigProxy + "aa00000000000000000000000000000000000000000000000000000000000000" + // cannonPrestate + "bb00000000000000000000000000000000000000000000000000000000000000" // cannonKonaPrestate + + require.Equal(t, expected, hex.EncodeToString(data)) +} diff --git a/op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade.go b/op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade.go deleted file mode 100644 index 9e4b849f2bc..00000000000 --- a/op-deployer/pkg/deployer/upgrade/v7_0_0/upgrade.go +++ /dev/null @@ -1,135 +0,0 @@ -package v7_0_0 - -import ( - "encoding/json" - "fmt" - "math/big" - - "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts" - - "github.com/ethereum-optimism/optimism/op-chain-ops/script" - "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm" - "github.com/ethereum/go-ethereum/common" - "github.com/lmittmann/w3" -) - -// ScriptInput represents the input struct that is actually passed to the script. -// It contains the prank, opcm, and upgrade input. -type ScriptInput struct { - Prank common.Address `evm:"prank"` - Opcm common.Address `evm:"opcm"` - UpgradeInput []byte `evm:"upgradeInput"` -} - -// UpgradeOPChainInput represents the struct that is read from the config file. -// It contains both fields for the old and new upgrade input. -type UpgradeOPChainInput struct { - Prank common.Address `json:"prank"` - Opcm common.Address `json:"opcm"` - ChainConfigs []OPChainConfig `json:"chainConfigs,omitempty"` - UpgradeInputV2 *UpgradeInputV2 `json:"upgradeInput,omitempty"` -} - -// UpgradeInputV2 represents the new upgrade input in OPCM v2. -type UpgradeInputV2 struct { - SystemConfig common.Address `json:"systemConfig"` - DisputeGameConfigs []DisputeGameConfig `json:"disputeGameConfigs"` - ExtraInstructions []ExtraInstruction `json:"extraInstructions"` -} - -// DisputeGameConfig represents the configuration for a dispute game. -type DisputeGameConfig struct { - Enabled bool `json:"enabled"` - InitBond *big.Int `json:"initBond"` - GameType GameType `json:"gameType"` - GameArgs []byte `json:"gameArgs"` -} - -// ExtraInstruction represents an additional upgrade instruction for the upgrade on OPCM v2. -type ExtraInstruction struct { - Key string `json:"key"` - Data []byte `json:"data"` -} - -// GameType represents the type of dispute game. -type GameType uint32 - -const ( - GameTypeCannon GameType = 0 - GameTypePermissionedCannon GameType = 1 - GameTypeCannonKona GameType = 2 -) - -// OPChainConfig represents the configuration for an OP Chain upgrade on OPCM v1. -type OPChainConfig struct { - SystemConfigProxy common.Address `json:"systemConfigProxy"` - ProxyAdmin common.Address `json:"proxyAdmin"` - AbsolutePrestate common.Hash `json:"absolutePrestate"` -} - -var upgradeInputEncoder = w3.MustNewFunc("dummy((address systemConfig,(bool enabled,uint256 initBond,uint32 gameType,bytes gameArgs)[] disputeGameConfigs,(string key,bytes data)[] extraInstructions))", - "") - -var opChainConfigEncoder = w3.MustNewFunc("dummy((address systemConfigProxy,address proxyAdmin,bytes32 absolutePrestate)[])", "") - -type UpgradeOPChain struct { - Run func(input common.Address) -} - -func (u *UpgradeOPChainInput) EncodedOpChainConfigs() ([]byte, error) { - data, err := opChainConfigEncoder.EncodeArgs(u.ChainConfigs) - if err != nil { - return nil, fmt.Errorf("failed to encode chain configs: %w", err) - } - return data[4:], nil -} - -func (u *UpgradeOPChainInput) EncodedUpgradeInputV2() ([]byte, error) { - data, err := upgradeInputEncoder.EncodeArgs(u.UpgradeInputV2) - if err != nil { - return nil, fmt.Errorf("failed to encode upgrade input: %w", err) - } - - return data[4:], nil -} - -func Upgrade(host *script.Host, input UpgradeOPChainInput) error { - // We need to check which of the two versions of the input we are using. - var encodedUpgradeInput []byte - var encodedError error - if input.UpgradeInputV2 == nil && len(input.ChainConfigs) == 0 { - return fmt.Errorf("failed to read either an upgrade input or config array") - } else if input.UpgradeInputV2 != nil { - encodedUpgradeInput, encodedError = input.EncodedUpgradeInputV2() - } else { - encodedUpgradeInput, encodedError = input.EncodedOpChainConfigs() - } - - if encodedError != nil { - return encodedError - } - - scriptInput := ScriptInput{ - Prank: input.Prank, - Opcm: input.Opcm, - UpgradeInput: encodedUpgradeInput, - } - return opcm.RunScriptVoid[ScriptInput](host, scriptInput, "UpgradeOPChain.s.sol", "UpgradeOPChain") -} - -type Upgrader struct{} - -func (u *Upgrader) Upgrade(host *script.Host, input json.RawMessage) error { - var upgradeInput UpgradeOPChainInput - if err := json.Unmarshal(input, &upgradeInput); err != nil { - return fmt.Errorf("failed to unmarshal input: %w", err) - } - return Upgrade(host, upgradeInput) -} - -func (u *Upgrader) ArtifactsURL() string { - // TODO(#18633): Add an actual resource locator that points to this set of artifacts. - return artifacts.CreateHttpLocator("") -} - -var DefaultUpgrader = new(Upgrader)