Skip to content

Commit

Permalink
Add Cepheus hardfork
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys Semerenko committed Nov 11, 2024
1 parent c8807fb commit 20688f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
// If jump table was not initialised we set the default one.
var table *JumpTable
switch {
case evm.chainRules.IsCepheus:
table = &cepheusInstructionSet
case evm.chainRules.IsShanghai:
table = &shanghaiInstructionSet
case evm.chainRules.IsMerge:
Expand Down
7 changes: 7 additions & 0 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
londonInstructionSet = newLondonInstructionSet()
mergeInstructionSet = newMergeInstructionSet()
shanghaiInstructionSet = newShanghaiInstructionSet()
cepheusInstructionSet = newCepheusInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
Expand All @@ -79,6 +80,12 @@ func validate(jt JumpTable) JumpTable {
return jt
}

func newCepheusInstructionSet() JumpTable {
instructionSet := newIstanbulInstructionSet()
enable3855(&instructionSet) // PUSH0 instruction
return validate(instructionSet)
}

func newShanghaiInstructionSet() JumpTable {
instructionSet := newMergeInstructionSet()
enable3855(&instructionSet) // PUSH0 instruction
Expand Down
2 changes: 2 additions & 0 deletions core/vm/jump_table_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func LookupInstructionSet(rules params.Rules) (JumpTable, error) {
return newTangerineWhistleInstructionSet(), nil
case rules.IsHomestead:
return newHomesteadInstructionSet(), nil
case rules.IsCepheus:
return newCepheusInstructionSet(), nil
}
return newFrontierInstructionSet(), nil
}
Expand Down
18 changes: 18 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ var (
LondonBlock: nil,
ArrowGlacierBlock: nil,
CassiopeiaBlock: big.NewInt(12571200),
CepheusBlock: nil,
TerminalTotalDifficulty: nil,
TerminalTotalDifficultyPassed: false,
Clique: &CliqueConfig{
Expand Down Expand Up @@ -285,6 +286,8 @@ var (
BerlinBlock: nil,
LondonBlock: nil,
ArrowGlacierBlock: nil,
CassiopeiaBlock: nil,
CepheusBlock: nil,
TerminalTotalDifficulty: nil,
TerminalTotalDifficultyPassed: false,
Clique: &CliqueConfig{
Expand Down Expand Up @@ -503,6 +506,7 @@ type ChainConfig struct {
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
CassiopeiaBlock *big.Int `json:"cassiopeiaBlock,omitempty"`
CepheusBlock *big.Int `json:"cepheusBlock,omitempty"` // Cepheus switch block (nil = no fork, 0 = already activated)

// Fork scheduling was switched from blocks to timestamps here

Expand Down Expand Up @@ -618,6 +622,9 @@ func (c *ChainConfig) Description() string {
if c.GrayGlacierBlock != nil {
banner += fmt.Sprintf(" - Gray Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock)
}
if c.CepheusBlock != nil {
banner += fmt.Sprintf(" - Cepheus: #%-8v\n", c.CepheusBlock)
}
banner += "\n"

// Add a special section for the merge as it's non-obvious
Expand Down Expand Up @@ -744,6 +751,11 @@ func (c *ChainConfig) IsPrague(time uint64) bool {
return isTimestampForked(c.PragueTime, time)
}

// IsCepheus returns whether num is either equal to the Cepheus fork block or greater.
func (c *ChainConfig) IsCepheus(num *big.Int) bool {
return isBlockForked(c.CepheusBlock, 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 @@ -790,6 +802,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "petersburgBlock", block: c.PetersburgBlock},
{name: "istanbulBlock", block: c.IstanbulBlock},
{name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true},
{name: "cepheusBlock", block: c.CepheusBlock},
{name: "berlinBlock", block: c.BerlinBlock},
{name: "londonBlock", block: c.LondonBlock},
{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
Expand Down Expand Up @@ -901,6 +914,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkTimestampIncompatible(c.PragueTime, newcfg.PragueTime, headTimestamp) {
return newTimestampCompatError("Prague fork timestamp", c.PragueTime, newcfg.PragueTime)
}
if isForkBlockIncompatible(c.CepheusBlock, newcfg.CepheusBlock, headNumber) {
return newBlockCompatError("Cepheus fork block", c.CepheusBlock, newcfg.CepheusBlock)
}
return nil
}

Expand Down Expand Up @@ -1046,6 +1062,7 @@ type Rules struct {
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon bool
IsMerge, IsShanghai, IsCancun, IsPrague bool
IsCepheus bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -1070,5 +1087,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsShanghai: c.IsShanghai(timestamp),
IsCancun: c.IsCancun(timestamp),
IsPrague: c.IsPrague(timestamp),
IsCepheus: c.IsCepheus(num),
}
}

0 comments on commit 20688f5

Please sign in to comment.