Skip to content

fix: tolerate unchanged memcpy after undelegation - #207

Merged
bmuddha merged 1 commit into
masterfrom
fix/undelegation-memcpy-noop
Nov 12, 2026
Merged

bmuddha merged 1 commit into
masterfrom
fix/undelegation-memcpy-noop

Conversation

@bmuddha

@bmuddha bmuddha commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

What changed

Older Anchor programs serialize typed accounts again after the undelegation CPI returns. Engine remaps those accounts read-only, so even an identical-byte copy fails with ExternalAccountDataModified.

Wrap sol_memcpy_ to accept a rejected copy only when its destination is instruction-writable, read-only mapped Undelegating account data and both byte ranges match. The fallback reads and compares without writing or changing permissions. Normal copies, overlap checks, and compute charging remain with the upstream syscall.

Impact

Existing Anchor binaries can complete redundant exit serialization after undelegation without switching to raw accounts or rebuilding with newer Anchor. Execution and simulation share the override. Direct SBF stores and other memory syscalls are unchanged.

engine_processor_memcpy_fallbacks counts accepted fallback calls, including simulations and calls in transactions that later fail.

Reviewer notes

Fallback validation must never broaden writable permissions or accept differing bytes. Only the original destination store violation is eligible; failed range, account, or byte checks return the original syscall error. The syscall is called once so the fallback does not charge compute twice.

@bmuddha bmuddha added the bug Something isn't working label Nov 12, 2026
@bmuddha bmuddha self-assigned this Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The processor adds a Memcpy syscall wrapper that accepts a narrow set of identical-byte memcpy fallbacks without writing memory or changing mapping permissions. It records accepted fallbacks, including those in transactions that later fail. The processor replaces the runtime’s existing sol_memcpy_ syscall with the wrapper. Runtime environments now provide mutable loader access when their Arc is uniquely owned.

Change: Bug fix

Merge Risk: Minimal · up to 753dd

This change lets older Anchor programs that serialize accounts after the undelegation CPI succeed when the memcpy would not change any bytes. No merge-blocking risk was found in the supplied context.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fallback that accepts an unchanged memcpy after undelegation. The raw summary confirms a Memcpy syscall wrapper that accepts identical-byte copies on read-only, unde…
Description check Passed The description states the problem (older Anchor programs re-serialize accounts after undelegation CPI, and the engine rejects even identical-byte copies with ExternalAccountDataModified). It then des…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a fallback that accepts an unchanged memcpy after undelegation. The raw summary confirms a Memcpy syscall wrapper that accepts identical-byte copies on read-only, undelegating account data. The title is specific and concise, and it fits the changeset.

Full details: Description check

Explanation

The description states the problem (older Anchor programs re-serialize accounts after undelegation CPI, and the engine rejects even identical-byte copies with ExternalAccountDataModified). It then describes the sol_memcpy_ wrapper, its eligibility checks, the metric, and reviewer notes. These match the raw summary of syscalls.rs, metrics.rs, and svm.rs.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b853fef and 753dd72.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 6

  • processor/Cargo.toml
  • processor/src/lib.rs
  • processor/src/metrics.rs
  • processor/src/svm.rs
  • processor/src/syscalls.rs
  • solana/program-runtime/src/loaded_programs.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@bmuddha
bmuddha marked this pull request as ready for review November 12, 2026 07:14
@bmuddha
bmuddha merged commit e0b3a76 into master Nov 12, 2026
13 checks passed
@bmuddha
bmuddha deleted the fix/undelegation-memcpy-noop branch November 12, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant