Skip to content
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
3 changes: 3 additions & 0 deletions op-deployer/pkg/deployer/devfeatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var (

// DeployV2DisputeGamesDevFlag enables deployment of V2 dispute game contracts.
DeployV2DisputeGamesDevFlag = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000100")

// OpcmV2DevFlag enables deployment of OPCM V2.
OpcmV2DevFlag = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000010000")
)

// IsDevFeatureEnabled checks if a specific development feature is enabled in a feature bitmap.
Expand Down
189 changes: 188 additions & 1 deletion op-deployer/pkg/deployer/integration_test/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestEndToEndBootstrapApplyWithUpgrade(t *testing.T) {
{"default", common.Hash{}},
{"deploy-v2-disputegames", deployer.DeployV2DisputeGamesDevFlag},
{"cannon-kona", deployer.EnableDevFeature(deployer.DeployV2DisputeGamesDevFlag, deployer.CannonKonaDevFlag)},
{"opcm-v2", deployer.OpcmV2DevFlag},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -221,6 +222,9 @@ func TestEndToEndBootstrapApplyWithUpgrade(t *testing.T) {
cfg.FaultGameClockExtension = standard.DisputeClockExtension
cfg.FaultGameMaxClockDuration = standard.DisputeMaxClockDuration
}
if deployer.IsDevFeatureEnabled(tt.devFeature, deployer.OpcmV2DevFlag) {
cfg.DevFeatureBitmap = deployer.OpcmV2DevFlag
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: DevFeatureBitmap overwrite loses combined feature flags in test

Line 210 sets cfg.DevFeatureBitmap to tt.devFeature, but lines 225-227 unconditionally overwrite it with just deployer.OpcmV2DevFlag when that flag is detected. This is currently harmless because the opcm-v2 test case only has OpcmV2DevFlag. However, if a combined test case is added (e.g., combining OpcmV2DevFlag with CannonKonaDevFlag), the overwrite would discard the additional flags, causing the test to use incorrect feature configuration. The conditional block appears redundant and potentially harmful.

Fix in Cursor Fix in Web

runEndToEndBootstrapAndApplyUpgradeTest(t, afactsFS, cfg)
})
}
Expand Down Expand Up @@ -768,7 +772,7 @@ func TestIntentConfiguration(t *testing.T) {
func runEndToEndBootstrapAndApplyUpgradeTest(t *testing.T, afactsFS foundry.StatDirFs, implementationsConfig bootstrap.ImplementationsConfig) {
lgr := implementationsConfig.Logger

ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()

superchainProxyAdminOwner := implementationsConfig.L1ProxyAdminOwner
Expand Down Expand Up @@ -827,6 +831,10 @@ func runEndToEndBootstrapAndApplyUpgradeTest(t *testing.T, afactsFS foundry.Stat
cannonKonaPrestate = common.Hash{'K', 'O', 'N', 'A'}
}
t.Run("upgrade opcm", func(t *testing.T) {
if deployer.IsDevFeatureEnabled(implementationsConfig.DevFeatureBitmap, deployer.OpcmV2DevFlag) {
t.Skip("Skipping OPCM upgrade for OPCM V2")
return
}
upgradeConfig := embedded.UpgradeOPChainInput{
Prank: superchainProxyAdminOwner,
Opcm: impls.Opcm,
Expand All @@ -844,9 +852,188 @@ func runEndToEndBootstrapAndApplyUpgradeTest(t *testing.T, afactsFS foundry.Stat
err = embedded.DefaultUpgrader.Upgrade(host, upgradeConfigBytes)
require.NoError(t, err, "OPCM upgrade should succeed")
})
t.Run("upgrade opcm v2", func(t *testing.T) {
if !deployer.IsDevFeatureEnabled(implementationsConfig.DevFeatureBitmap, deployer.OpcmV2DevFlag) {
t.Skip("Skipping OPCM V2 upgrade for non-OPCM V2 dev feature")
return
}
require.NotEqual(t, common.Address{}, impls.OpcmV2, "OpcmV2 address should not be zero")
t.Logf("Using OpcmV2 at address: %s", impls.OpcmV2.Hex())
t.Logf("Using OpcmUtils at address: %s", impls.OpcmUtils.Hex())
t.Logf("Using OpcmContainer at address: %s", impls.OpcmContainer.Hex())

// Verify OPCM V2 has code deployed
opcmCode, err := versionClient.CodeAt(ctx, impls.OpcmV2, nil)
require.NoError(t, err)
require.NotEmpty(t, opcmCode, "OPCM V2 should have code deployed")
t.Logf("OPCM V2 code size: %d bytes", len(opcmCode))

// Verify OpcmUtils has code deployed
utilsCode, err := versionClient.CodeAt(ctx, impls.OpcmUtils, nil)
require.NoError(t, err)
require.NotEmpty(t, utilsCode, "OpcmUtils should have code deployed")
t.Logf("OpcmUtils code size: %d bytes", len(utilsCode))

// Verify OpcmContainer has code deployed
containerCode, err := versionClient.CodeAt(ctx, impls.OpcmContainer, nil)
require.NoError(t, err)
require.NotEmpty(t, containerCode, "OpcmContainer should have code deployed")
t.Logf("OpcmContainer code size: %d bytes", len(containerCode))

// First, upgrade the superchain with V2
t.Run("upgrade superchain v2", func(t *testing.T) {
superchainUpgradeConfig := embedded.UpgradeSuperchainV2Input{
Prank: superchainProxyAdminOwner,
Opcm: impls.OpcmV2,
SuperchainConfig: implementationsConfig.SuperchainConfigProxy,
SuperchainInstructions: []embedded.ExtraInstruction{},
}
err := embedded.UpgradeSuperchainV2(host, superchainUpgradeConfig)
if err != nil {
t.Logf("Superchain upgrade may have failed (could already be upgraded): %v", err)
} else {
t.Log("Superchain V2 upgrade succeeded")
}
})

// Deploy a new chain using OPCM V2
var deployedSystemConfig common.Address
t.Run("deploy chain with opcm v2", func(t *testing.T) {
// Construct FullConfig for deploy
cannonArgs := mustEncodeGameArgs(common.Hash{'C', 'A', 'N', 'N', 'O', 'N'}, common.Address{}, common.Address{})
permissionedArgs := mustEncodeGameArgs(common.Hash{'C', 'A', 'N', 'N', 'O', 'N'}, superchainProxyAdminOwner, superchainProxyAdminOwner)
konaArgs := mustEncodeGameArgs(common.Hash{'K', 'O', 'N', 'A'}, common.Address{}, common.Address{})

t.Logf("CANNON game args (len=%d): %x", len(cannonArgs), cannonArgs)
t.Logf("PERMISSIONED_CANNON game args (len=%d): %x", len(permissionedArgs), permissionedArgs)
t.Logf("KONA game args (len=%d): %x", len(konaArgs), konaArgs)

deployInput := embedded.DeployOPChainV2Input{
Opcm: impls.OpcmV2,
FullConfigV2: embedded.FullConfigV2{
SaltMixer: "test-salt-mixer-v2",
SuperchainConfig: implementationsConfig.SuperchainConfigProxy,
ProxyAdminOwner: superchainProxyAdminOwner,
SystemConfigOwner: superchainProxyAdminOwner,
UnsafeBlockSigner: superchainProxyAdminOwner,
Batcher: superchainProxyAdminOwner,
StartingAnchorRoot: embedded.Proposal{
Root: [32]byte{'D', 'E', 'A', 'D'},
L2SequenceNumber: 0,
},
StartingRespectedGameType: 1, // PERMISSIONED_CANNON
BasefeeScalar: 1368,
BlobBasefeeScalar: 810949,
GasLimit: 30000000,
L2ChainId: big.NewInt(999999999),
ResourceConfig: embedded.ResourceConfig{
MaxResourceLimit: 20000000,
ElasticityMultiplier: 10,
BaseFeeMaxChangeDenominator: 8,
MinimumBaseFee: 1000000000,
SystemTxMaxGas: 1000000,
MaximumBaseFee: big.NewInt(20000000),
},
DisputeGameConfigs: []embedded.DisputeGameConfig{
{
Enabled: false,
InitBond: big.NewInt(0),
GameType: embedded.GameTypeCannon,
GameArgs: cannonArgs,
},
{
Enabled: true,
InitBond: big.NewInt(0),
GameType: embedded.GameTypePermissionedCannon,
GameArgs: permissionedArgs,
},
{
Enabled: false,
InitBond: big.NewInt(0),
GameType: embedded.GameTypeCannonKona,
GameArgs: konaArgs,
},
},
},
}

output, err := embedded.DeployOPChainV2(host, deployInput)
require.NoError(t, err, "OPCM V2 deploy should succeed")
require.NotEqual(t, common.Address{}, output.ChainContractsV2.SystemConfig, "SystemConfig should be deployed")

deployedSystemConfig = output.ChainContractsV2.SystemConfig
t.Logf("Deployed SystemConfig at: %s", deployedSystemConfig.Hex())
})

// Then test upgrade on the V2-deployed chain
t.Run("upgrade chain v2", func(t *testing.T) {
if deployedSystemConfig == (common.Address{}) {
t.Skip("Skipping upgrade test - no chain was deployed")
return
}

upgradeConfig := embedded.UpgradeOPChainV2Input{
Prank: superchainProxyAdminOwner,
Opcm: impls.OpcmV2,
UpgradeInputV2: embedded.UpgradeInputV2{
SystemConfig: deployedSystemConfig,
DisputeGameConfigs: []embedded.DisputeGameConfig{
{
Enabled: true,
InitBond: big.NewInt(0),
GameType: embedded.GameTypeCannon,
GameArgs: []byte{},
},
{
Enabled: true,
InitBond: big.NewInt(0),
GameType: embedded.GameTypePermissionedCannon,
GameArgs: []byte{},
},
{
Enabled: false,
InitBond: big.NewInt(0),
GameType: embedded.GameTypeCannonKona,
GameArgs: []byte{},
},
},
ExtraInstructions: []embedded.ExtraInstruction{
{
Key: "PermittedProxyDeployment",
Data: []byte("DelayedWETH"),
},
},
},
}
upgradeConfigBytes, err := json.Marshal(upgradeConfig)
require.NoError(t, err, "UpgradeOPChainV2Input should marshal to JSON")
err = embedded.DefaultUpgraderV2.Upgrade(host, upgradeConfigBytes)
require.NoError(t, err, "OPCM V2 chain upgrade should succeed")
})
})
})
}

func mustEncodeGameArgs(absolutePrestate common.Hash, proposer, challenger common.Address) []byte {
// Use Ethereum ABI encoding for the game args
// In Solidity, abi.encode(MyStruct{...}) encodes the struct fields as a tuple
// For FaultDisputeGameConfig: abi.encode((bytes32)) = 32 bytes
// For PermissionedDisputeGameConfig: abi.encode((bytes32,address,address)) = 96 bytes (3 * 32)

if proposer == (common.Address{}) {
// FaultDisputeGameConfig: abi.encode((bytes32 absolutePrestate))
// This is just the raw bytes32 value (32 bytes)
return absolutePrestate[:]
}
// PermissionedDisputeGameConfig: abi.encode((bytes32,address,address))
// This is 96 bytes: bytes32 + address (left-padded to 32) + address (left-padded to 32)
result := make([]byte, 96)
copy(result[0:32], absolutePrestate[:])
copy(result[44:64], proposer[:]) // address at offset 32, left-padded (12 zero bytes + 20 address bytes)
copy(result[76:96], challenger[:]) // address at offset 64, left-padded (12 zero bytes + 20 address bytes)
return result
}

func needsSuperchainConfigUpgrade(
ctx context.Context,
client *ethclient.Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestCLIUpgrade(t *testing.T) {
version: "v4.1.0",
forkBlock: 9165154, // one block past the opcm deployment block
},
// TODO: Add v5.0.0 test case
}

for _, tc := range testCases {
Expand Down
107 changes: 107 additions & 0 deletions op-deployer/pkg/deployer/upgrade/embedded/deploy_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package embedded

import (
"fmt"
"math/big"

"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"
)

type DeployOPChainV2Input struct {
Opcm common.Address `json:"opcm"`
FullConfigV2 FullConfigV2 `evm:"-" json:"fullConfig"`
}

type FullConfigV2 struct {
SaltMixer string `json:"saltMixer"`
SuperchainConfig common.Address `json:"superchainConfig"`
ProxyAdminOwner common.Address `json:"proxyAdminOwner"`
SystemConfigOwner common.Address `json:"systemConfigOwner"`
UnsafeBlockSigner common.Address `json:"unsafeBlockSigner"`
Batcher common.Address `json:"batcher"`
StartingAnchorRoot Proposal `json:"startingAnchorRoot"`
StartingRespectedGameType uint32 `json:"startingRespectedGameType"`
BasefeeScalar uint32 `json:"basefeeScalar"`
BlobBasefeeScalar uint32 `json:"blobBasefeeScalar"`
GasLimit uint64 `json:"gasLimit"`
L2ChainId *big.Int `json:"l2ChainId"`
ResourceConfig ResourceConfig `json:"resourceConfig"`
DisputeGameConfigs []DisputeGameConfig `json:"disputeGameConfigs"`
}

type Proposal struct {
Root [32]byte `json:"root"`
L2SequenceNumber uint64 `json:"l2SequenceNumber"`
}

type ResourceConfig struct {
MaxResourceLimit uint32 `json:"maxResourceLimit"`
ElasticityMultiplier uint8 `json:"elasticityMultiplier"`
BaseFeeMaxChangeDenominator uint8 `json:"baseFeeMaxChangeDenominator"`
MinimumBaseFee uint32 `json:"minimumBaseFee"`
SystemTxMaxGas uint32 `json:"systemTxMaxGas"`
MaximumBaseFee *big.Int `json:"maximumBaseFee"`
}

type DeployOPChainV2Output struct {
ChainContractsV2 ChainContracts `evm:"-" json:"chainContracts"`
}

func (d *DeployOPChainV2Output) ChainContracts() ([]byte, error) {
return chainContractsEncoder.EncodeArgs(&d.ChainContractsV2)
}

func (d *DeployOPChainV2Output) SetChainContracts(data []byte) error {
return chainContractsEncoder.DecodeReturns(data, &d.ChainContractsV2)
}

type ChainContracts struct {
SystemConfig common.Address `json:"systemConfig"`
ProxyAdmin common.Address `json:"proxyAdmin"`
AddressManager common.Address `json:"addressManager"`
L1CrossDomainMessenger common.Address `json:"l1CrossDomainMessenger"`
L1ERC721Bridge common.Address `json:"l1ERC721Bridge"`
L1StandardBridge common.Address `json:"l1StandardBridge"`
OptimismPortal common.Address `json:"optimismPortal"`
EthLockbox common.Address `json:"ethLockbox"`
OptimismMintableERC20Factory common.Address `json:"optimismMintableERC20Factory"`
DisputeGameFactory common.Address `json:"disputeGameFactory"`
AnchorStateRegistry common.Address `json:"anchorStateRegistry"`
DelayedWETH common.Address `json:"delayedWETH"`
}

var fullConfigEncoder = w3.MustNewFunc(
"dummy((string saltMixer,address superchainConfig,address proxyAdminOwner,address systemConfigOwner,address unsafeBlockSigner,address batcher,(bytes32 root,uint256 l2SequenceNumber) startingAnchorRoot,uint32 startingRespectedGameType,uint32 basefeeScalar,uint32 blobBasefeeScalar,uint64 gasLimit,uint256 l2ChainId,(uint32 maxResourceLimit,uint8 elasticityMultiplier,uint8 baseFeeMaxChangeDenominator,uint32 minimumBaseFee,uint32 systemTxMaxGas,uint128 maximumBaseFee) resourceConfig,(bool enabled,uint256 initBond,uint32 gameType,bytes gameArgs)[] disputeGameConfigs))",
"",
)

var chainContractsEncoder = w3.MustNewFunc(
"dummy()",
"(address systemConfig,address proxyAdmin,address addressManager,address l1CrossDomainMessenger,address l1ERC721Bridge,address l1StandardBridge,address optimismPortal,address ethLockbox,address optimismMintableERC20Factory,address disputeGameFactory,address anchorStateRegistry,address delayedWETH)",
)

func (d *DeployOPChainV2Input) FullConfig() ([]byte, error) {
data, err := fullConfigEncoder.EncodeArgs(&d.FullConfigV2)
if err != nil {
return nil, fmt.Errorf("failed to encode full config: %w", err)
}

// Strip the 4-byte function selector
return data[4:], nil
}

func DeployOPChainV2(host *script.Host, input DeployOPChainV2Input) (*DeployOPChainV2Output, error) {
output, err := opcm.RunScriptSingle[DeployOPChainV2Input, DeployOPChainV2Output](
host,
input,
"DeployOPChainV2.s.sol",
"DeployOPChainV2",
)
if err != nil {
return nil, fmt.Errorf("failed to deploy OP chain V2: %w", err)
}
return &output, nil
}
46 changes: 46 additions & 0 deletions op-deployer/pkg/deployer/upgrade/embedded/upgrade_superchain_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package embedded

import (
"fmt"

"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"
)

type UpgradeSuperchainV2Input struct {
Prank common.Address `json:"prank"`
Opcm common.Address `json:"opcm"`
SuperchainConfig common.Address `evm:"-" json:"superchainConfig"`
SuperchainInstructions []ExtraInstruction `evm:"-" json:"superchainInstructions"`
}

type SuperchainUpgradeInputV2 struct {
SuperchainConfig common.Address
ExtraInstructions []ExtraInstruction
}

var superchainUpgradeInputEncoder = w3.MustNewFunc(
"dummy((address superchainConfig,(string key,bytes data)[] extraInstructions))",
"",
)

func (u *UpgradeSuperchainV2Input) SuperchainUpgradeInput() ([]byte, error) {
input := SuperchainUpgradeInputV2{
SuperchainConfig: u.SuperchainConfig,
ExtraInstructions: u.SuperchainInstructions,
}

data, err := superchainUpgradeInputEncoder.EncodeArgs(&input)
if err != nil {
return nil, fmt.Errorf("failed to encode superchain upgrade input: %w", err)
}

// Strip the 4-byte function selector
return data[4:], nil
}

func UpgradeSuperchainV2(host *script.Host, input UpgradeSuperchainV2Input) error {
return opcm.RunScriptVoid(host, input, "UpgradeSuperchainV2.s.sol", "UpgradeSuperchain")
}
Loading