Skip to content

Commit cc27ba3

Browse files
committed
fix: apply hard forks during tracing
1 parent 2986a6c commit cc27ba3

File tree

8 files changed

+56
-55
lines changed

8 files changed

+56
-55
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
148148
chainConfig.DAOForkBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
149149
misc.ApplyDAOHardFork(statedb)
150150
}
151-
// Apply Curie hard fork
152-
if chainConfig.CurieBlock != nil && chainConfig.CurieBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
153-
misc.ApplyCurieHardFork(statedb)
154-
}
155-
// Apply Feynman hard fork
156-
if chainConfig.IsFeynmanTransitionBlock(pre.Env.Timestamp, pre.Env.ParentTimestamp) {
157-
misc.ApplyFeynmanHardFork(statedb)
158-
}
159-
// Apply GalileoV2 hard fork
160-
if chainConfig.IsGalileoV2TransitionBlock(pre.Env.Timestamp, pre.Env.ParentTimestamp) {
161-
misc.ApplyGalileoV2HardFork(statedb)
162-
}
151+
// Apply Scroll hard fork state transitions on state
152+
misc.ApplyForkStateTransitions(chainConfig, statedb, pre.Env.Number, pre.Env.Timestamp, pre.Env.ParentTimestamp)
163153
// Apply EIP-2935
164154
if pre.Env.BlockHashes != nil && chainConfig.IsFeynman(pre.Env.Timestamp) {
165155
var (

consensus/misc/forks.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package misc
1818

1919
import (
2020
"fmt"
21+
"math/big"
2122

2223
"github.com/scroll-tech/go-ethereum/common"
24+
"github.com/scroll-tech/go-ethereum/core/state"
2325
"github.com/scroll-tech/go-ethereum/core/types"
2426
"github.com/scroll-tech/go-ethereum/params"
2527
)
@@ -41,3 +43,20 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
4143
// All ok, return
4244
return nil
4345
}
46+
47+
// ApplyForkStateTransitions applies the special hard fork state transitions for
48+
// Curie, Feynman, or GalileoV2, if the given block is the upgrade block.
49+
func ApplyForkStateTransitions(config *params.ChainConfig, statedb *state.StateDB, blockNumber, blockTimestamp, parentTimestamp uint64) {
50+
// Apply Curie hard fork
51+
if config.CurieBlock != nil && config.CurieBlock.Cmp(new(big.Int).SetUint64(blockNumber)) == 0 {
52+
ApplyCurieHardFork(statedb)
53+
}
54+
// Apply Feynman hard fork
55+
if config.IsFeynmanTransitionBlock(blockTimestamp, parentTimestamp) {
56+
ApplyFeynmanHardFork(statedb)
57+
}
58+
// Apply GalileoV2 hard fork
59+
if config.IsGalileoV2TransitionBlock(blockTimestamp, parentTimestamp) {
60+
ApplyGalileoV2HardFork(statedb)
61+
}
62+
}

core/chain_makers.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
246246
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
247247
misc.ApplyDAOHardFork(statedb)
248248
}
249-
if config.CurieBlock != nil && config.CurieBlock.Cmp(b.header.Number) == 0 {
250-
misc.ApplyCurieHardFork(statedb)
251-
}
252-
if config.IsFeynmanTransitionBlock(b.Time(), parent.Time()) {
253-
misc.ApplyFeynmanHardFork(statedb)
254-
}
255-
if config.IsGalileoV2TransitionBlock(b.Time(), parent.Time()) {
256-
misc.ApplyGalileoV2HardFork(statedb)
257-
}
249+
// Apply Scroll hard fork state transitions on state
250+
misc.ApplyForkStateTransitions(config, statedb, b.header.Number.Uint64(), b.header.Time, parent.Time())
258251
// Execute any user modifications to the block
259252
if gen != nil {
260253
gen(i, b)

core/state_processor.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,13 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8888
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
8989
misc.ApplyDAOHardFork(statedb)
9090
}
91-
// Apply Curie hard fork
92-
if p.config.CurieBlock != nil && p.config.CurieBlock.Cmp(block.Number()) == 0 {
93-
misc.ApplyCurieHardFork(statedb)
94-
}
95-
// Apply Feynman hard fork
91+
// Apply Scroll hard fork state transitions on state
9692
parent := p.bc.GetHeaderByHash(block.ParentHash())
97-
if p.config.IsFeynmanTransitionBlock(block.Time(), parent.Time) {
98-
misc.ApplyFeynmanHardFork(statedb)
99-
}
100-
// Apply GalileoV2 hard fork
101-
if p.config.IsGalileoV2TransitionBlock(block.Time(), parent.Time) {
102-
misc.ApplyGalileoV2HardFork(statedb)
103-
}
93+
misc.ApplyForkStateTransitions(p.config, statedb, blockNumber.Uint64(), blockTime, parent.Time)
94+
// Apply EIP-2935
10495
blockContext := NewEVMBlockContext(header, p.bc, p.config, nil)
10596
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
10697
processorBlockTransactionGauge.Update(int64(block.Transactions().Len()))
107-
// Apply EIP-2935
10898
if p.config.IsFeynman(block.Time()) {
10999
ProcessParentBlockHash(block.ParentHash(), vmenv, statedb)
110100
}

eth/state_accessor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/scroll-tech/go-ethereum/common"
25+
"github.com/scroll-tech/go-ethereum/consensus/misc"
2526
"github.com/scroll-tech/go-ethereum/core"
2627
"github.com/scroll-tech/go-ethereum/core/state"
2728
"github.com/scroll-tech/go-ethereum/core/types"
@@ -176,6 +177,8 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
176177
if err != nil {
177178
return nil, vm.BlockContext{}, nil, err
178179
}
180+
// Apply Scroll hard fork state transitions on state
181+
misc.ApplyForkStateTransitions(eth.blockchain.Config(), statedb, block.NumberU64(), block.Time(), parent.Time())
179182
// If feynman hardfork, insert parent block hash in the state as per EIP-2935.
180183
if eth.blockchain.Config().IsFeynman(block.Time()) {
181184
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, eth.blockchain.Config(), nil)

eth/tracers/api.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/scroll-tech/go-ethereum/common"
3333
"github.com/scroll-tech/go-ethereum/common/hexutil"
3434
"github.com/scroll-tech/go-ethereum/consensus"
35+
"github.com/scroll-tech/go-ethereum/consensus/misc"
3536
"github.com/scroll-tech/go-ethereum/core"
3637
"github.com/scroll-tech/go-ethereum/core/rawdb"
3738
"github.com/scroll-tech/go-ethereum/core/state"
@@ -202,10 +203,11 @@ type txTraceResult struct {
202203
// blockTraceTask represents a single block trace task when an entire chain is
203204
// being traced.
204205
type blockTraceTask struct {
205-
statedb *state.StateDB // Intermediate state prepped for tracing
206-
block *types.Block // Block to trace the transactions from
207-
rootref common.Hash // Trie root reference held for this task
208-
results []*txTraceResult // Trace results procudes by the task
206+
statedb *state.StateDB // Intermediate state prepped for tracing
207+
block *types.Block // Block to trace the transactions from
208+
parentBlock *types.Block // Block to trace the transactions from
209+
rootref common.Hash // Trie root reference held for this task
210+
results []*txTraceResult // Trace results procudes by the task
209211
}
210212

211213
// blockTraceResult represets the results of tracing a single block when an entire
@@ -277,11 +279,16 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
277279
for task := range tasks {
278280
signer := types.MakeSigner(api.backend.ChainConfig(), task.block.Number(), task.block.Time())
279281
blockCtx := core.NewEVMBlockContext(task.block.Header(), api.chainContext(localctx), api.backend.ChainConfig(), nil)
282+
283+
// Apply Scroll hard fork state transitions on state
284+
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), task.statedb, task.block.NumberU64(), task.block.Time(), task.parentBlock.Time())
285+
280286
// EIP-2935: Insert parent hash in history contract.
281287
if api.backend.ChainConfig().IsFeynman(task.block.Time()) {
282288
evm := vm.NewEVM(blockCtx, vm.TxContext{}, task.statedb, api.backend.ChainConfig(), vm.Config{})
283289
core.ProcessParentBlockHash(task.block.ParentHash(), evm, task.statedb)
284290
}
291+
285292
// Trace all the transactions contained within
286293
for i, tx := range task.block.Transactions() {
287294
msg, _ := tx.AsMessage(signer, task.block.BaseFee())
@@ -410,7 +417,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
410417
// Send the block over to the concurrent tracers (if not in the fast-forward phase)
411418
txs := next.Transactions()
412419
select {
413-
case tasks <- &blockTraceTask{statedb: statedb.Copy(), block: next, rootref: block.Root(), results: make([]*txTraceResult, len(txs))}:
420+
case tasks <- &blockTraceTask{statedb: statedb.Copy(), block: next, parentBlock: block, rootref: block.Root(), results: make([]*txTraceResult, len(txs))}:
414421
case <-notifier.Closed():
415422
return
416423
}
@@ -544,6 +551,10 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
544551
vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), api.backend.ChainConfig(), nil)
545552
deleteEmptyObjects = chainConfig.IsEIP158(block.Number())
546553
)
554+
555+
// Apply Scroll hard fork state transitions on state
556+
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())
557+
547558
// EIP-2935: Insert parent hash in history contract.
548559
if api.backend.ChainConfig().IsFeynman(block.Time()) {
549560
vmenv := vm.NewEVM(vmctx, vm.TxContext{}, statedb, chainConfig, vm.Config{})
@@ -624,11 +635,16 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
624635
threads = len(txs)
625636
}
626637
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), api.backend.ChainConfig(), nil)
638+
639+
// Apply Scroll hard fork state transitions on state
640+
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())
641+
627642
// EIP-2935: Insert parent hash in history contract.
628643
if api.backend.ChainConfig().IsFeynman(block.Time()) {
629644
evm := vm.NewEVM(blockCtx, vm.TxContext{}, statedb, api.backend.ChainConfig(), vm.Config{})
630645
core.ProcessParentBlockHash(block.ParentHash(), evm, statedb)
631646
}
647+
632648
blockHash := block.Hash()
633649
blockNumber := block.NumberU64()
634650
for th := 0; th < threads; th++ {
@@ -764,6 +780,9 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
764780
}
765781
}
766782

