Skip to content

[SharovBot] fix: revert TrieContext.Branch unsafe borrow causing RPC proof/trace corruption#21630

Merged
yperbasis merged 3 commits into
mainfrom
agent-fix/revert-branch-borrow-unsafe
Jun 5, 2026
Merged

[SharovBot] fix: revert TrieContext.Branch unsafe borrow causing RPC proof/trace corruption#21630
yperbasis merged 3 commits into
mainfrom
agent-fix/revert-branch-borrow-unsafe

Conversation

@erigon-copilot

@erigon-copilot erigon-copilot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[SharovBot]

Problem

PR #21524 removed common.Copy from TrieContext.Branch(), claiming the returned slice can be safely borrowed. However, mainnet RPC integration tests show widespread failures:

  • All 20 eth_getProof tests: diff mismatch
  • 50+ eth_simulateV1 tests: diff mismatch
  • debug_traceBlockByNumber: malformed JSON + diff mismatch

The 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 to git revert b2329dc55b. It:

  • restores common.Copy(enc) in TrieContext.Branch() so each returned slice is independent;
  • restores the original PatriciaContext.Branch interface doc and TrieContext.Branch comment;
  • restores Test_TrieContext_BranchCopiesData in 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.

…proof/trace corruption

Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) in execution/commitment/commitmentdb/commitment_context.go:TrieContext.Branch() to ensure returned branch bytes are independent per call.
  • Update PatriciaContext interface 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.

@yperbasis yperbasis added this to the 3.5.0 milestone Jun 5, 2026
yperbasis and others added 2 commits June 5, 2026 10:08
…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 yperbasis enabled auto-merge June 5, 2026 09:58
@yperbasis yperbasis added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit f0ed752 Jun 5, 2026
88 of 89 checks passed
@yperbasis yperbasis deleted the agent-fix/revert-branch-borrow-unsafe branch June 5, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants