core/state/partial: only write modified accounts to trie

Match upstream BALStateTransition behavior: only call UpdateAccount for
accounts that were actually modified (balance, nonce, code, or storage
changes). Previously, all accounts in the BAL (including read-only ones)
were written back to the trie, which could cause root mismatches if the
re-encoded RLP differed from the original encoding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
CPerezz 2026-02-18 15:16:16 +01:00
parent da476a8eca
commit fc2d55dd58
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -287,6 +287,11 @@ func (s *PartialState) ApplyBALAndComputeRoot(parentRoot common.Hash, expectedRo
continue
}
// Only write accounts that were actually modified to the trie.
// Upstream BALStateTransition only processes ModifiedAccounts().
if !state.modified {
continue
}
if err := tr.UpdateAccount(state.addr, state.account, 0); err != nil {
return common.Hash{}, 0, fmt.Errorf("failed to update account %s: %w",
state.addr.Hex(), err)