From b5d9b12e70e9e17bad544794c5d3a816aeee1f94 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Wed, 18 Feb 2026 13:28:06 +0100 Subject: [PATCH] core/state/partial: fix storage value encoding in trie updates Trim leading zeros from storage values before passing to UpdateStorage, matching the upstream BALStateTransition behavior. UpdateStorage RLP-encodes the value internally, so passing untrimmed 32-byte values (e.g. [0,0,...,5]) produces different trie nodes than trimmed values ([5]), causing systematic state root mismatches on every BAL-processed block. BuildStateSet already correctly trimmed values for the pathdb layer; this fix aligns the trie update path. Co-Authored-By: Claude Opus 4.6 --- core/state/partial/state.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/state/partial/state.go b/core/state/partial/state.go index e5f29a889c..44c5b67393 100644 --- a/core/state/partial/state.go +++ b/core/state/partial/state.go @@ -444,8 +444,10 @@ func (s *PartialState) applyStorageChanges( return common.Hash{}, nil, err } } else { - // Update slot - if err := storageTrie.UpdateStorage(addr, slot.Bytes(), value.Bytes()); err != nil { + // Update slot — trim leading zeros to match how the EVM stores + // values (as big integers). UpdateStorage RLP-encodes the value, + // so [0,0,...,5] vs [5] produce different trie nodes. + if err := storageTrie.UpdateStorage(addr, slot.Bytes(), common.TrimLeftZeroes(value.Bytes())); err != nil { return common.Hash{}, nil, err } }