From c633c02753308f74977469996683985b1a203a88 Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Tue, 21 May 2024 11:12:33 +0800 Subject: [PATCH] core/vm: add secp256r1 into PrecompiledContractsHaber --- cmd/geth/chaincmd.go | 5 +++++ cmd/geth/config.go | 4 ++++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 5 +++++ core/genesis.go | 4 ++++ core/vm/contracts.go | 30 ++++++++++++++++++++++++++++++ eth/backend.go | 4 ++++ eth/ethconfig/config.go | 3 +++ eth/ethconfig/gen_config.go | 6 ++++++ params/config.go | 11 +++++++++-- 10 files changed, 71 insertions(+), 2 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index b7ff192334..7f810dbe20 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -63,6 +63,7 @@ var ( Flags: flags.Merge([]cli.Flag{ utils.CachePreimagesFlag, utils.OverrideCancun, + utils.OverrideHaber, utils.OverrideVerkle, }, utils.DatabaseFlags), Description: ` @@ -256,6 +257,10 @@ func initGenesis(ctx *cli.Context) error { v := ctx.Uint64(utils.OverrideCancun.Name) overrides.OverrideCancun = &v } + if ctx.IsSet(utils.OverrideHaber.Name) { + v := ctx.Uint64(utils.OverrideHaber.Name) + overrides.OverrideHaber = &v + } if ctx.IsSet(utils.OverrideVerkle.Name) { v := ctx.Uint64(utils.OverrideVerkle.Name) overrides.OverrideVerkle = &v diff --git a/cmd/geth/config.go b/cmd/geth/config.go index ca7e7810a7..d35e088ff2 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -189,6 +189,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { v := ctx.Uint64(utils.OverrideCancun.Name) cfg.Eth.OverrideCancun = &v } + if ctx.IsSet(utils.OverrideHaber.Name) { + v := ctx.Uint64(utils.OverrideHaber.Name) + cfg.Eth.OverrideHaber = &v + } if ctx.IsSet(utils.OverrideVerkle.Name) { v := ctx.Uint64(utils.OverrideVerkle.Name) cfg.Eth.OverrideVerkle = &v diff --git a/cmd/geth/main.go b/cmd/geth/main.go index d4be86c012..4689290d6b 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -73,6 +73,7 @@ var ( utils.SmartCardDaemonPathFlag, utils.RialtoHash, utils.OverrideCancun, + utils.OverrideHaber, utils.OverrideVerkle, utils.OverrideFullImmutabilityThreshold, utils.OverrideMinBlocksForBlobRequests, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c2653dd66e..e6faa8d0f8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -310,6 +310,11 @@ var ( Usage: "Manually specify the Cancun fork timestamp, overriding the bundled setting", Category: flags.EthCategory, } + OverrideHaber = &cli.Uint64Flag{ + Name: "override.haber", + Usage: "Manually specify the Haber fork timestamp, overriding the bundled setting", + Category: flags.EthCategory, + } OverrideVerkle = &cli.Uint64Flag{ Name: "override.verkle", Usage: "Manually specify the Verkle fork timestamp, overriding the bundled setting", diff --git a/core/genesis.go b/core/genesis.go index 0e567f8231..b4833ac8a6 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -217,6 +217,7 @@ func (e *GenesisMismatchError) Error() string { // Typically, these modifications involve hardforks that are not enabled on the BSC mainnet, intended for testing purposes. type ChainOverrides struct { OverrideCancun *uint64 + OverrideHaber *uint64 OverrideVerkle *uint64 } @@ -246,6 +247,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g if overrides != nil && overrides.OverrideCancun != nil { config.CancunTime = overrides.OverrideCancun } + if overrides != nil && overrides.OverrideHaber != nil { + config.HaberTime = overrides.OverrideHaber + } if overrides != nil && overrides.OverrideVerkle != nil { config.VerkleTime = overrides.OverrideVerkle } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index b3dd51d7ea..38a6cac24d 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -248,6 +248,30 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{}, } +// PrecompiledContractsHaber contains the default set of pre-compiled Ethereum +// contracts used in the Haber release. +var PrecompiledContractsHaber = map[common.Address]PrecompiledContract{ + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, + + common.BytesToAddress([]byte{100}): &tmHeaderValidate{}, + common.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{}, + common.BytesToAddress([]byte{102}): &blsSignatureVerify{}, + common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidateHertz{}, + common.BytesToAddress([]byte{104}): &verifyDoubleSignEvidence{}, + common.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{}, + + common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, +} + // PrecompiledContractsP256Verify contains the precompiled Ethereum // contract specified in EIP-7212. This is exported for testing purposes. var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{ @@ -269,6 +293,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ } var ( + PrecompiledAddressesHaber []common.Address PrecompiledAddressesCancun []common.Address PrecompiledAddressesFeynman []common.Address PrecompiledAddressesHertz []common.Address @@ -320,11 +345,16 @@ func init() { for k := range PrecompiledContractsCancun { PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k) } + for k := range PrecompiledContractsHaber { + PrecompiledAddressesHaber = append(PrecompiledAddressesHaber, k) + } } // ActivePrecompiles returns the precompiles enabled with the current configuration. func ActivePrecompiles(rules params.Rules) []common.Address { switch { + case rules.IsHaber: + return PrecompiledAddressesHaber case rules.IsCancun: return PrecompiledAddressesCancun case rules.IsFeynman: diff --git a/eth/backend.go b/eth/backend.go index 860562eb4a..89ce49ad1d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -183,6 +183,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { chainConfig.CancunTime = config.OverrideCancun overrides.OverrideCancun = config.OverrideCancun } + if config.OverrideHaber != nil { + chainConfig.HaberTime = config.OverrideHaber + overrides.OverrideHaber = config.OverrideHaber + } if config.OverrideVerkle != nil { chainConfig.VerkleTime = config.OverrideVerkle overrides.OverrideVerkle = config.OverrideVerkle diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index daa92e8c8b..0b69b62219 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -191,6 +191,9 @@ type Config struct { // OverrideCancun (TODO: remove after the fork) OverrideCancun *uint64 `toml:",omitempty"` + // OverrideHaber (TODO: remove after the fork) + OverrideHaber *uint64 `toml:",omitempty"` + // OverrideVerkle (TODO: remove after the fork) OverrideVerkle *uint64 `toml:",omitempty"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 9f59076bcf..4ed328d632 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -71,6 +71,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCEVMTimeout time.Duration RPCTxFeeCap float64 OverrideCancun *uint64 `toml:",omitempty"` + OverrideHaber *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve uint64 } @@ -129,6 +130,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCEVMTimeout = c.RPCEVMTimeout enc.RPCTxFeeCap = c.RPCTxFeeCap enc.OverrideCancun = c.OverrideCancun + enc.OverrideHaber = c.OverrideHaber enc.OverrideVerkle = c.OverrideVerkle enc.BlobExtraReserve = c.BlobExtraReserve return &enc, nil @@ -191,6 +193,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCEVMTimeout *time.Duration RPCTxFeeCap *float64 OverrideCancun *uint64 `toml:",omitempty"` + OverrideHaber *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` BlobExtraReserve *uint64 } @@ -360,6 +363,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideCancun != nil { c.OverrideCancun = dec.OverrideCancun } + if dec.OverrideHaber != nil { + c.OverrideHaber = dec.OverrideHaber + } if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } diff --git a/params/config.go b/params/config.go index 1c0b8fb175..93425f953a 100644 --- a/params/config.go +++ b/params/config.go @@ -504,6 +504,7 @@ type ChainConfig struct { FeynmanTime *uint64 `json:"feynmanTime,omitempty"` // Feynman switch time (nil = no fork, 0 = already activated) FeynmanFixTime *uint64 `json:"feynmanFixTime,omitempty"` // FeynmanFix switch time (nil = no fork, 0 = already activated) CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun) + HaberTime *uint64 `json:"haberTime,omitempty"` // Haber switch time (nil = no fork, 0 = already on haber) PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague) VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle) @@ -913,6 +914,11 @@ func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { return c.IsLondon(num) && isTimestampForked(c.CancunTime, time) } +// IsHaber returns whether time is either equal to the Haber fork time or greater. +func (c *ChainConfig) IsHaber(num *big.Int, time uint64) bool { + return c.IsLondon(num) && isTimestampForked(c.HaberTime, time) +} + // IsPrague returns whether num is either equal to the Prague fork time or greater. func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool { return c.IsLondon(num) && isTimestampForked(c.PragueTime, time) @@ -1305,8 +1311,8 @@ type Rules struct { IsPlato bool IsHertz bool IsHertzfix bool - IsShanghai, IsKepler, IsFeynman, IsCancun, IsPrague bool - IsVerkle bool + IsShanghai, IsKepler, IsFeynman, IsCancun, IsHaber bool + IsPrague, IsVerkle bool } // Rules ensures c's ChainID is not nil. @@ -1341,6 +1347,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsKepler: c.IsKepler(num, timestamp), IsFeynman: c.IsFeynman(num, timestamp), IsCancun: c.IsCancun(num, timestamp), + IsHaber: c.IsHaber(num, timestamp), IsPrague: c.IsPrague(num, timestamp), IsVerkle: c.IsVerkle(num, timestamp), }