Skip to content

Challenge proposal: safety of str slicing - #757

Open
DevinWatson wants to merge 3 commits into
model-checking:mainfrom
DevinWatson:str-slicing-challenge
Open

DevinWatson wants to merge 3 commits into
model-checking:mainfrom
DevinWatson:str-slicing-challenge

Conversation

@DevinWatson

Copy link
Copy Markdown

This proposes a challenge on byte-range slicing of str: the eleven SliceIndex<str> implementations in
core/src/str/traits.rs, and the char-boundary, get, unchecked-slicing and split_at functions and the
slicing panic helper slice_error_fail_rt in core/src/str/mod.rs. It is the str counterpart of
Challenge 17 and does not overlap Challenges 17, 20, 21 or 22.

Adds the challenge document and its book entry.

Tracking issue: #756

Notes for reviewers:

Disclosure:

  • I have a complete solution to this challenge. It was written and checked privately on 2026-11-12 and
    2026-11-13 (UTC), before this proposal, at the current pins (Rust nightly-2026-10-23, Kani c5e65fdfc3e1,
    the flags of scripts/run-kani.sh with --object-bits 12).
  • Figures from it: 143 harnesses and 613 covers, all passing; total verification time 534 s to 660 s over
    three runs, slowest harness 63 s to 99 s, none above 120 s; 60 injected faults, 57 detected by the harnesses (of the
    other three, one is equivalent and two are caught only by an out-of-band check of the panic site). No
    change to any function body. One unwinding bound, on the harness of ceil_char_boundary, whose unwinding
    assertion Kani checks: the bound is #[kani::unwind(4)]; the unwinding assertion of the loop passes at 4
    and fails at 3, and at 4 it fails on a seeded fault whose contract admits four continuation bytes in a
    row, an input that needs one more iteration. Stubs: only stub_verified of that proved contract, in the
    seven harnesses of slice_error_fail_rt (its six case harnesses and check_char_around_index). No other
    bound, stub or assumption on the length beyond the tool's object limit that the page names.
  • A rehearsal of all four Kani partitions and the autoharness job on the full repository with the solution
    applied gave 472 of 472, 472 of 472, 472 of 472 and 471 of 471 harnesses in partitions 1 to 4, and 1887 of
    1887 harnesses and 246 of 246 functions in the autoharness job; every job exited 0. An earlier rehearsal found
    that a loop invariant on ceil_char_boundary broke three existing CStr harnesses, because any harness
    that reaches a loop contract runs in loop-contract mode; the solution therefore has no loop contract.
  • It was produced with AI assistance and checked by the tools in CI.
  • I intend to submit it as a solution once the challenge is published, and I will follow whatever the
    committee decides in Discussion: incentive structure for contributions #751 (a proposer share, a window for the proposer, review duties, or none of these).
    I am also willing to review other solutions to this challenge and to share the fault-injection table.
  • With Challenge 21: Unbounded verification for StrSearcher safety with Kani #621: whichever is merged second rebases onto the other. One contract per function stays: the one
    that meets this page's criteria for index > len and for the exact result, checked by both sets of
    harnesses; and one string generator, shared. If Challenge 21: Unbounded verification for StrSearcher safety with Kani #621 is merged first, my solution would reuse its
    contracts where they meet the criteria and strengthen them where they do not, keeping Challenge 21: Unbounded verification for StrSearcher safety with Kani #621's harnesses
    passing.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

DevinWatson and others added 2 commits November 12, 2026 21:12
Adds Challenge 32, the safety of byte-range slicing of `str`: the eleven
`SliceIndex<str>` implementations and `check_range` in str/traits.rs, and
the char-boundary, get, unchecked-slicing and split_at functions and the
slicing panic helper in str/mod.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DevinWatson
DevinWatson requested a review from a team as a code owner November 13, 2026 04:10
@patricklam

Copy link
Copy Markdown

Good to see challenges by others as well.

@feliperodri
feliperodri requested a balanced review from Copilot November 14, 2026 18:48
@feliperodri feliperodri added the Challenge Proposal Used to tag a challenge proposal PR / Issue label Nov 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the documentation-only addition of the string-slicing verification challenge and its book navigation entry.

No open issues 🎉

What changed in this PR

Proposes Challenge 32 for verifying the safety of byte-range str slicing, tracked by #756. It complements the existing slice, string-searcher, and iterator challenges without changing library code.

Changes:

  • Defines the scope of 28 unsafe functions and 57 safe functions, including boundary checks and slicing panic paths.
  • Specifies contract, exact-result, and unbounded verification requirements, with explicit assumptions and Kani-specific panic-path obligations.
  • Adds the challenge to the book’s navigation.
File Description
doc/​src/​SUMMARY.md Adds the Challenge 32 navigation entry.
doc/​src/​challenges/​0032-str-slicing.md Defines the challenge’s scope, assumptions, and verification success criteria.

Review effort: Balanced

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.

4 participants