Skip to content
Merged
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
4 changes: 4 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (e *GenesisMismatchError) Error() string {
type ChainOverrides struct {
Morph203Time *uint64
ViridianTime *uint64
EmeraldTime *uint64
}

// apply applies the chain overrides on the supplied chain config.
Expand All @@ -161,6 +162,9 @@ func (o *ChainOverrides) apply(cfg *params.ChainConfig) error {
if o.ViridianTime != nil {
cfg.ViridianTime = o.ViridianTime
}
if o.EmeraldTime != nil {
cfg.EmeraldTime = o.EmeraldTime
}
return cfg.CheckConfigForkOrder()
}

Expand Down
1 change: 1 addition & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestStateProcessorErrors(t *testing.T) {
CurieBlock: big.NewInt(0),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
Ethash: new(params.EthashConfig),
}
signer = types.LatestSigner(config)
Expand Down
16 changes: 15 additions & 1 deletion core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type sigCache struct {
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer {
var signer Signer
switch {
case config.IsEmerald(blockNumber, blockTime):
signer = NewEmeraldSigner(config.ChainID)
case config.IsViridian(blockNumber, blockTime):
signer = NewViridianSigner(config.ChainID)
case config.IsCurie(blockNumber):
Expand Down Expand Up @@ -71,6 +73,8 @@ func LatestSigner(config *params.ChainConfig) Signer {
var signer Signer
if config.ChainID != nil {
switch {
case config.EmeraldTime != nil:
signer = NewEmeraldSigner(config.ChainID)
case config.ViridianTime != nil:
signer = NewViridianSigner(config.ChainID)
case config.CurieBlock != nil:
Expand Down Expand Up @@ -98,7 +102,7 @@ func LatestSigner(config *params.ChainConfig) Signer {
func LatestSignerForChainID(chainID *big.Int) Signer {
var signer Signer
if chainID != nil {
signer = NewViridianSigner(chainID)
signer = NewEmeraldSigner(chainID)
} else {
signer = HomesteadSigner{}
}
Expand Down Expand Up @@ -224,6 +228,9 @@ func newModernSigner(chainID *big.Int, fork forks.Fork) Signer {
if fork >= forks.Viridian {
s.txtypes[SetCodeTxType] = struct{}{}
}
if fork >= forks.Emerald {
// Future Emerald-specific transaction types can be added here
}
return s
}

Expand Down Expand Up @@ -295,6 +302,13 @@ func NewViridianSigner(chainId *big.Int) Signer {
return newModernSigner(chainId, forks.Viridian)
}

// NewEmeraldSigner returns a signer that accepts
// - All Viridian transaction types
// - Future Emerald-specific transaction types
func NewEmeraldSigner(chainId *big.Int) Signer {
return newModernSigner(chainId, forks.Emerald)
}

// NewCurieSigner returns a signer that accepts
// - EIP-4844 blob transactions
// - EIP-1559 dynamic fee transactions
Expand Down
2 changes: 2 additions & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
if cfg.JumpTable[STOP] == nil {
var jt JumpTable
switch {
case evm.chainRules.IsEmerald:
jt = emeraldInstructionSet
case evm.chainRules.IsViridian:
jt = viridianInstructionSet
case evm.chainRules.IsCurie:
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 @@ -57,6 +57,7 @@ var (
shanghaiInstructionSet = newShanghaiInstructionSet()
curieInstructionSet = newCurieInstructionSet()
viridianInstructionSet = newViridianInstructionSet()
emeraldInstructionSet = newEmeraldInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
Expand All @@ -68,6 +69,12 @@ func newViridianInstructionSet() JumpTable {
return instructionSet
}

func newEmeraldInstructionSet() JumpTable {
instructionSet := newViridianInstructionSet()
// Emerald-specific changes can be added here in the future
return instructionSet
}

// newCurieInstructionSet returns the frontier, homestead, byzantium,
// contantinople, istanbul, petersburg, berlin, london, shanghai, and curie instructions.
func newCurieInstructionSet() JumpTable {
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func setDefaults(cfg *Config) {
CurieBlock: new(big.Int),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
}
}

Expand Down
1 change: 1 addition & 0 deletions eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
config.CurieBlock = londonBlock
config.Morph203Time = nil
config.ViridianTime = nil
config.EmeraldTime = nil
engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase()
genesis, err := gspec.Commit(db)
Expand Down
5 changes: 4 additions & 1 deletion genesis_l2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
"berlinBlock": 0,
"londonBlock": 0,
"terminalTotalDifficulty": 0,
"archimedesBlock": 0,
"archimedesBlock": 0,
"shanghaiBlock": 0,
"bernoulliBlock": 0,
"curieBlock": 0,
"morph203Time": 0,
"viridianTime": 0,
"emeraldTime": 0,
"morph": {
"useZktrie": true,
"feeVaultAddress": "0x0e87cd091e091562F25CB1cf4641065dA2C049F5"
Expand Down
19 changes: 17 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ var (
CurieBlock: big.NewInt(0),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -422,6 +423,7 @@ var (
CurieBlock: big.NewInt(0),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
Expand Down Expand Up @@ -454,6 +456,7 @@ var (
CurieBlock: big.NewInt(0),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -487,6 +490,7 @@ var (
CurieBlock: big.NewInt(0),
Morph203Time: new(uint64),
ViridianTime: new(uint64),
EmeraldTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -579,6 +583,7 @@ type ChainConfig struct {
CurieBlock *big.Int `json:"curieBlock,omitempty"` // Curie switch block (nil = no fork, 0 = already on curie)
Morph203Time *uint64 `json:"morph203Time,omitempty"` // Morph203Time switch time (nil = no fork, 0 = already on morph203)
ViridianTime *uint64 `json:"viridianTime,omitempty"` // ViridianTime switch time (nil = no fork, 0 = already on viridian)
EmeraldTime *uint64 `json:"emeraldTime,omitempty"` // EmeraldTime switch time (nil = no fork, 0 = already on emerald)

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
Expand Down Expand Up @@ -671,7 +676,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Morph203: %v, Viridian: %v, Engine: %v, Morph config: %v}",
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Morph203: %v, Viridian: %v, Emerald: %v, Engine: %v, Morph config: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -693,6 +698,7 @@ func (c *ChainConfig) String() string {
c.CurieBlock,
c.Morph203Time,
c.ViridianTime,
c.EmeraldTime,
engine,
c.Morph,
)
Expand Down Expand Up @@ -794,6 +800,10 @@ func (c *ChainConfig) IsViridian(num *big.Int, time uint64) bool {
return c.IsCurie(num) && isTimestampForked(c.ViridianTime, time)
}

func (c *ChainConfig) IsEmerald(num *big.Int, time uint64) bool {
return isTimestampForked(c.EmeraldTime, time)
}

// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
if c.TerminalTotalDifficulty == nil {
Expand Down Expand Up @@ -857,6 +867,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "curieBlock", block: c.CurieBlock, optional: true},
{name: "morph203Time", timestamp: c.Morph203Time, optional: true},
{name: "viridianTime", timestamp: c.ViridianTime, optional: true},
{name: "emeraldTime", timestamp: c.EmeraldTime, optional: true},
} {
if lastFork.name != "" {
switch {
Expand Down Expand Up @@ -963,6 +974,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int, headTi
if isForkTimestampIncompatible(c.ViridianTime, newcfg.ViridianTime, headTimestamp) {
return newTimestampCompatError("ViridianTime fork timestamp", c.ViridianTime, newcfg.ViridianTime)
}
if isForkTimestampIncompatible(c.EmeraldTime, newcfg.EmeraldTime, headTimestamp) {
return newTimestampCompatError("EmeraldTime fork timestamp", c.EmeraldTime, newcfg.EmeraldTime)
}
return nil
}

Expand Down Expand Up @@ -1109,7 +1123,7 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsArchimedes, IsShanghai bool
IsBernoulli, IsCurie, IsMorph203, IsViridian bool
IsBernoulli, IsCurie, IsMorph203, IsViridian, IsEmerald bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -1136,5 +1150,6 @@ func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
IsCurie: c.IsCurie(num),
IsMorph203: c.IsMorph203(time),
IsViridian: c.IsViridian(num, time),
IsEmerald: c.IsEmerald(num, time),
}
}
3 changes: 3 additions & 0 deletions params/forks/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
Curie
Morph203
Viridian
Emerald
)

// String implements fmt.Stringer.
Expand Down Expand Up @@ -71,4 +72,6 @@ var forkToString = map[Fork]string{
Bernoulli: "Bernoulli",
Curie: "Curie",
Morph203: "Morph203",
Viridian: "Viridian",
Emerald: "Emerald",
}