Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ActivePrecompiles #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/precompile/contract"
"github.com/ethereum/go-ethereum/precompile/modules"
"golang.org/x/crypto/ripemd160"
)

Expand Down Expand Up @@ -131,6 +130,14 @@ var (
PrecompiledAddressesIstanbul []common.Address
PrecompiledAddressesByzantium []common.Address
PrecompiledAddressesHomestead []common.Address

PrecompiledAddressesKava16 = []common.Address{
common.HexToAddress("0x16"),
}
PrecompiledAddressesKava17 = []common.Address{
common.HexToAddress("0x16"),
common.HexToAddress("0x17"),
}
)

func init() {
Expand Down Expand Up @@ -167,12 +174,15 @@ func ActivePrecompiles(rules params.Rules) (precompiles []common.Address) {
precompiles = PrecompiledAddressesHomestead
}

// TODO: Consider performance improvements here to prevent iteration & allocations on every call.
// NOTE: If using init to cache addresses, then some care should be taken to ensure all precompiles are
// registered before being cached here.
for _, precompile := range modules.RegisteredModules() {
precompiles = append(precompiles, precompile.Address)
// TODO: Consider performance improvements here
kavaPrecompiles := make([]common.Address, 0)
switch {
case rules.IsKava16:
kavaPrecompiles = PrecompiledAddressesKava16
case rules.IsKava17:
kavaPrecompiles = PrecompiledAddressesKava17
}
precompiles = append(precompiles, kavaPrecompiles...)

return precompiles
}
Expand Down
18 changes: 18 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var (
LondonBlock: big.NewInt(12_965_000),
ArrowGlacierBlock: big.NewInt(13_773_000),
GrayGlacierBlock: big.NewInt(15_050_000),
Kava16Block: big.NewInt(9_561_866),
Kava17Block: big.NewInt(10_000_000),
TerminalTotalDifficulty: MainnetTerminalTotalDifficulty, // 58_750_000_000_000_000_000_000
TerminalTotalDifficultyPassed: true,
ShanghaiTime: newUint64(1681338455),
Expand Down Expand Up @@ -307,6 +309,8 @@ type ChainConfig struct {
MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)
Kava16Block *big.Int `json:"kava16Block,omitempty"` // Kava16Block switch block (nil = no fork, 0 = already on kava16)
Kava17Block *big.Int `json:"kava17Block,omitempty"` // Kava17Block switch block (nil = no fork, 0 = already on kava17)
ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
GrayGlacierBlock *big.Int `json:"grayGlacierBlock,omitempty"` // Eip-5133 (bomb delay) switch block (nil = no fork, 0 = already activated)
MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter
Expand Down Expand Up @@ -543,6 +547,16 @@ func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
}

// IsKava16 returns whether num is either equal to the Kava16 fork block or greater.
func (c *ChainConfig) IsKava16(num *big.Int) bool {
return isBlockForked(c.Kava16Block, num)
}

// IsKava17 returns whether num is either equal to the Kava17 fork block or greater.
func (c *ChainConfig) IsKava17(num *big.Int) bool {
return isBlockForked(c.Kava17Block, 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 {
Expand Down Expand Up @@ -850,6 +864,8 @@ type Rules struct {
IsBerlin, IsLondon bool
IsMerge, IsShanghai, IsCancun, IsPrague bool
IsVerkle bool

IsKava16, IsKava17 bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -875,5 +891,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsCancun: c.IsCancun(num, timestamp),
IsPrague: c.IsPrague(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp),
IsKava16: c.IsKava16(num),
IsKava17: c.IsKava17(num),
}
}
Loading