[SharovBot] fix: revert TrieContext.Branch unsafe borrow causing RPC proof/trace corruption#21630
Merged
Merged
Conversation
…proof/trace corruption Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression introduced by #21524 where TrieContext.Branch() returned a borrowed slice that could be mutated/reused before callers finished consuming it, leading to incorrect/malformed RPC outputs (e.g., eth_getProof, eth_simulateV1, debug_traceBlockByNumber). The fix restores defensive copying at the TrieContext boundary and updates the API contract + unit test accordingly.
Changes:
- Restore
common.Copy(enc)inexecution/commitment/commitmentdb/commitment_context.go:TrieContext.Branch()to ensure returned branch bytes are independent per call. - Update
PatriciaContextinterface documentation to reflect “caller-owned copy” semantics. - Rename/update the unit test to assert that mutating the underlying storage does not affect previously returned branch data.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
execution/commitment/commitmentdb/commitment_context.go |
Restores copying in TrieContext.Branch() to prevent aliasing and downstream data corruption. |
execution/commitment/commitmentdb/commitment_context_test.go |
Updates the test to validate that Branch() returns an independent slice (copy), and renames it accordingly. |
execution/commitment/commitment.go |
Updates PatriciaContext.Branch() documentation to match the restored “owned copy” contract. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…vert The initial revert paraphrased the PatriciaContext.Branch and TrieContext.Branch comments and trimmed one assertion from the unit test. Restore the exact pre-#21524 text and the full two-direction Test_TrieContext_BranchCopiesData, so the PR's net diff is precisely the inverse of #21524 and nothing else.
yperbasis
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[SharovBot]
Problem
PR #21524 removed
common.CopyfromTrieContext.Branch(), claiming the returned slice can be safely borrowed. However, mainnet RPC integration tests show widespread failures:eth_getProoftests: diff mismatcheth_simulateV1tests: diff mismatchdebug_traceBlockByNumber: malformed JSON + diff mismatchThe borrowed slice is being mutated before callers finish using it.
Fix
Pure revert of #21524 (
b2329dc55b). The net diff is exactly the inverse of that commit and touches nothing else — equivalent togit revert b2329dc55b. It:common.Copy(enc)inTrieContext.Branch()so each returned slice is independent;PatriciaContext.Branchinterface doc andTrieContext.Branchcomment;Test_TrieContext_BranchCopiesDatain full, including the original two-direction independence assertions (source mutation does not reach the returned slice, and mutating the returned slice does not reach the source).CI evidence
Failing job: https://github.com/erigontech/erigon/actions/runs/26987787453/job/79641095034
Regressing commit: b2329dc
Fixes regression from #21524.