783+
// Apply Scroll hard fork state transitions on state
784+
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())
785+
767786
// EIP-2935: Insert parent hash in history contract.
768787
if api.backend.ChainConfig().IsFeynman(block.Time()) {
769788
evm := vm.NewEVM(vmctx, vm.TxContext{}, statedb, api.backend.ChainConfig(), vm.Config{})

miner/scroll_worker.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -630,21 +630,8 @@ func (w *worker) tryCommitNewWork(now time.Time, parentHash common.Hash, reorgin
630630

631631
// handleForks
632632
func (w *worker) handleForks(parent *types.Block) (bool, error) {
633-
// Apply Curie predeployed contract update
634-
if w.chainConfig.CurieBlock != nil && w.chainConfig.CurieBlock.Cmp(w.current.header.Number) == 0 {
635-
misc.ApplyCurieHardFork(w.current.state)
636-
return true, nil
637-
}
638-
639-
// Apply Feynman hard fork
640-
if w.chainConfig.IsFeynmanTransitionBlock(w.current.header.Time, parent.Time()) {
641-
misc.ApplyFeynmanHardFork(w.current.state)
642-
}
643-
644-
// Apply GalileoV2 hard fork
645-
if w.chainConfig.IsGalileoV2TransitionBlock(w.current.header.Time, parent.Time()) {
646-
misc.ApplyGalileoV2HardFork(w.current.state)
647-
}
633+
// Apply Scroll hard fork state transitions on state
634+
misc.ApplyForkStateTransitions(w.chainConfig, w.current.state, w.current.header.Number.Uint64(), w.current.header.Time, parent.Time())
648635

649636
// Apply EIP-2935
650637
if w.chainConfig.IsFeynman(w.current.header.Time) {

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 9 // Minor version component of the current release
27-
VersionPatch = 18 // Patch version component of the current release
27+
VersionPatch = 19 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)