zkalloc fix: safe arena routing#215
Open
TomWambsgans wants to merge 2 commits into
Open
Conversation
Barnadrot/zk-alloc#9) (replaces the "flush_rayon" ugly fix) Co-authored-by: Barnadrot <kbarna.drot@gmail.com>
) - realloc: switch copy_nonoverlapping -> copy. When a Vec grows inside the arena, the freshly-bumped destination can overlap the source within the same slab, violating copy_nonoverlapping's precondition (UB). - begin_phase: panic if a phase is already active. Phases must stay flat in a bump allocator: a nested begin would recycle the slab and overwrite the outer phase's still-live data. Rather than refcounting (per PR #10), we make the violation impossible via an assert. Co-authored-by: Barnadrot <kbarna.drot@gmail.com>
Barnadrot
added a commit
to Barnadrot/leanMultisig
that referenced
this pull request
May 11, 2026
Profile attributes 1.30% of P-core cycles to libc allocator helpers (_int_malloc + cfree + malloc) inside the zk-alloc build — those are sub-MIN_ARENA_BYTES allocations being routed to System during the active phase. Lowering the floor pulls the 1024..4095-byte band back into the bump-pointer fast path; ideally we recover most of that 1.30%. Why this is still phase-crossing safe: - The ~1.5 KB crossbeam_deque::Injector blocks named in the original comment fall in [0, 1024), so they still route to System. - Sticky-System realloc (PR leanEthereum#215) keeps any Vec that was first allocated in System in System through growth — a Vec allocated at 64 B and grown to 4 KiB inside a phase stays in System. - The known phase-crossing patterns (Registry slots, HashMap entries, rayon job frames) are all sub-KB per the comment; they remain routed to System. Risk: if there is a phase-crossing allocation in the 1024..4095-byte band we have not enumerated, it will end up in arena memory and be recycled across phase boundaries. Correctness gate must pass before benchmark, and prove_loop's 5-warm-proof pattern is the same shape that would expose such a bug.
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.
(size-routing + sticky-System realloc) (mirors Barnadrot/zk-alloc#9)
(replaces the "flush_rayon" ugly fix)