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
16 changes: 3 additions & 13 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,9 @@ 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 EIP-2935
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(chainConfig, statedb, pre.Env.Number, pre.Env.Timestamp, pre.Env.ParentTimestamp)
// Apply EIP-2935: Insert parent hash in history contract.
if pre.Env.BlockHashes != nil && chainConfig.IsFeynman(pre.Env.Timestamp) {
var (
prevNumber = pre.Env.Number - 1
Expand Down
4 changes: 2 additions & 2 deletions consensus/misc/curie.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
)

// ApplyCurieHardFork modifies the state database according to the Curie hard-fork rules,
// applyCurieHardFork modifies the state database according to the Curie hard-fork rules,
// updating the bytecode and storage of the L1GasPriceOracle contract.
func ApplyCurieHardFork(statedb *state.StateDB) {
func applyCurieHardFork(statedb *state.StateDB) {
log.Info("Applying Curie hard fork")

// update contract byte code
Expand Down
4 changes: 2 additions & 2 deletions consensus/misc/feynman.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
)

// ApplyFeynmanHardFork modifies the state database according to the Feynman hard-fork rules,
// applyFeynmanHardFork modifies the state database according to the Feynman hard-fork rules,
// updating the bytecode and storage of the L1GasPriceOracle contract.
func ApplyFeynmanHardFork(statedb *state.StateDB) {
func applyFeynmanHardFork(statedb *state.StateDB) {
log.Info("Applying Feynman hard fork")

// update contract byte code
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)
}
}
4 changes: 2 additions & 2 deletions consensus/misc/galileoV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
)

// ApplyGalileoV2HardFork modifies the state database according to the GalileoV2 hard-fork rules,
// applyGalileoV2HardFork modifies the state database according to the GalileoV2 hard-fork rules,
// updating the bytecode and storage of the L1GasPriceOracle contract.
func ApplyGalileoV2HardFork(statedb *state.StateDB) {
func applyGalileoV2HardFork(statedb *state.StateDB) {
log.Info("Applying GalileoV2 hard fork")

// update contract byte code
Expand Down
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.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: Insert parent hash in history contract.
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
5 changes: 4 additions & 1 deletion 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,7 +177,9 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
if err != nil {
return nil, vm.BlockContext{}, nil, err
}
// If feynman hardfork, insert parent block hash in the state as per EIP-2935.
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(eth.blockchain.Config(), statedb, block.NumberU64(), block.Time(), parent.Time())
// Apply EIP-2935: Insert parent hash in history contract.
if eth.blockchain.Config().IsFeynman(block.Time()) {
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, eth.blockchain.Config(), nil)
vmenv := vm.NewEVM(context, vm.TxContext{}, statedb, eth.blockchain.Config(), vm.Config{})
Expand Down
37 changes: 28 additions & 9 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 // Parent block of the block to trace
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)
// EIP-2935: Insert parent hash in history contract.

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

// Apply 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,7 +551,11 @@ 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())
)
// EIP-2935: Insert parent hash in history contract.

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

// Apply 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{})
core.ProcessParentBlockHash(block.ParentHash(), vmenv, statedb)
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)
// EIP-2935: Insert parent hash in history contract.

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

// Apply 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,7 +780,10 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
}
}

// EIP-2935: Insert parent hash in history contract.
// Apply Scroll hard fork state transitions on state
misc.ApplyForkStateTransitions(api.backend.ChainConfig(), statedb, block.NumberU64(), block.Time(), parent.Time())

// Apply 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{})
core.ProcessParentBlockHash(block.ParentHash(), evm, statedb)
Expand Down
19 changes: 3 additions & 16 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,23 +630,10 @@ 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
// Apply EIP-2935: Insert parent hash in history contract.
if w.chainConfig.IsFeynman(w.current.header.Time) {
context := core.NewEVMBlockContext(w.current.header, w.chain, w.chainConfig, nil)
vmenv := vm.NewEVM(context, vm.TxContext{}, w.current.state, w.chainConfig, vm.Config{})
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