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: Most implementation addresses not set in state.json when standard release tag used #12434

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
10 changes: 10 additions & 0 deletions op-deployer/pkg/deployer/integration_test/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ func validateOPChainDeployment(t *testing.T, ctx context.Context, l1Client *ethc
})
}

require.NotEmpty(t, st.ImplementationsDeployment.DelayedWETHImplAddress, "DelayedWETHImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.OptimismPortalImplAddress, "OptimismPortalImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.SystemConfigImplAddress, "SystemConfigImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress, "L1CrossDomainMessengerImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1ERC721BridgeImplAddress, "L1ERC721BridgeImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.L1StandardBridgeImplAddress, "L1StandardBridgeImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress, "OptimismMintableERC20FactoryImplAddress should be set")
require.NotEmpty(t, st.ImplementationsDeployment.DisputeGameFactoryImplAddress, "DisputeGameFactoryImplAddress should be set")
// TODO: Need to check that 'mipsSingletonAddress' and 'preimageOracleSingletonAddress' are set

t.Run("l2 genesis", func(t *testing.T) {
require.Greater(t, len(chainState.Allocs), 0)
l2Allocs, _ := chainState.UnmarshalAllocs()
Expand Down
24 changes: 20 additions & 4 deletions op-deployer/pkg/deployer/opcm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,30 @@ func (c *Contract) ProtocolVersions(ctx context.Context) (common.Address, error)
}

func (c *Contract) getAddress(ctx context.Context, name string) (common.Address, error) {
return c.callContractMethod(ctx, name, abi.Arguments{})
}

// Used to call getAddress(string) on legacy ResolvedDelegateProxy contract
func (c *Contract) GetAddressByName(ctx context.Context, name string) (common.Address, error) {
inputs := abi.Arguments{
abi.Argument{
Name: "_name",
Type: mustType("string"),
Indexed: false,
},
}
return c.callContractMethod(ctx, "getAddress", inputs, name)
}

func (c *Contract) callContractMethod(ctx context.Context, methodName string, inputs abi.Arguments, args ...interface{}) (common.Address, error) {
method := abi.NewMethod(
name,
name,
methodName,
methodName,
abi.Function,
"view",
true,
false,
abi.Arguments{},
inputs,
abi.Arguments{
abi.Argument{
Name: "address",
Expand All @@ -46,7 +62,7 @@ func (c *Contract) getAddress(ctx context.Context, name string) (common.Address,
},
)

calldata, err := method.Inputs.Pack()
calldata, err := method.Inputs.Pack(args...)
if err != nil {
return common.Address{}, fmt.Errorf("failed to pack inputs: %w", err)
}
Expand Down
85 changes: 83 additions & 2 deletions op-deployer/pkg/deployer/pipeline/opchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package pipeline

import (
"context"
"encoding/hex"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
state2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)

func DeployOPChain(ctx context.Context, env *Env, bundle ArtifactsBundle, intent *state2.Intent, st *state2.State, chainID common.Hash) error {
Expand Down Expand Up @@ -91,10 +94,88 @@ func DeployOPChain(ctx context.Context, env *Env, bundle ArtifactsBundle, intent
DelayedWETHPermissionlessGameProxyAddress: dco.DelayedWETHPermissionlessGameProxy,
})

currentBlock, _ := env.L1Client.BlockNumber(ctx)
block, _ := env.L1Client.BlockByNumber(ctx, big.NewInt(int64(currentBlock)))
Comment on lines +97 to +98
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check the error returned from these two calls, or is there a reason it's safe to ignore them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot, I'll make a follow up pr to fix this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should create some semgrep rules to catch these - I will look into that.

currentBlockHash := block.Hash()

errCh := make(chan error, 8)

// If any of the implementations addresses (excluding OpcmProxy) are empty,
// we need to set them using the implementation address read from their corresponding proxy.
// The reason these might be empty is because we're only invoking DeployOPChain.s.sol as part of the pipeline.
// TODO: Need to initialize 'mipsSingletonAddress' and 'preimageOracleSingletonAddress'
setImplementationAddressTasks := []func(){
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.DelayedWETHPermissionedGameProxy, currentBlockHash, &st.ImplementationsDeployment.DelayedWETHImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.OptimismPortalProxy, currentBlockHash, &st.ImplementationsDeployment.OptimismPortalImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.SystemConfigProxy, currentBlockHash, &st.ImplementationsDeployment.SystemConfigImplAddress)
},
func() {
setRDPImplementationAddress(ctx, env.L1Client, errCh, dco.AddressManager, &st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.L1ERC721BridgeProxy, currentBlockHash, &st.ImplementationsDeployment.L1ERC721BridgeImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.L1StandardBridgeProxy, currentBlockHash, &st.ImplementationsDeployment.L1StandardBridgeImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.OptimismMintableERC20FactoryProxy, currentBlockHash, &st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress)
},
func() {
setEIP1967ImplementationAddress(ctx, env.L1Client, errCh, dco.DisputeGameFactoryProxy, currentBlockHash, &st.ImplementationsDeployment.DisputeGameFactoryImplAddress)
},
}
for _, task := range setImplementationAddressTasks {
go task()
}

var lastTaskErr error
for i := 0; i < len(setImplementationAddressTasks); i++ {
taskErr := <-errCh
if lastTaskErr != nil {
lastTaskErr = taskErr
}
blmalone marked this conversation as resolved.
Show resolved Hide resolved
}
if lastTaskErr != nil {
return fmt.Errorf("failed to set implementation addresses: %w", lastTaskErr)
}

return nil
}

func shouldDeployOPChain(intent *state2.Intent, st *state2.State, chainID common.Hash) bool {
func setRDPImplementationAddress(ctx context.Context, client *ethclient.Client, errCh chan error, addressManager common.Address, implAddress *common.Address) {
if *implAddress != (common.Address{}) {
errCh <- nil
return
}

contract := opcm.NewContract(addressManager, client)
address, err := contract.GetAddressByName(ctx, "OVM_L1CrossDomainMessenger")
if err == nil {
*implAddress = address
}
errCh <- err
}

func setEIP1967ImplementationAddress(ctx context.Context, client *ethclient.Client, errCh chan error, proxy common.Address, currentBlockHash common.Hash, implAddress *common.Address) {
if *implAddress != (common.Address{}) {
errCh <- nil
return
}

storageValue, err := client.StorageAtHash(ctx, proxy, genesis.ImplementationSlot, currentBlockHash)
if err == nil {
*implAddress = common.HexToAddress(hex.EncodeToString(storageValue))
}
errCh <- err
}

func shouldDeployOPChain(intent *state.Intent, st *state.State, chainID common.Hash) bool {
for _, chain := range st.Chains {
if chain.ID == chainID {
return false
Expand Down