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 <noreply@anthropic.com>
This commit is contained in:
CPerezz 2026-02-18 13:28:06 +01:00
parent a15c05a406
commit b5d9b12e70
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -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
}
}