Repository navigation
Challenge proposal: safety of core::slice::rotate - #774
Open
DevinWatson wants to merge 3 commits into
Open
DevinWatson wants to merge 3 commits into
DevinWatson wants to merge 3 commits into
Conversation
Proposes Challenge 36 and adds its book entry. Documentation only: doc/src/challenges/0036-slice-rotate.md and one SUMMARY.md line.
…rotate strategies
DevinWatson
force-pushed
the
slice-rotate-challenge
branch
from
November 23, 2026 17:03
63ca035 to
cae7299
Compare
This branch has not been deployed
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.
This proposes a challenge on the in-place slice rotation implementation in
core/src/slice/rotate.rs: the dispatcherptr_rotateand its three strategies (memmove through astack buffer, the gcd cycle walk, and Gries--Mills block swaps) behind the safe methods
<[T]>::rotate_leftand<[T]>::rotate_right.Adds the challenge document and its book entry.
Tracking issue: #773
Notes for reviewers:
const_minhelper whose valuethe dispatch proof relies on. The only callers are
rotate_left/rotate_rightincore::slice. Inventory checked againstmainata43ef3d40d(unchanged from6079edcda31).requires proving both absence of undefined behavior and the exact rotation postcondition
(
(j + left) mod (left + right), equivalentlyappend(drop(left, xs), take(left, xs)), with allelement values/ownership preserved) for arbitrary
leftandrightacrossptr_rotate,ptr_rotate_memmove,ptr_rotate_gcd, andptr_rotate_swap, with no length bound.T: the page asks for verification over genericT(issue Ruling needed: what satisfies "must hold for generic type T (no monomorphization)" #734), naming the shapesthat exercise every branch in the file (zero-sized, buffer-dividing and non-dividing sizes,
over-aligned, larger than the 256-byte buffer, validity-carrying such as
NonZero, anddestructor-carrying).
optimize_for_size: the three strategies are private and are only calledunder conditions the dispatcher establishes (
left > 0,right > 0, non-ZSTTfor gcd/swap;smaller side fits the 256-byte buffer for memmove). The page allows a strategy's contract to
record its condition;
ptr_rotateitself takes the documented precondition alone. Both defaultand
optimize_for_sizeconfigurations are covered.SUMMARY.mdline if another proposal is mergedfirst, and re-check the inventory against
mainbefore each review round.Disclosure:
Tsolution to this challenge as written,verified privately with VeriFast 26.10 and
refinement-checker26.10 (zero edits tolibrary/;original/rotate.rsis byte-identical tolibrary/core/src/slice/rotate.rs,diff -uexit0).verifast-proofs/check-verifast-proofs.shandcheck-verifast-proofs-negative.sh):rotate_list(left, xs)plus pointwiserotate_list_nthand RustBelt ownership-preservationrotate_preserves_own) proved for all 4unsafe functions (
ptr_rotate,ptr_rotate_memmove,ptr_rotate_gcd,ptr_rotate_swap) andsafe
const_min, for arbitraryleft/rightand polymorphic genericT.0 errors found (1025 statements verified);--cfg feature="optimize_for_size":0 errors found (997 statements verified);refinement-checker:No refinement errors foundon both configurations (
~7.0 swall time,~152 MiBpeak RSS).assume(...)calls in proof bodies; minimal trusted surface documented (2layoutlemmas for
[usize; 32]/([usize; 32], [T; 0])inrotate_axioms.rsspecand41-line*__VeriFast_wrapperstd primitive specs checked byrefinement-checker).5/5seeded production/spec faults (gcd off-by-one, swap offset off-by-one,memmove wrong destination, inverted ZST guard, reversed rotation postcondition) rejected by
verifast, and all4/4code mutants also rejected byrefinement-checker; includes acompanion
rotate.rs-negativedirectory wired intocheck-verifast-proofs-negative.sh.<= 24Kani prototype disclosed on the initial open of this PR is supersededby the unbounded VeriFast 26.10 solution above, and the challenge page has been tightened
accordingly to remove the bounded
<= 24fallback.)refinement-checker.committee decides in Discussion: incentive structure for contributions #751. I am also willing to review other solutions to this challenge and to
share the fault-injection table.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.