From a0ad1eecc0c6f329e3050a931d125fbddfc7dd65 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 2 Feb 2026 21:12:47 +0100 Subject: [PATCH] fix test by accepting a non-deployed contract --- core/chain_makers.go | 3 +++ core/state/database.go | 16 ++++++++-------- core/state_processor.go | 4 +--- core/transition_registry.go | 35 +++++++++++++++++++++++++++++++++++ eth/state_accessor.go | 6 +----- miner/worker.go | 5 +---- 6 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 core/transition_registry.go diff --git a/core/chain_makers.go b/core/chain_makers.go index 7ce86b14e9..76b634e57e 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -396,6 +396,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{}) ProcessParentBlockHash(b.header.ParentHash, evm) } + if config.IsVerkle(b.header.Number, b.header.Time) { + InitializeBinaryTransitionRegistry(statedb) + } // Execute any user modifications to the block if gen != nil { diff --git a/core/state/database.go b/core/state/database.go index fc134e8b5e..01ece45b8b 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -211,25 +211,24 @@ func LoadTransitionState(reader StateReader, root common.Hash) *overlay.Transiti endedBytes, err := reader.Storage(params.BinaryTransitionRegistryAddress, transitionEndedKey) if err != nil { - // Registry exists but can't read ended flag - treat as still in transition - endedBytes = common.Hash{} + return nil } ended := endedBytes != (common.Hash{}) currentAccountBytes, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressAddressKey) if err != nil { - panic(fmt.Errorf("error reading conversion account pointer: %w", err)) + return nil } currentAccount := common.BytesToAddress(currentAccountBytes[12:]) currentSlotHash, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressSlotKey) if err != nil { - panic(fmt.Errorf("error reading conversion slot pointer: %w", err)) + return nil } storageProcessedBytes, err := reader.Storage(params.BinaryTransitionRegistryAddress, conversionProgressStorageProcessed) if err != nil { - panic(fmt.Errorf("error reading conversion storage processing completion status: %w", err)) + return nil } storageProcessed := storageProcessedBytes[0] == 1 @@ -308,7 +307,8 @@ func (db *CachingDB) ReadersWithCacheStats(stateRoot common.Hash) (ReaderWithSta // OpenTrie opens the main account trie at a specific root hash. func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) { - reader, err := db.StateReader(root) + reader, err := db.triedb.StateReader(root) + flatReader := newFlatReader(reader) if err != nil { tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb) if err != nil { @@ -317,12 +317,12 @@ func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) { return tr, nil } - if isTransitionActive(reader) || db.triedb.IsVerkle() { + if isTransitionActive(flatReader) || db.triedb.IsVerkle() { bt, err := bintrie.NewBinaryTrie(root, db.triedb) if err != nil { return nil, fmt.Errorf("could not open the overlay tree: %w", err) } - ts := LoadTransitionState(reader, root) + ts := LoadTransitionState(flatReader, root) if !ts.InTransition() { // Transition complete, use BinaryTrie only return bt, nil diff --git a/core/state_processor.go b/core/state_processor.go index 5d76560825..558181ca5b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -94,9 +94,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg ProcessParentBlockHash(block.ParentHash(), evm) } if config.IsVerkle(header.Number, header.Time) { - statedb.SetCode(params.BinaryTransitionRegistryAddress, []byte{1, 2, 3}, tracing.CodeChangeUnspecified) - statedb.SetNonce(params.BinaryTransitionRegistryAddress, 1, tracing.NonceChangeUnspecified) - statedb.SetState(params.BinaryTransitionRegistryAddress, common.Hash{}, common.Hash{1}) + InitializeBinaryTransitionRegistry(statedb) } // Iterate over and process the individual transactions diff --git a/core/transition_registry.go b/core/transition_registry.go new file mode 100644 index 0000000000..83cb62e30a --- /dev/null +++ b/core/transition_registry.go @@ -0,0 +1,35 @@ +// Copyright 2026 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package core + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" + "github.com/ethereum/go-ethereum/params" +) + +// InitializeBinaryTransitionRegistry seeds the transition registry account used +// during the MPT->BinaryTrie transition. +func InitializeBinaryTransitionRegistry(statedb *state.StateDB) { + if statedb == nil { + return + } + statedb.SetCode(params.BinaryTransitionRegistryAddress, []byte{1, 2, 3}, tracing.CodeChangeUnspecified) + statedb.SetNonce(params.BinaryTransitionRegistryAddress, 1, tracing.NonceChangeUnspecified) + statedb.SetState(params.BinaryTransitionRegistryAddress, common.Hash{}, common.Hash{1}) +} diff --git a/eth/state_accessor.go b/eth/state_accessor.go index 2ff27581fe..385b38ed97 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -26,12 +26,10 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/triedb" ) @@ -254,9 +252,7 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block, core.ProcessParentBlockHash(block.ParentHash(), evm) } if eth.blockchain.Config().IsVerkle(block.Number(), block.Time()) { - statedb.SetCode(params.BinaryTransitionRegistryAddress, []byte{1, 2, 3}, tracing.CodeChangeUnspecified) - statedb.SetNonce(params.BinaryTransitionRegistryAddress, 1, tracing.NonceChangeUnspecified) - statedb.SetState(params.BinaryTransitionRegistryAddress, common.Hash{}, common.Hash{1}) + core.InitializeBinaryTransitionRegistry(statedb) } if txIndex == 0 && len(block.Transactions()) == 0 { return nil, context, statedb, release, nil diff --git a/miner/worker.go b/miner/worker.go index 4a7057c505..cb2e24d0cd 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -29,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/stateless" - "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -268,9 +267,7 @@ func (miner *Miner) prepareWork(genParams *generateParams, witness bool) (*envir core.ProcessParentBlockHash(header.ParentHash, env.evm) } if miner.chainConfig.IsVerkle(header.Number, header.Time) { - env.state.SetCode(params.BinaryTransitionRegistryAddress, []byte{1, 2, 3}, tracing.CodeChangeUnspecified) - env.state.SetNonce(params.BinaryTransitionRegistryAddress, 1, tracing.NonceChangeUnspecified) - env.state.SetState(params.BinaryTransitionRegistryAddress, common.Hash{}, common.Hash{1}) + core.InitializeBinaryTransitionRegistry(env.state) } return env, nil }