Skip to content

Challenge proposal: safety of core::slice::rotate - #774

Open
DevinWatson wants to merge 3 commits into
model-checking:mainfrom
DevinWatson:slice-rotate-challenge
Open

DevinWatson wants to merge 3 commits into
model-checking:mainfrom
DevinWatson:slice-rotate-challenge

Conversation

@DevinWatson

@DevinWatson DevinWatson commented Nov 18, 2026 •

Copy link
Copy Markdown

This proposes a challenge on the in-place slice rotation implementation in
core/src/slice/rotate.rs: the dispatcher ptr_rotate and its three strategies (memmove through a
stack buffer, the gcd cycle walk, and Gries--Mills block swaps) behind the safe methods
<[T]>::rotate_left and <[T]>::rotate_right.

Adds the challenge document and its book entry.

Tracking issue: #773

Notes for reviewers:

  • Scope: four unsafe functions in one 277-line file, plus the safe const_min helper whose value
    the dispatch proof relies on. The only callers are rotate_left / rotate_right in
    core::slice. Inventory checked against main at a43ef3d40d (unchanged from 6079edcda31).
  • Unbounded safety and unbounded functional correctness across all three strategies: the page
    requires proving both absence of undefined behavior and the exact rotation postcondition
    ((j + left) mod (left + right), equivalently append(drop(left, xs), take(left, xs)), with all
    element values/ownership preserved) for arbitrary left and right across ptr_rotate,
    ptr_rotate_memmove, ptr_rotate_gcd, and ptr_rotate_swap, with no length bound.
  • Generic T: the page asks for verification over generic T (issue Ruling needed: what satisfies "must hold for generic type T (no monomorphization)" #734), naming the shapes
    that 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, and
    destructor-carrying).
  • Side conditions & optimize_for_size: the three strategies are private and are only called
    under conditions the dispatcher establishes (left > 0, right > 0, non-ZST T for gcd/swap;
    smaller side fits the 256-byte buffer for memmove). The page allows a strategy's contract to
    record its condition; ptr_rotate itself takes the documented precondition alone. Both default
    and optimize_for_size configurations are covered.
  • I will renumber the file, the title and the SUMMARY.md line if another proposal is merged
    first, and re-check the inventory against main before each review round.

Disclosure:

  • I have a complete unbounded, polymorphic generic-T solution to this challenge as written,
    verified privately with VeriFast 26.10 and refinement-checker 26.10 (zero edits to
    library/; original/rotate.rs is byte-identical to library/core/src/slice/rotate.rs,
    diff -u exit 0).
  • Figures from the private VeriFast 26.10 solution (3 consecutive deterministic runs of
    verifast-proofs/check-verifast-proofs.sh and check-verifast-proofs-negative.sh):
    • Unbounded safety + exact functional correctness (rotate_list(left, xs) plus pointwise
      rotate_list_nth and RustBelt ownership-preservation rotate_preserves_own) proved for all 4
      unsafe functions (ptr_rotate, ptr_rotate_memmove, ptr_rotate_gcd, ptr_rotate_swap) and
      safe const_min, for arbitrary left/right and polymorphic generic T.
    • Default cfg: 0 errors found (1025 statements verified); --cfg feature="optimize_for_size":
      0 errors found (997 statements verified); refinement-checker: No refinement errors found
      on both configurations (~7.0 s wall time, ~152 MiB peak RSS).
    • Zero assume(...) calls in proof bodies; minimal trusted surface documented (2 layout
      lemmas for [usize; 32] / ([usize; 32], [T; 0]) in rotate_axioms.rsspec and 4 1-line
      *__VeriFast_wrapper std primitive specs checked by refinement-checker).
    • Falsifiability: 5/5 seeded 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 all 4/4 code mutants also rejected by refinement-checker; includes a
      companion rotate.rs-negative directory wired into check-verifast-proofs-negative.sh.
  • (An earlier bounded <= 24 Kani prototype disclosed on the initial open of this PR is superseded
    by the unbounded VeriFast 26.10 solution above, and the challenge page has been tightened
    accordingly to remove the bounded <= 24 fallback.)
  • It was produced with AI assistance and machine-checked by VeriFast 26.10 and refinement-checker.
  • I intend to submit this solution once the challenge is published, and I will follow whatever the
    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.

Proposes Challenge 36 and adds its book entry. Documentation only:
doc/src/challenges/0036-slice-rotate.md and one SUMMARY.md line.
@DevinWatson
DevinWatson requested a review from a team as a code owner November 18, 2026 01:44
@feliperodri feliperodri added the Challenge Proposal Used to tag a challenge proposal PR / Issue label Nov 18, 2026
@DevinWatson
DevinWatson force-pushed the slice-rotate-challenge branch from 63ca035 to cae7299 Compare November 23, 2026 17:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Challenge Proposal Used to tag a challenge proposal PR / Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants