Skip to content

Commit b373d79

Browse files
yazzaouigballet
andauthored
core/state: state copy bugfixes with Verkle Trees (#31696)
This change addresses critical issues in the state object duplication process specific to Verkle trie implementations. Without these modifications, updates to state objects fail to propagate correctly through the trie structure after a statedb copy operation, leading to inaccuracies in the computation of the state root hash. --------- Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
1 parent ff54ca0 commit b373d79

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

core/state/database.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ func mustCopyTrie(t Trie) Trie {
302302
return t.Copy()
303303
case *trie.VerkleTrie:
304304
return t.Copy()
305+
case *trie.TransitionTrie:
306+
return t.Copy()
305307
default:
306308
panic(fmt.Errorf("unknown trie type %T", t))
307309
}

core/state/state_object.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/crypto"
2929
"github.com/ethereum/go-ethereum/log"
3030
"github.com/ethereum/go-ethereum/rlp"
31+
"github.com/ethereum/go-ethereum/trie"
3132
"github.com/ethereum/go-ethereum/trie/trienode"
3233
"github.com/holiman/uint256"
3334
)
@@ -494,8 +495,20 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
494495
selfDestructed: s.selfDestructed,
495496
newContract: s.newContract,
496497
}
497-
if s.trie != nil {
498+
499+
switch s.trie.(type) {
500+
case *trie.VerkleTrie:
501+
// Verkle uses only one tree, and the copy has already been
502+
// made in mustCopyTrie.
503+
obj.trie = db.trie
504+
case *trie.TransitionTrie:
505+
// Same thing for the transition tree, since the MPT is
506+
// read-only.
507+
obj.trie = db.trie
508+
case *trie.StateTrie:
498509
obj.trie = mustCopyTrie(s.trie)
510+
case nil:
511+
// do nothing
499512
}
500513
return obj
501514
}

trie/transition.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
211211
func (t *TransitionTrie) Copy() *TransitionTrie {
212212
return &TransitionTrie{
213213
overlay: t.overlay.Copy(),
214-
base: t.base.Copy(),
214+
// base in immutable, so there is no need to copy it
215+
base: t.base,
215216
storage: t.storage,
216217
}
217218
}

0 commit comments

Comments
 (0)