diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 4d1047d948..5d1728d1fd 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -105,13 +105,14 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{18}): &bls12381MapG2{}, } -// PrecompiledContractsP256Verify contains the precompiled Ethereum +// PrecompiledContractsNapoli contains the precompiled Ethereum // contract specified in EIP-7212. This is exported for testing purposes. -var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{ +var PrecompiledContractsNapoli = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{19}): &p256Verify{}, } var ( + PrecompiledAddressesNapoli []common.Address PrecompiledAddressesBerlin []common.Address PrecompiledAddressesIstanbul []common.Address PrecompiledAddressesByzantium []common.Address @@ -134,11 +135,17 @@ func init() { for k := range PrecompiledContractsBerlin { PrecompiledAddressesBerlin = append(PrecompiledAddressesBerlin, k) } + + for k := range PrecompiledContractsNapoli { + PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k) + } } // ActivePrecompiles returns the precompiles enabled with the current configuration. func ActivePrecompiles(rules params.Rules) []common.Address { switch { + case rules.IsNapoli: + return PrecompiledAddressesNapoli case rules.IsBerlin: return PrecompiledAddressesBerlin case rules.IsIstanbul: diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 24ddae0715..c55f58eb51 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -423,4 +423,8 @@ func BenchmarkPrecompiledP256Verify(bench *testing.B) { benchmarkPrecompiled("13", t, bench) } -func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "13", t) } +func TestPrecompiledP256Verify(t *testing.T) { + t.Parallel() + + testJson("p256Verify", "13", t) +} diff --git a/core/vm/testdata/precompiles/p256Verify.json b/core/vm/testdata/precompiles/p256Verify.json index fbcac41e9f..c01387dda7 100644 --- a/core/vm/testdata/precompiles/p256Verify.json +++ b/core/vm/testdata/precompiles/p256Verify.json @@ -6,4 +6,4 @@ "Name": "CallP256Verify", "NoBenchmark": false } - ] \ No newline at end of file +] \ No newline at end of file diff --git a/params/config.go b/params/config.go index e3740068c6..278374356b 100644 --- a/params/config.go +++ b/params/config.go @@ -649,6 +649,7 @@ type ChainConfig struct { ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch Block (nil = no fork, 0 = already on shanghai) CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch Block (nil = no fork, 0 = already on cancun) PragueBlock *big.Int `json:"pragueBlock,omitempty"` // Prague switch Block (nil = no fork, 0 = already on prague) + NapoliBlock *big.Int `json:"napoliBlock,omitempty"` // Napoli switch Block (nil = no fork, 0 = already on Napoli) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -971,21 +972,26 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0 } -// IsShanghai returns whether time is either equal to the Shanghai fork time or greater. +// IsShanghai returns whether num is either equal to the Shanghai fork block or greater. func (c *ChainConfig) IsShanghai(num *big.Int) bool { return isBlockForked(c.ShanghaiBlock, num) } -// IsCancun returns whether num is either equal to the Cancun fork time or greater. +// IsCancun returns whether num is either equal to the Cancun fork block or greater. func (c *ChainConfig) IsCancun(num *big.Int) bool { return isBlockForked(c.CancunBlock, num) } -// IsPrague returns whether num is either equal to the Prague fork time or greater. +// IsPrague returns whether num is either equal to the Prague fork block or greater. func (c *ChainConfig) IsPrague(num *big.Int) bool { return isBlockForked(c.PragueBlock, num) } +// IsNapoli returns whether num is either equal to the Napoli fork block or greater. +func (c *ChainConfig) IsNapoli(num *big.Int) bool { + return isBlockForked(c.NapoliBlock, num) +} + // CheckCompatible checks whether scheduled fork transitions have been imported // with a mismatching chain configuration. func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError { @@ -1327,6 +1333,7 @@ type Rules struct { IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsBerlin, IsLondon bool IsMerge, IsShanghai, IsCancun, IsPrague bool + IsNapoli bool } // Rules ensures c's ChainID is not nil. @@ -1352,5 +1359,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsShanghai: c.IsShanghai(num), IsCancun: c.IsCancun(num), IsPrague: c.IsPrague(num), + IsNapoli: c.IsNapoli(num), } }