diff --git a/common/constants.all.go b/common/constants.all.go index 3400ccad6f..52d432aee9 100644 --- a/common/constants.all.go +++ b/common/constants.all.go @@ -64,6 +64,7 @@ type constant struct { tipEpochHalving *big.Int eip1559Block *big.Int cancunBlock *big.Int + pragueBlock *big.Int trc21IssuerSMC Address xdcxListingSMC Address @@ -98,6 +99,7 @@ var ( TIPXDCXReceiverDisable = MainnetConstant.tipXDCXReceiverDisable Eip1559Block = MainnetConstant.eip1559Block CancunBlock = MainnetConstant.cancunBlock + PragueBlock = MainnetConstant.pragueBlock TIPUpgradeReward = MainnetConstant.tipUpgradeReward TipUpgradePenalty = MainnetConstant.tipUpgradePenalty TIPEpochHalving = MainnetConstant.tipEpochHalving @@ -160,6 +162,7 @@ func CopyConstants(chainID uint64) { TIPXDCXReceiverDisable = c.tipXDCXReceiverDisable Eip1559Block = c.eip1559Block CancunBlock = c.cancunBlock + PragueBlock = c.pragueBlock TIPUpgradeReward = c.tipUpgradeReward TipUpgradePenalty = c.tipUpgradePenalty TIPEpochHalving = c.tipEpochHalving diff --git a/common/constants.devnet.go b/common/constants.devnet.go index c7133f6315..06c92bd24e 100644 --- a/common/constants.devnet.go +++ b/common/constants.devnet.go @@ -1,6 +1,7 @@ package common import ( + "math" "math/big" ) @@ -28,6 +29,7 @@ var DevnetConstant = constant{ tipXDCXReceiverDisable: big.NewInt(0), eip1559Block: big.NewInt(32400), cancunBlock: big.NewInt(43200), + pragueBlock: big.NewInt(math.MaxInt64), tipUpgradeReward: big.NewInt(9999999999), tipUpgradePenalty: big.NewInt(9999999999), tipEpochHalving: big.NewInt(9999999999), diff --git a/common/constants.local.go b/common/constants.local.go index 291d2871de..7a641631f6 100644 --- a/common/constants.local.go +++ b/common/constants.local.go @@ -1,6 +1,7 @@ package common import ( + "math" "math/big" ) @@ -28,6 +29,7 @@ var localConstant = constant{ tipXDCXReceiverDisable: big.NewInt(0), eip1559Block: big.NewInt(0), cancunBlock: big.NewInt(0), + pragueBlock: big.NewInt(math.MaxInt64), tipUpgradeReward: big.NewInt(999999999), tipUpgradePenalty: big.NewInt(999999999), tipEpochHalving: big.NewInt(999999999), diff --git a/common/constants.mainnet.go b/common/constants.mainnet.go index b4123fee70..869fc575e8 100644 --- a/common/constants.mainnet.go +++ b/common/constants.mainnet.go @@ -1,6 +1,7 @@ package common import ( + "math" "math/big" ) @@ -28,6 +29,7 @@ var MainnetConstant = constant{ tipXDCXReceiverDisable: big.NewInt(80370900), // Target 2nd Oct 2024, safer to release after disable miner eip1559Block: big.NewInt(9999999999), cancunBlock: big.NewInt(9999999999), + pragueBlock: big.NewInt(math.MaxInt64), tipUpgradeReward: big.NewInt(9999999999), tipUpgradePenalty: big.NewInt(9999999999), tipEpochHalving: big.NewInt(9999999999), diff --git a/common/constants.testnet.go b/common/constants.testnet.go index 055fd43494..786af3496c 100644 --- a/common/constants.testnet.go +++ b/common/constants.testnet.go @@ -1,6 +1,7 @@ package common import ( + "math" "math/big" ) @@ -28,6 +29,7 @@ var TestnetConstant = constant{ tipXDCXReceiverDisable: big.NewInt(66825000), // Target 26 Aug 2024 eip1559Block: big.NewInt(71550000), // Target 14th Feb 2025 cancunBlock: big.NewInt(71551800), + pragueBlock: big.NewInt(math.MaxInt64), tipUpgradeReward: big.NewInt(9999999999), tipUpgradePenalty: big.NewInt(9999999999), tipEpochHalving: big.NewInt(9999999999), diff --git a/core/vm/gas_table_test.go b/core/vm/gas_table_test.go index e4f1abedd6..1bb8132ea2 100644 --- a/core/vm/gas_table_test.go +++ b/core/vm/gas_table_test.go @@ -121,15 +121,15 @@ var createGasTests = []struct { // legacy create(0, 0, 0xc000) _with_ 3860 {"0x61C00060006000f0" + "600052" + "60206000F3", true, 44309, 44309}, // create2(0, 0, 0xc001, 0) without 3860 - {"0x600061C00160006000f5" + "600052" + "60206000F3", false, 50471, 100_000}, + {"0x600061C00160006000f5" + "600052" + "60206000F3", false, 50471, 50471}, // create2(0, 0, 0xc001, 0) (too large), with 3860 - {"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32012, 100_000}, + {"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32012, 100000}, // create2(0, 0, 0xc000, 0) // This case is trying to deploy code at (within) the limit - {"0x600061C00060006000f5" + "600052" + "60206000F3", true, 53528, 100_000}, + {"0x600061C00060006000f5" + "600052" + "60206000F3", true, 53528, 53528}, // create2(0, 0, 0xc001, 0) // This case is trying to deploy code exceeding the limit - {"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32024, 100_000}} + {"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32024, 100000}} func TestCreateGas(t *testing.T) { for i, tt := range createGasTests { diff --git a/core/vm/jump_table_export.go b/core/vm/jump_table_export.go index 89d8504b54..e925bfb354 100644 --- a/core/vm/jump_table_export.go +++ b/core/vm/jump_table_export.go @@ -17,6 +17,8 @@ package vm import ( + "errors" + "github.com/XinFinOrg/XDPoSChain/params" ) @@ -24,6 +26,8 @@ import ( // the rules. func LookupInstructionSet(rules params.Rules) (JumpTable, error) { switch { + case rules.IsPrague: + return newCancunInstructionSet(), errors.New("prague-fork not defined yet") case rules.IsCancun: return newCancunInstructionSet(), nil case rules.IsEIP1559: diff --git a/params/config.go b/params/config.go index 7ed6afe103..4d7b99445f 100644 --- a/params/config.go +++ b/params/config.go @@ -314,9 +314,6 @@ var ( // AllEthashProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Ethash consensus. - // - // This configuration is intentionally not using keyed fields to force anyone - // adding flags to the config to also have to set these fields. AllEthashProtocolChanges = &ChainConfig{ ChainID: big.NewInt(1337), HomesteadBlock: big.NewInt(0), @@ -326,7 +323,15 @@ var ( EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: nil, + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + ShanghaiBlock: big.NewInt(0), + Eip1559Block: nil, + CancunBlock: nil, + PragueBlock: nil, Ethash: new(EthashConfig), Clique: nil, XDPoS: nil, @@ -352,6 +357,8 @@ var ( XDPoS: &XDPoSConfig{Period: 0, Epoch: 900}, } + // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced + // and accepted by the Ethereum core developers into the Clique consensus. AllCliqueProtocolChanges = &ChainConfig{ ChainID: big.NewInt(1337), HomesteadBlock: big.NewInt(0), @@ -361,7 +368,15 @@ var ( EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: nil, + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + ShanghaiBlock: big.NewInt(0), + Eip1559Block: nil, + CancunBlock: nil, + PragueBlock: nil, Ethash: nil, Clique: &CliqueConfig{Period: 0, Epoch: 900}, XDPoS: nil, @@ -395,6 +410,8 @@ var ( }, } + // TestChainConfig contains every protocol change (EIPs) introduced + // and accepted by the Ethereum core developers for testing purposes. TestChainConfig = &ChainConfig{ ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), @@ -404,7 +421,15 @@ var ( EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: nil, + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + BerlinBlock: big.NewInt(0), + LondonBlock: big.NewInt(0), + ShanghaiBlock: big.NewInt(0), + Eip1559Block: nil, + CancunBlock: nil, + PragueBlock: nil, Ethash: new(EthashConfig), Clique: nil, XDPoS: nil, @@ -441,6 +466,7 @@ type ChainConfig struct { ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` Eip1559Block *big.Int `json:"eip1559Block,omitempty"` CancunBlock *big.Int `json:"cancunBlock,omitempty"` + PragueBlock *big.Int `json:"pragueBlock,omitempty"` // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` @@ -761,6 +787,9 @@ func (c *ChainConfig) String() string { if c.CancunBlock != nil { result += fmt.Sprintf(", CancunBlock: %v", c.CancunBlock) } + if c.PragueBlock != nil { + result += fmt.Sprintf(", PragueBlock: %v", c.PragueBlock) + } if c.XDPoS != nil { result += fmt.Sprintf(", %s", c.XDPoS.String()) } @@ -803,6 +832,10 @@ func (c *ChainConfig) Description() string { if c.CancunBlock != nil { cancunBlock = c.CancunBlock } + pragueBlock := common.PragueBlock + if c.PragueBlock != nil { + pragueBlock = c.PragueBlock + } var banner = "Chain configuration:\n" banner += fmt.Sprintf(" - ChainID: %-8v\n", c.ChainID) @@ -821,6 +854,7 @@ func (c *ChainConfig) Description() string { banner += fmt.Sprintf(" - Shanghai: %-8v\n", shanghaiBlock) banner += fmt.Sprintf(" - Eip1559: %-8v\n", eip1559Block) banner += fmt.Sprintf(" - Cancun: %-8v\n", cancunBlock) + banner += fmt.Sprintf(" - Prague: %-8v\n", pragueBlock) banner += fmt.Sprintf(" - TIPUpgradeReward: %-8v\n", common.TIPUpgradeReward) banner += fmt.Sprintf(" - TIPEpochHalving: %-8v\n", common.TIPEpochHalving) banner += fmt.Sprintf(" - Engine: %v", engine) @@ -890,14 +924,21 @@ func (c *ChainConfig) IsShanghai(num *big.Int) bool { return isForked(common.ShanghaiBlock, num) || isForked(c.ShanghaiBlock, num) } +// IsEIP1559 returns whether num is either equal to the EIP1559 fork block or greater. func (c *ChainConfig) IsEIP1559(num *big.Int) bool { return isForked(common.Eip1559Block, num) || isForked(c.Eip1559Block, num) } +// IsCancun returns whether num is either equal to the Cancun fork block or greater. func (c *ChainConfig) IsCancun(num *big.Int) bool { return isForked(common.CancunBlock, num) || isForked(c.CancunBlock, num) } +// IsPrague returns whether num is either equal to the Prague fork block or greater. +func (c *ChainConfig) IsPrague(num *big.Int) bool { + return isForked(common.PragueBlock, num) || isForked(c.PragueBlock, num) +} + func (c *ChainConfig) IsTIP2019(num *big.Int) bool { return isForked(common.TIP2019Block, num) } @@ -1043,6 +1084,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.CancunBlock, newcfg.CancunBlock, head) { return newCompatError("Cancun fork block", c.CancunBlock, newcfg.CancunBlock) } + if isForkIncompatible(c.PragueBlock, newcfg.PragueBlock, head) { + return newCompatError("Prague fork block", c.PragueBlock, newcfg.PragueBlock) + } if !XDPoSConfigEqual(c.XDPoS, newcfg.XDPoS) { storedblock := big.NewInt(1) if c.XDPoS != nil && c.XDPoS.V2 != nil && c.XDPoS.V2.SwitchBlock != nil { @@ -1118,14 +1162,23 @@ func (err *ConfigCompatError) Error() string { // Rules is a one time interface meaning that it shouldn't be used in between transition // phases. type Rules struct { - ChainId *big.Int - IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool - IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool - IsBerlin, IsLondon bool - IsMerge, IsShanghai bool - IsXDCxDisable bool - IsEIP1559 bool - IsCancun bool + ChainId *big.Int + IsHomestead bool + IsEIP150 bool + IsEIP155 bool + IsEIP158 bool + IsByzantium bool + IsConstantinople bool + IsPetersburg bool + IsIstanbul bool + IsBerlin bool + IsLondon bool + IsMerge bool + IsShanghai bool + IsXDCxDisable bool + IsEIP1559 bool + IsCancun bool + IsPrague bool } func (c *ChainConfig) Rules(num *big.Int) Rules { @@ -1150,5 +1203,6 @@ func (c *ChainConfig) Rules(num *big.Int) Rules { IsXDCxDisable: c.IsXDCxDisable(num), IsEIP1559: c.IsEIP1559(num), IsCancun: c.IsCancun(num), + IsPrague: c.IsPrague(num), } }