Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 2 additions & 12 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
chainConfig.DAOForkBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
misc.ApplyDAOHardFork(statedb)
}
// Apply Curie hard fork
if chainConfig.CurieBlock != nil && chainConfig.CurieBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
misc.ApplyCurieHardFork(statedb)
}
// Apply Feynman hard fork
if chainConfig.IsFeynmanTransitionBlock(pre.Env.Timestamp, pre.Env.ParentTimestamp) {
misc.ApplyFeynmanHardFork(statedb)
}
// Apply GalileoV2 hard fork
if chainConfig.IsGalileoV2TransitionBlock(pre.Env.Timestamp, pre.Env.ParentTimestamp) {
misc.ApplyGalileoV2HardFork(statedb)
}
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(chainConfig, statedb, pre.Env.Number, pre.Env.Timestamp, pre.Env.ParentTimestamp)
// Apply EIP-2935
if pre.Env.BlockHashes != nil && chainConfig.IsFeynman(pre.Env.Timestamp) {
var (
Expand Down
19 changes: 19 additions & 0 deletions consensus/misc/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package misc

import (
"fmt"
"math/big"

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/core/state"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/params"
)
Expand All @@ -41,3 +43,20 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
// All ok, return
return nil
}

// ApplyForkStateTransitions applies the special hard fork state transitions for
// Curie, Feynman, or GalileoV2, if the given block is the upgrade block.
func ApplyForkStateTransitions(config *params.ChainConfig, statedb *state.StateDB, blockNumber, blockTimestamp, parentTimestamp uint64) {
// Apply Curie hard fork
if config.CurieBlock != nil && config.CurieBlock.Cmp(new(big.Int).SetUint64(blockNumber)) == 0 {
ApplyCurieHardFork(statedb)
}
// Apply Feynman hard fork
if config.IsFeynmanTransitionBlock(blockTimestamp, parentTimestamp) {
ApplyFeynmanHardFork(statedb)
}
// Apply GalileoV2 hard fork
if config.IsGalileoV2TransitionBlock(blockTimestamp, parentTimestamp) {
ApplyGalileoV2HardFork(statedb)
}
}
11 changes: 2 additions & 9 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
misc.ApplyDAOHardFork(statedb)
}
if config.CurieBlock != nil && config.CurieBlock.Cmp(b.header.Number) == 0 {
misc.ApplyCurieHardFork(statedb)
}
if config.IsFeynmanTransitionBlock(b.Time(), parent.Time()) {
misc.ApplyFeynmanHardFork(statedb)
}
if config.IsGalileoV2TransitionBlock(b.Time(), parent.Time()) {
misc.ApplyGalileoV2HardFork(statedb)
}
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(config, statedb, b.header.Number.Uint64(), b.header.Time, parent.Time())
// Execute any user modifications to the block
if gen != nil {
gen(i, b)
Expand Down
16 changes: 3 additions & 13 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,13 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(statedb)
}
// Apply Curie hard fork
if p.config.CurieBlock != nil && p.config.CurieBlock.Cmp(block.Number()) == 0 {
misc.ApplyCurieHardFork(statedb)
}
// Apply Feynman hard fork
// Apply Scroll hard fork state transitions on state
parent := p.bc.GetHeaderByHash(block.ParentHash())
if p.config.IsFeynmanTransitionBlock(block.Time(), parent.Time) {
misc.ApplyFeynmanHardFork(statedb)
}
// Apply GalileoV2 hard fork
if p.config.IsGalileoV2TransitionBlock(block.Time(), parent.Time) {
misc.ApplyGalileoV2HardFork(statedb)
}
misc.ApplyForkStateTransitions(p.config, statedb, blockNumber.Uint64(), blockTime, parent.Time)
// Apply EIP-2935
blockContext := NewEVMBlockContext(header, p.bc, p.config, nil)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
processorBlockTransactionGauge.Update(int64(block.Transactions().Len()))
// Apply EIP-2935
if p.config.IsFeynman(block.Time()) {
ProcessParentBlockHash(block.ParentHash(), vmenv, statedb)
}
Expand Down
3 changes: 3 additions & 0 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/consensus/misc"
"github.com/scroll-tech/go-ethereum/core"
"github.com/scroll-tech/go-ethereum/core/state"
"github.com/scroll-tech/go-ethereum/core/types"
Expand Down Expand Up @@ -176,6 +177,8 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
if err != nil {
return nil, vm.BlockContext{}, nil, err
}
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(eth.blockchain.Config(), statedb, block.NumberU64(), block.Time(), parent.Time())
// If feynman hardfork, insert parent block hash in the state as per EIP-2935.
if eth.blockchain.Config().IsFeynman(block.Time()) {
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, eth.blockchain.Config(), nil)
Expand Down
29 changes: 24 additions & 5 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/consensus/misc"
"github.com/scroll-tech/go-ethereum/core"
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/state"
Expand Down Expand Up @@ -202,10 +203,11 @@ type txTraceResult struct {
// blockTraceTask represents a single block trace task when an entire chain is
// being traced.
type blockTraceTask struct {
statedb *state.StateDB // Intermediate state prepped for tracing
block *types.Block // Block to trace the transactions from
rootref common.Hash // Trie root reference held for this task
results []*txTraceResult // Trace results procudes by the task
statedb *state.StateDB // Intermediate state prepped for tracing
block *types.Block // Block to trace the transactions from
parentBlock *types.Block // Block to trace the transactions from
rootref common.Hash // Trie root reference held for this task
results []*txTraceResult // Trace results procudes by the task
}

// blockTraceResult represets the results of tracing a single block when an entire
Expand Down Expand Up @@ -277,11 +279,16 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
for task := range tasks {
signer := types.MakeSigner(api.backend.ChainConfig(), task.block.Number(), task.block.Time())
blockCtx := core.NewEVMBlockContext(task.block.Header(), api.chainContext(localctx), api.backend.ChainConfig(), nil)

// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), task.statedb, task.block.NumberU64(), task.block.Time(), task.parentBlock.Time())

// EIP-2935: Insert parent hash in history contract.
if api.backend.ChainConfig().IsFeynman(task.block.Time()) {
evm := vm.NewEVM(blockCtx, vm.TxContext{}, task.statedb, api.backend.ChainConfig(), vm.Config{})
core.ProcessParentBlockHash(task.block.ParentHash(), evm, task.statedb)
}

// Trace all the transactions contained within
for i, tx := range task.block.Transactions() {
msg, _ := tx.AsMessage(signer, task.block.BaseFee())
Expand Down Expand Up @@ -410,7 +417,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
// Send the block over to the concurrent tracers (if not in the fast-forward phase)
txs := next.Transactions()
select {
case tasks <- &blockTraceTask{statedb: statedb.Copy(), block: next, rootref: block.Root(), results: make([]*txTraceResult, len(txs))}:
case tasks <- &blockTraceTask{statedb: statedb.Copy(), block: next, parentBlock: block, rootref: block.Root(), results: make([]*txTraceResult, len(txs))}:
case <-notifier.Closed():
return
}
Expand Down Expand Up @@ -544,6 +551,10 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), api.backend.ChainConfig(), nil)
deleteEmptyObjects = chainConfig.IsEIP158(block.Number())
)

// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())

// EIP-2935: Insert parent hash in history contract.
if api.backend.ChainConfig().IsFeynman(block.Time()) {
vmenv := vm.NewEVM(vmctx, vm.TxContext{}, statedb, chainConfig, vm.Config{})
Expand Down Expand Up @@ -624,11 +635,16 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
threads = len(txs)
}
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), api.backend.ChainConfig(), nil)

// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())

// EIP-2935: Insert parent hash in history contract.
if api.backend.ChainConfig().IsFeynman(block.Time()) {
evm := vm.NewEVM(blockCtx, vm.TxContext{}, statedb, api.backend.ChainConfig(), vm.Config{})
core.ProcessParentBlockHash(block.ParentHash(), evm, statedb)
}

blockHash := block.Hash()
blockNumber := block.NumberU64()
for th := 0; th < threads; th++ {
Expand Down Expand Up @@ -764,6 +780,9 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
}
}

// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())

// EIP-2935: Insert parent hash in history contract.
if api.backend.ChainConfig().IsFeynman(block.Time()) {
evm := vm.NewEVM(vmctx, vm.TxContext{}, statedb, api.backend.ChainConfig(), vm.Config{})
Expand Down
17 changes: 2 additions & 15 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,21 +630,8 @@ func (w *worker) tryCommitNewWork(now time.Time, parentHash common.Hash, reorgin

// handleForks
func (w *worker) handleForks(parent *types.Block) (bool, error) {
// Apply Curie predeployed contract update
if w.chainConfig.CurieBlock != nil && w.chainConfig.CurieBlock.Cmp(w.current.header.Number) == 0 {
misc.ApplyCurieHardFork(w.current.state)
return true, nil
}

// Apply Feynman hard fork
if w.chainConfig.IsFeynmanTransitionBlock(w.current.header.Time, parent.Time()) {
misc.ApplyFeynmanHardFork(w.current.state)
}

// Apply GalileoV2 hard fork
if w.chainConfig.IsGalileoV2TransitionBlock(w.current.header.Time, parent.Time()) {
misc.ApplyGalileoV2HardFork(w.current.state)
}
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(w.chainConfig, w.current.state, w.current.header.Number.Uint64(), w.current.header.Time, parent.Time())

// Apply EIP-2935
if w.chainConfig.IsFeynman(w.current.header.Time) {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 9 // Minor version component of the current release
VersionPatch = 18 // Patch version component of the current release
VersionPatch = 19 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
Loading