diff --git a/core/chain_makers.go b/core/chain_makers.go index 0ea272bc60..a98bfe868a 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -416,7 +416,15 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse Uncles: b.uncles, Withdrawals: b.withdrawals, } - + if !config.IsShanghai(b.header.Number, b.header.Time) { + if body.Withdrawals != nil { + panic("unexpected withdrawal before shanghai") + } + } else { + if body.Withdrawals == nil { + body.Withdrawals = make([]*types.Withdrawal, 0) + } + } // Finalize the state transition by applying operations such as withdrawals, // uncle rewards, and related processing. b.engine.Finalize(cm, b.header, statedb, &body) diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index 4fe690030d..5fb911fe90 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -417,7 +417,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, blockBody := &types.Body{ Transactions: txes, - Withdrawals: *block.BlockOverrides.Withdrawals, + Withdrawals: *block.BlockOverrides.Withdrawals, // Withdrawal is also sanitized as non-nil } chainHeadReader := &simChainHeadReader{ctx, sim.b} diff --git a/miner/worker.go b/miner/worker.go index f35406198c..7e0be2f852 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -190,7 +190,11 @@ func (miner *Miner) generateWork(ctx context.Context, genParam *generateParams, Transactions: work.txs, Withdrawals: genParam.withdrawals, } - if miner.chainConfig.IsShanghai(work.header.Number, work.header.Time) { + if !miner.chainConfig.IsShanghai(work.header.Number, work.header.Time) { + if body.Withdrawals != nil { + return &newPayloadResult{err: errors.New("unexpected withdrawals before shanghai")} + } + } else { if body.Withdrawals == nil { body.Withdrawals = make([]*types.Withdrawal, 0) }