You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: tolerate unchanged memcpy after undelegation - #207
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.
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: 4
Check name
Status
Explanation
Title check
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
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
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.
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 mappedUndelegatingaccount 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_fallbackscounts 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.