From 07dad0d79770e51ad89e4c132d48d6b9c9d1d0cf Mon Sep 17 00:00:00 2001 From: PinelliaC Date: Wed, 10 Jul 2024 10:47:49 +0800 Subject: [PATCH 1/2] fix: add ProxyOwnerUpgradeTime to mantle upgrade config --- core/genesis.go | 1 + core/mantle_upgrade.go | 23 +++++++++++++++++++++++ core/state_transition.go | 5 +++++ params/config.go | 8 ++++++++ 4 files changed, 37 insertions(+) diff --git a/core/genesis.go b/core/genesis.go index e99eea751c..a32b6ab9df 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -313,6 +313,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen config.BVMETHMintUpgradeTime = mantleUpgradeChainConfig.BVMETHMintUpgradeTime config.MetaTxV2UpgradeTime = mantleUpgradeChainConfig.MetaTxV2UpgradeTime config.MetaTxV3UpgradeTime = mantleUpgradeChainConfig.MetaTxV3UpgradeTime + config.ProxyOwnerUpgradeTime = mantleUpgradeChainConfig.ProxyOwnerUpgradeTime } if overrides != nil && overrides.OverrideShanghai != nil { diff --git a/core/mantle_upgrade.go b/core/mantle_upgrade.go index 1290d7d723..bfd509b8d9 100644 --- a/core/mantle_upgrade.go +++ b/core/mantle_upgrade.go @@ -3,6 +3,7 @@ package core import ( "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" ) @@ -13,6 +14,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: nil, //TODO set upgrade timestamp + ProxyOwnerUpgradeTime: nil, //TODO set upgrade timestamp } MantleSepoliaUpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleSepoliaChainId, @@ -20,6 +22,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(1_720_594_800), MetaTxV2UpgradeTime: u64Ptr(1_720_594_800), MetaTxV3UpgradeTime: u64Ptr(1_720_594_800), + ProxyOwnerUpgradeTime: u64Ptr(0), } MantleSepoliaQA3UpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleSepoliaQA3ChainId, @@ -27,6 +30,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(1_717_689_600), + ProxyOwnerUpgradeTime: u64Ptr(0), } MantleSepoliaQA9UpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleSepoliaQA9ChainId, @@ -34,6 +38,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(1_716_962_400), + ProxyOwnerUpgradeTime: u64Ptr(0), } MantleLocalUpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleLocalChainId, @@ -41,15 +46,32 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(0), + ProxyOwnerUpgradeTime: u64Ptr(0), } MantleDefaultUpgradeConfig = MantleUpgradeChainConfig{ BaseFeeTime: u64Ptr(0), BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: nil, + ProxyOwnerUpgradeTime: nil, } ) +// L2ProxyAdmin contract upgrade constants +var ( + // L2ProxyAdminAddress is the address of the L2ProxyAdmin contract + // predeploy + L2ProxyAdminAddress = common.HexToAddress("0x4200000000000000000000000000000000000018") + + // OwnerSlot refers to the storage slot in the L2ProxyAdmin contract that + // holds the owner of the contract + OwnerSlot = common.BigToHash(big.NewInt(0)) + + // NewProxyAdminOwnerAddress is the address that the L2ProxyAdmin contract + // will be transferred to + NewProxyAdminOwnerAddress = common.HexToHash("0x09734bB3980906Bb217305EA6Bd34256feEAB105") +) + type MantleUpgradeChainConfig struct { ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection @@ -57,6 +79,7 @@ type MantleUpgradeChainConfig struct { BVMETHMintUpgradeTime *uint64 `json:"bvmETHMintUpgradeTime"` // BVM_ETH mint upgrade switch time (nil = no fork, 0 = already on) MetaTxV2UpgradeTime *uint64 `json:"metaTxV2UpgradeTime"` // MetaTxV1UpgradeBlock identifies the current block height is using metaTx with MetaTxSignDataV2 MetaTxV3UpgradeTime *uint64 `json:"metaTxV3UpgradeTime"` // MetaTxV3UpgradeBlock identifies the current block height is ensuring sponsor and sender are not the same + ProxyOwnerUpgradeTime *uint64 `json:"proxyOwnerUpgradeTime"` // ProxyOwnerUpgradeBlock identifies the current block time is ensuring the L2ProxyAdmin contract owner is set to NewProxyAdminOwnerAddress } func GetUpgradeConfigForMantle(chainID *big.Int) *MantleUpgradeChainConfig { diff --git a/core/state_transition.go b/core/state_transition.go index 66ebfa39b8..668900c539 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -467,6 +467,11 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { snap := st.state.Snapshot() // Will be reverted if failed + // Check if the owner of the L2ProxyAdmin contract needs to be upgraded + if st.evm.ChainConfig().IsProxyOwnerUpgrade(&st.evm.Context.Time) { + st.evm.StateDB.SetState(L2ProxyAdminAddress, OwnerSlot, NewProxyAdminOwnerAddress) + } + result, err := st.innerTransitionDb() // Failed deposits must still be included. Unless we cannot produce the block at all due to the gas limit. // On deposit failure, we rewind any state changes from after the minting, and increment the nonce. diff --git a/params/config.go b/params/config.go index 0de4c101d8..3f1108f89a 100644 --- a/params/config.go +++ b/params/config.go @@ -467,6 +467,9 @@ type ChainConfig struct { MetaTxV2UpgradeTime *uint64 `json:"metaTxV2UpgradeTime,omitempty"` // MetaTxV2UpgradeTime switch time ( nil = no fork, 0 = already forked) MetaTxV3UpgradeTime *uint64 `json:"metaTxV3UpgradeTime,omitempty"` // MetaTxV3UpgradeTime switch time ( nil = no fork, 0 = already forked) + // ProxyOwner upgrade config + ProxyOwnerUpgradeTime *uint64 `json:"proxyOwnerUpgradeTime,omitempty"` // ProxyOwnerUpgradeTime switch time ( nil = no fork, 0 = already forked) + // Fork scheduling was switched from blocks to timestamps here ShanghaiTime *uint64 `json:"shanghaiTime,omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai) @@ -699,6 +702,11 @@ func (c *ChainConfig) IsMetaTxV3(time uint64) bool { return isTimestampForked(c.MetaTxV3UpgradeTime, time) } +// IsProxyOwnerUpgrade returns whether time is either equal to the ProxyOwnerUpgrade fork time +func (c *ChainConfig) IsProxyOwnerUpgrade(time *uint64) bool { + return configTimestampEqual(c.ProxyOwnerUpgradeTime, time) +} + // IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater. func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool { return isBlockForked(c.ArrowGlacierBlock, num) From b581d00ce00ca16e8124f22986598ed68038d08d Mon Sep 17 00:00:00 2001 From: PinelliaC Date: Mon, 15 Jul 2024 19:40:27 +0800 Subject: [PATCH 2/2] refactor: modify configTimestampEqual to isTimestampEqual --- core/mantle_upgrade.go | 24 ++++-------------------- core/state_transition.go | 17 ++++++++++++++++- params/config.go | 12 ++++++++++-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/core/mantle_upgrade.go b/core/mantle_upgrade.go index bfd509b8d9..6a6e2e883c 100644 --- a/core/mantle_upgrade.go +++ b/core/mantle_upgrade.go @@ -3,7 +3,6 @@ package core import ( "math/big" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" ) @@ -22,7 +21,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(1_720_594_800), MetaTxV2UpgradeTime: u64Ptr(1_720_594_800), MetaTxV3UpgradeTime: u64Ptr(1_720_594_800), - ProxyOwnerUpgradeTime: u64Ptr(0), + ProxyOwnerUpgradeTime: nil, } MantleSepoliaQA3UpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleSepoliaQA3ChainId, @@ -30,7 +29,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(1_717_689_600), - ProxyOwnerUpgradeTime: u64Ptr(0), + ProxyOwnerUpgradeTime: nil, } MantleSepoliaQA9UpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleSepoliaQA9ChainId, @@ -38,7 +37,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(1_716_962_400), - ProxyOwnerUpgradeTime: u64Ptr(0), + ProxyOwnerUpgradeTime: nil, } MantleLocalUpgradeConfig = MantleUpgradeChainConfig{ ChainID: params.MantleLocalChainId, @@ -46,7 +45,7 @@ var ( BVMETHMintUpgradeTime: u64Ptr(0), MetaTxV2UpgradeTime: u64Ptr(0), MetaTxV3UpgradeTime: u64Ptr(0), - ProxyOwnerUpgradeTime: u64Ptr(0), + ProxyOwnerUpgradeTime: nil, } MantleDefaultUpgradeConfig = MantleUpgradeChainConfig{ BaseFeeTime: u64Ptr(0), @@ -57,21 +56,6 @@ var ( } ) -// L2ProxyAdmin contract upgrade constants -var ( - // L2ProxyAdminAddress is the address of the L2ProxyAdmin contract - // predeploy - L2ProxyAdminAddress = common.HexToAddress("0x4200000000000000000000000000000000000018") - - // OwnerSlot refers to the storage slot in the L2ProxyAdmin contract that - // holds the owner of the contract - OwnerSlot = common.BigToHash(big.NewInt(0)) - - // NewProxyAdminOwnerAddress is the address that the L2ProxyAdmin contract - // will be transferred to - NewProxyAdminOwnerAddress = common.HexToHash("0x09734bB3980906Bb217305EA6Bd34256feEAB105") -) - type MantleUpgradeChainConfig struct { ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection diff --git a/core/state_transition.go b/core/state_transition.go index 668900c539..d662ff3cc0 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -37,6 +37,21 @@ var ( LEGACY_ERC20_MNT = common.HexToAddress("0xdEAddEaDdeadDEadDEADDEAddEADDEAddead0000") ) +// L2ProxyAdmin contract upgrade constants +var ( + // L2ProxyAdminAddress is the address of the L2ProxyAdmin contract + // predeploy + L2ProxyAdminAddress = common.HexToAddress("0x4200000000000000000000000000000000000018") + + // OwnerSlot refers to the storage slot in the L2ProxyAdmin contract that + // holds the owner of the contract + OwnerSlot = common.BigToHash(big.NewInt(0)) + + // NewProxyAdminOwnerAddress is the address that the L2ProxyAdmin contract + // will be transferred to + NewProxyAdminOwnerAddress = common.HexToHash("0x09734bB3980906Bb217305EA6Bd34256feEAB105") +) + // ExecutionResult includes all output after executing given evm // message no matter the execution itself is successful or not. type ExecutionResult struct { @@ -468,7 +483,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // Will be reverted if failed // Check if the owner of the L2ProxyAdmin contract needs to be upgraded - if st.evm.ChainConfig().IsProxyOwnerUpgrade(&st.evm.Context.Time) { + if st.evm.ChainConfig().IsProxyOwnerUpgrade(st.evm.Context.Time) { st.evm.StateDB.SetState(L2ProxyAdminAddress, OwnerSlot, NewProxyAdminOwnerAddress) } diff --git a/params/config.go b/params/config.go index 3f1108f89a..8c8e61cf55 100644 --- a/params/config.go +++ b/params/config.go @@ -703,8 +703,8 @@ func (c *ChainConfig) IsMetaTxV3(time uint64) bool { } // IsProxyOwnerUpgrade returns whether time is either equal to the ProxyOwnerUpgrade fork time -func (c *ChainConfig) IsProxyOwnerUpgrade(time *uint64) bool { - return configTimestampEqual(c.ProxyOwnerUpgradeTime, time) +func (c *ChainConfig) IsProxyOwnerUpgrade(time uint64) bool { + return isTimestampEqual(c.ProxyOwnerUpgradeTime, time) } // IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater. @@ -986,6 +986,14 @@ func isTimestampForked(s *uint64, head uint64) bool { return *s <= head } +// isTimestampEqual returns whether it is time to fork. +func isTimestampEqual(s *uint64, head uint64) bool { + if s == nil { + return false + } + return *s == head +} + func configTimestampEqual(x, y *uint64) bool { if x == nil { return y == nil