fix test, add napoli block

This commit is contained in:
Anshal Shukla 2023-11-30 12:56:21 +05:30
parent 738107b6c8
commit 05a19f2a36
4 changed files with 26 additions and 7 deletions

View file

@ -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:

View file

@ -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)
}

View file

@ -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),
}
}