Skip to content

Commit

Permalink
feature: add more upgrade contracts check
Browse files Browse the repository at this point in the history
  • Loading branch information
redhdx committed Oct 16, 2024
1 parent 8bd1558 commit b8afadd
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 50 deletions.
5 changes: 4 additions & 1 deletion op-chain-ops/cmd/opbnb-upgrade/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ func entrypoint(ctx *cli.Context) error {

proxyAddresses := opbnb_upgrades.BscQAnetProxyContracts
implAddresses := opbnb_upgrades.BscQAnetImplContracts
batchInboxAddr := opbnb_upgrades.BscQAnetBatcherInbox
if l1ChainID.Uint64() == opbnb_upgrades.BscTestnet && !ctx.Bool("qa_net") {
proxyAddresses = opbnb_upgrades.BscTestnetProxyContracts
implAddresses = opbnb_upgrades.BscTestnetImplContracts
batchInboxAddr = opbnb_upgrades.BscTestnetBatcherInbox
fmt.Println("using bscTestnet")
} else if l1ChainID.Uint64() == opbnb_upgrades.BscMainnet {
proxyAddresses = opbnb_upgrades.BscMainnetProxyContracts
implAddresses = opbnb_upgrades.BscMainnetImplContracts
batchInboxAddr = opbnb_upgrades.BscMainnetBatcherInbox
fmt.Println("using bscMainnet")
} else {
fmt.Println("using bscQAnet")
Expand Down Expand Up @@ -205,7 +208,7 @@ func entrypoint(ctx *cli.Context) error {
if newContractsFile == "" {
return errors.New("must set new_contracts_file")
}
err := opbnb_upgrades.CompareContracts(oldContractsFile, newContractsFile)
err := opbnb_upgrades.CompareContracts(oldContractsFile, newContractsFile, proxyAddresses, batchInboxAddr)
if err != nil {
return err
}
Expand Down
170 changes: 135 additions & 35 deletions op-chain-ops/opbnb-upgrades/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,28 @@ type OptimismPortalInfo struct {
}

type SystemConfigInfo struct {
SystemConfigInfo string `yaml:"system_config_info"`
Name string `yaml:"name"`
Address string `yaml:"address"`
Version string `yaml:"version"`
Overhead string `yaml:"overhead"`
Scalar string `yaml:"scalar"`
BatcherHash string `yaml:"batcher_hash"`
GasLimit string `yaml:"gas_limit"`
ResourceConfig ResourceMeteringResourceConfig `yaml:"resource_config"`
StartBlock string `yaml:"start_block"`
BaseFeeScalar string `yaml:"base_fee_scalar"`
BlobBaseFeeScalar string `yaml:"blob_base_fee_scalar"`
SystemConfigInfo string `yaml:"system_config_info"`
Name string `yaml:"name"`
Address string `yaml:"address"`
Version string `yaml:"version"`
Owner string `yaml:"owner"`
UnsafeBlockSigner string `yaml:"unsafe_block_signer"`
Overhead string `yaml:"overhead"`
Scalar string `yaml:"scalar"`
BatcherHash string `yaml:"batcher_hash"`
GasLimit string `yaml:"gas_limit"`
ResourceConfig ResourceMeteringResourceConfig `yaml:"resource_config"`
StartBlock string `yaml:"start_block"`
BaseFeeScalar string `yaml:"base_fee_scalar"`
BlobBaseFeeScalar string `yaml:"blob_base_fee_scalar"`
BatcherInbox string `yaml:"batcher_inbox"`
L1CrossDomainMessengerAddress string `yaml:"l1_cross_domain_messenger_address"`
L1ERC721BridgeAddress string `yaml:"l1_erc_721_bridge_address"`
L1StandardBridgeAddress string `yaml:"l1_standard_bridge_address"`
DisputeGameFactoryAddress string `yaml:"dispute_game_factory_address"`
OptimismPortalAddress string `yaml:"optimism_portal_address"`
OptimismMintableERC20FactoryAddress string `yaml:"optimism_mintable_erc20_factory_address"`
GasPayingTokenAddress string `yaml:"gas_paying_token_address"`
}

// ResourceMeteringResourceConfig is an auto generated low-level Go binding around an user-defined struct.
Expand Down Expand Up @@ -277,6 +287,14 @@ func CheckOldContracts(proxyAddresses map[string]common.Address, backend *ethcli
if err != nil {
return nil, err
}
owner, err := systemConfig.Owner(&bind.CallOpts{})
if err != nil {
return nil, err
}
unsafeBlockSigner, err := systemConfig.UnsafeBlockSigner(&bind.CallOpts{})
if err != nil {
return nil, err
}
overhead, err := systemConfig.Overhead(&bind.CallOpts{})
if err != nil {
return nil, err
Expand Down Expand Up @@ -306,14 +324,16 @@ func CheckOldContracts(proxyAddresses map[string]common.Address, backend *ethcli
MaximumBaseFee: resourceConfig.MaximumBaseFee.String(),
}
oldSystemConfig := SystemConfigInfo{
Name: "SystemConfig",
Address: proxyAddresses["SystemConfigProxy"].String(),
Version: version,
Overhead: overhead.String(),
Scalar: scalar.String(),
BatcherHash: hex.EncodeToString(batcherHash[:]),
GasLimit: strconv.FormatUint(gasLimit, 10),
ResourceConfig: newResourceConfig,
Name: "SystemConfig",
Address: proxyAddresses["SystemConfigProxy"].String(),
Owner: owner.String(),
UnsafeBlockSigner: unsafeBlockSigner.String(),
Version: version,
Overhead: overhead.String(),
Scalar: scalar.String(),
BatcherHash: hex.EncodeToString(batcherHash[:]),
GasLimit: strconv.FormatUint(gasLimit, 10),
ResourceConfig: newResourceConfig,
}
data := []interface{}{oldL1CrossDomainMessenger, oldL1ERC721Bridge,
oldL1StandardBridge, oldL2OutputOracle, oldOptimismMintableERC20Factory, oldOptimismPortal, oldSystemConfig}
Expand Down Expand Up @@ -503,6 +523,14 @@ func CheckNewContracts(proxyAddresses map[string]common.Address, backend *ethcli
SuperChainConfig: superChainConfig.String(),
}
systemConfig, err := newBindings.NewSystemConfigCaller(proxyAddresses["SystemConfigProxy"], backend)
owner, err := systemConfig.Owner(&bind.CallOpts{})
if err != nil {
return nil, err
}
unsafeBlockSigner, err := systemConfig.UnsafeBlockSigner(&bind.CallOpts{})
if err != nil {
return nil, err
}
version, err = systemConfig.Version(&bind.CallOpts{})
if err != nil {
return nil, err
Expand Down Expand Up @@ -547,25 +575,67 @@ func CheckNewContracts(proxyAddresses map[string]common.Address, backend *ethcli
if err != nil {
return nil, err
}
batchInbox, err := systemConfig.BatchInbox(&bind.CallOpts{})
if err != nil {
return nil, err
}
l1CrossDomainMessengerAddress, err := systemConfig.L1CrossDomainMessenger(&bind.CallOpts{})
if err != nil {
return nil, err
}
l1ERC721BridgeAddress, err := systemConfig.L1ERC721Bridge(&bind.CallOpts{})
if err != nil {
return nil, err
}
l1StandardBridgeAddress, err := systemConfig.L1StandardBridge(&bind.CallOpts{})
if err != nil {
return nil, err
}
disputeGameFactoryAddress, err := systemConfig.DisputeGameFactory(&bind.CallOpts{})
if err != nil {
return nil, err
}
optimismPortalAddress, err := systemConfig.OptimismPortal(&bind.CallOpts{})
if err != nil {
return nil, err
}
optimismMintableERC20FactoryAddress, err := systemConfig.OptimismMintableERC20Factory(&bind.CallOpts{})
if err != nil {
return nil, err
}
gasPayingTokenAddress, err := systemConfig.GasPayingToken(&bind.CallOpts{})
if err != nil {
return nil, err
}
newSystemConfig := SystemConfigInfo{
Name: "SystemConfig",
Address: proxyAddresses["SystemConfigProxy"].String(),
Version: version,
Overhead: overhead.String(),
Scalar: scalar.String(),
BatcherHash: hex.EncodeToString(batcherHash[:]),
GasLimit: strconv.FormatUint(gasLimit, 10),
ResourceConfig: newResourceConfig,
StartBlock: startBlock.String(),
BaseFeeScalar: strconv.FormatUint(uint64(baseFeeScalar), 10),
BlobBaseFeeScalar: strconv.FormatUint(uint64(blobBaseFeeScalar), 10),
Name: "SystemConfig",
Address: proxyAddresses["SystemConfigProxy"].String(),
Version: version,
Owner: owner.String(),
UnsafeBlockSigner: unsafeBlockSigner.String(),
Overhead: overhead.String(),
Scalar: scalar.String(),
BatcherHash: hex.EncodeToString(batcherHash[:]),
GasLimit: strconv.FormatUint(gasLimit, 10),
ResourceConfig: newResourceConfig,
StartBlock: startBlock.String(),
BaseFeeScalar: strconv.FormatUint(uint64(baseFeeScalar), 10),
BlobBaseFeeScalar: strconv.FormatUint(uint64(blobBaseFeeScalar), 10),
BatcherInbox: batchInbox.String(),
L1CrossDomainMessengerAddress: l1CrossDomainMessengerAddress.String(),
L1ERC721BridgeAddress: l1ERC721BridgeAddress.String(),
L1StandardBridgeAddress: l1StandardBridgeAddress.String(),
DisputeGameFactoryAddress: disputeGameFactoryAddress.String(),
OptimismPortalAddress: optimismPortalAddress.String(),
OptimismMintableERC20FactoryAddress: optimismMintableERC20FactoryAddress.String(),
GasPayingTokenAddress: gasPayingTokenAddress.Addr.String(),
}
data := []interface{}{newL1CrossDomainMessenger, newL1ERC721Bridge,
newL1StandardBridge, newL2OutputOracle, newOptimismMintableERC20Factory, newOptimismPortal, newSystemConfig}
return data, nil
}

func CompareContracts(oldContractsFilePath string, newContractsFilePath string) error {
func CompareContracts(oldContractsFilePath string, newContractsFilePath string, proxyAddresses map[string]common.Address, batchInboxAddr common.Address) error {
oldContractsFile, err := os.Open(oldContractsFilePath)
if err != nil {
return err
Expand Down Expand Up @@ -775,9 +845,15 @@ func CompareContracts(oldContractsFilePath string, newContractsFilePath string)
if newSystemConfigInfo.Overhead != oldSystemConfigInfo.Overhead {
return fmt.Errorf("SystemConfig Overhead var check diff, expect %s actual %s", oldSystemConfigInfo.Overhead, newSystemConfigInfo.Overhead)
}
//if newSystemConfigInfo.Scalar != oldSystemConfigInfo.Scalar {
// return fmt.Errorf("SystemConfig Scalar var check diff, expect %s actual %s", oldSystemConfigInfo.Scalar, newSystemConfigInfo.Scalar)
//}
if newSystemConfigInfo.Scalar != oldSystemConfigInfo.Scalar {
return fmt.Errorf("SystemConfig Scalar var check diff, expect %s actual %s", oldSystemConfigInfo.Scalar, newSystemConfigInfo.Scalar)
}
if newSystemConfigInfo.Owner != oldSystemConfigInfo.Owner {
return fmt.Errorf("SystemConfig Owner var check diff, expect %s actual %s", oldSystemConfigInfo.Owner, newSystemConfigInfo.Owner)
}
if newSystemConfigInfo.UnsafeBlockSigner != oldSystemConfigInfo.UnsafeBlockSigner {
return fmt.Errorf("SystemConfig UnsafeBlockSigner var check diff, expect %s actual %s", oldSystemConfigInfo.UnsafeBlockSigner, newSystemConfigInfo.UnsafeBlockSigner)
}
if newSystemConfigInfo.BatcherHash != oldSystemConfigInfo.BatcherHash {
return fmt.Errorf("SystemConfig BatcherHash var check diff, expect %s actual %s", oldSystemConfigInfo.BatcherHash, newSystemConfigInfo.BatcherHash)
}
Expand Down Expand Up @@ -808,6 +884,30 @@ func CompareContracts(oldContractsFilePath string, newContractsFilePath string)
if newSystemConfigInfo.ResourceConfig.MaximumBaseFee != oldSystemConfigInfo.ResourceConfig.MaximumBaseFee {
return fmt.Errorf("SystemConfig ResourceConfig.MaximumBaseFee var check diff, expect %s actual %s", oldSystemConfigInfo.ResourceConfig.MaximumBaseFee, newSystemConfigInfo.ResourceConfig.MaximumBaseFee)
}
if newSystemConfigInfo.BatcherInbox != batchInboxAddr.String() {
return fmt.Errorf("SystemConfig BatcherInbox var check diff, expect %s actual %s", batchInboxAddr.String(), newSystemConfigInfo.BatcherInbox)
}
if newSystemConfigInfo.L1CrossDomainMessengerAddress != proxyAddresses["L1CrossDomainMessengerProxy"].String() {
return fmt.Errorf("SystemConfig L1CrossDomainMessengerAddress var check diff, expect %s actual %s", proxyAddresses["L1CrossDomainMessengerProxy"].String(), newSystemConfigInfo.L1CrossDomainMessengerAddress)
}
if newSystemConfigInfo.L1ERC721BridgeAddress != proxyAddresses["L1ERC721BridgeProxy"].String() {
return fmt.Errorf("SystemConfig L1ERC721BridgeAddress var check diff, expect %s actual %s", proxyAddresses["L1ERC721BridgeProxy"].String(), newSystemConfigInfo.L1ERC721BridgeAddress)
}
if newSystemConfigInfo.L1StandardBridgeAddress != proxyAddresses["L1StandardBridgeProxy"].String() {
return fmt.Errorf("SystemConfig L1StandardBridgeAddress var check diff, expect %s actual %s", proxyAddresses["L1StandardBridgeAddressProxy"].String(), newSystemConfigInfo.L1StandardBridgeAddress)
}
if newSystemConfigInfo.DisputeGameFactoryAddress != ZeroAddress {
return fmt.Errorf("SystemConfig L1StandardBridgeAddress var check diff, expect %s actual %s", ZeroAddress, newSystemConfigInfo.DisputeGameFactoryAddress)
}
if newSystemConfigInfo.OptimismPortalAddress != proxyAddresses["OptimismPortalProxy"].String() {
return fmt.Errorf("SystemConfig OptimismPortalAddress var check diff, expect %s actual %s", proxyAddresses["OptimismPortalAddressProxy"].String(), newSystemConfigInfo.OptimismPortalAddress)
}
if newSystemConfigInfo.OptimismMintableERC20FactoryAddress != proxyAddresses["OptimismMintableERC20FactoryProxy"].String() {
return fmt.Errorf("SystemConfig OptimismMintableERC20FactoryAddress var check diff, expect %s actual %s", proxyAddresses["OptimismMintableERC20FactoryProxy"].String(), newSystemConfigInfo.OptimismMintableERC20FactoryAddress)
}
if newSystemConfigInfo.GasPayingTokenAddress != ETHER {
return fmt.Errorf("SystemConfig GasPayingTokenAddress var check diff, expect %s actual %s", ETHER, newSystemConfigInfo.GasPayingTokenAddress)
}
return nil
}

Expand Down
17 changes: 11 additions & 6 deletions op-chain-ops/opbnb-upgrades/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const (
)

const (
bscTestnetStartBlock = 30727847
bscMainnetStartBlock = 30758357
bscQAnetStartBlock = 44147099
BscTestnetStartBlock = 30727847
BscMainnetStartBlock = 30758357
BscQAnetStartBlock = 44147099
)

const (
Expand All @@ -19,10 +19,15 @@ const (
Blobbasefeescala uint32 = 655000
)

const (
ETHER = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
ZeroAddress = "0x0000000000000000000000000000000000000000"
)

var (
bscTestnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000005611")
bscMainnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000000204")
bscQAnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000008848")
BscTestnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000005611")
BscMainnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000000204")
BscQAnetBatcherInbox = common.HexToAddress("0xff00000000000000000000000000000000008848")
)

var BscTestnetProxyContracts = map[string]common.Address{
Expand Down
12 changes: 6 additions & 6 deletions op-chain-ops/opbnb-upgrades/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ func SystemConfig(batch *safe.Batch, proxyAddresses map[string]common.Address, i
}

// set startBlock genesis block l1 origin
startBlock := common.BigToHash(new(big.Int).SetUint64(bscQAnetStartBlock))
startBlock := common.BigToHash(new(big.Int).SetUint64(BscQAnetStartBlock))
if chainId.Uint64() == BscTestnet {
startBlock = common.BigToHash(new(big.Int).SetUint64(bscTestnetStartBlock))
startBlock = common.BigToHash(new(big.Int).SetUint64(BscTestnetStartBlock))
} else if chainId.Uint64() == BscMainnet {
startBlock = common.BigToHash(new(big.Int).SetUint64(bscMainnetStartBlock))
startBlock = common.BigToHash(new(big.Int).SetUint64(BscMainnetStartBlock))
}

input := []bindings.StorageSetterSlot{
Expand Down Expand Up @@ -660,11 +660,11 @@ func SystemConfig(batch *safe.Batch, proxyAddresses map[string]common.Address, i
}

// set startBlock genesis block l1 origin
batchInboxAddr := bscQAnetBatcherInbox
batchInboxAddr := BscQAnetBatcherInbox
if chainId.Uint64() == BscTestnet {
batchInboxAddr = bscTestnetBatcherInbox
batchInboxAddr = BscTestnetBatcherInbox
} else if chainId.Uint64() == BscMainnet {
batchInboxAddr = bscMainnetBatcherInbox
batchInboxAddr = BscMainnetBatcherInbox
}
_basefeeScalar := BasefeeScalar
_blobbasefeeScalar := Blobbasefeescala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
"SystemConfig": "0x406aC857817708eAf4ca3A82317eF4ae3D1EA23B",
"Guardian": "0x9e1A970683f6Cf53a4e3F13faCFaDC1c7E37D9bc",
"SuperChainConfig": "",
"Balance": "282513270126855175611174"
"Balance": "282865745286885175611178"
},
{
"SystemConfigInfo": "",
"Name": "SystemConfig",
"Address": "0x406aC857817708eAf4ca3A82317eF4ae3D1EA23B",
"Version": "1.3.0",
"Owner": "0x9e1A970683f6Cf53a4e3F13faCFaDC1c7E37D9bc",
"UnsafeBlockSigner": "0x23264E1F3C04efBe84108E666a187D240DDAfcED",
"Overhead": "0",
"Scalar": "452312848583266388373324160190187140051835877600158453279134000734489610656",
"BatcherHash": "0000000000000000000000001fd6a75cc72f39147756a663f3ef1fc95ef89495",
Expand All @@ -79,7 +81,15 @@
},
"StartBlock": "",
"BaseFeeScalar": "",
"BlobBaseFeeScalar": ""
"BlobBaseFeeScalar": "",
"BatcherInbox": "",
"L1CrossDomainMessengerAddress": "",
"L1ERC721BridgeAddress": "",
"L1StandardBridgeAddress": "",
"DisputeGameFactoryAddress": "",
"OptimismPortalAddress": "",
"OptimismMintableERC20FactoryAddress": "",
"GasPayingTokenAddress": ""
}
]

0 comments on commit b8afadd

Please sign in to comment.