Skip to content

Challenge proposal: Safety of CString, the owned C string - #772

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

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

Conversation

@DevinWatson

@DevinWatson DevinWatson commented Nov 17, 2026 •

Copy link
Copy Markdown

This adds a challenge for library/alloc/src/ffi/c_str.rs, the owned C string CString and its
conversions. Challenge 13 and its in-tree proofs cover the borrowed half (core::ffi::CStr, with
bounded harnesses); no challenge, harness or open pull request covers the alloc half. The page asks
for an unbounded proof (byte vectors of any length; the file has no loops of its own, delegating the
nul scan to core::slice::memchr), a stated representation invariant, contracts for the three public
unsafe constructors (from_vec_unchecked, from_vec_with_nul_unchecked, from_raw), and exact
byte-level behavior of the constructors, views and conversions. Two assumptions are written on the
page rather than left implicit: memchr through a stated first-index contract, and the C strlen
that from_raw calls through a stated model.

Tracking issue: #771

Renumbered to Challenge 35 (0035-cstring.md): proposal #770 (core::io::BorrowedBuf) was opened
before this one and claims 0034, so both SUMMARY.md entries would collide. 0034 stays with #770;
this page is 0035. I will renumber again if another proposal merges first.

Disclosure. Before opening this proposal I prepared a solution privately, with AI assistance, and checked it with
the tools and versions pinned on main (Rust nightly-2026-10-23, Kani c5e65fdfc3e15ec32293f2a4c07509aebec033c9, the flags of
scripts/run-kani.sh). Figures from that run: 42 harnesses, slowest 476 s under contention
(median about 11 s), total 1331 s of verification time for the passing set in the full-suite run, no unwind attribute outside the bounded tiers the page itself allows,
three stated stubs (an over-approximating memchr model for the unbounded safety harnesses, an input-class-exact
core::str::from_utf8 model for two directed UTF-8 harnesses, and the empty-C-string constant behind Kani's
C-string-literal limit rust-lang#2549), no change to a function body.
Known limits of that solution: a quantified first-index memchr contract is not checkable at these pins (the SAT
backend ignores symbolic-bound quantifiers; z3 gave no verdict on it in 14.5 CPU-minutes; cvc5 rejects CBMC's array
terms in its configuration), so scan decisions are bounded as the page's second route allows; several conversion
harnesses sit at CBMC's memory cap and flip between pass and out-of-memory across repeated jobs=2 runs (direct CBMC
on the same binaries shows every property holds); to_string_lossy is proved only on a one-byte invalid input. I intend to submit it once the challenge is published. I am not related
to any committee member. If the committee decides on a proposer window, a proposer share or a review duty in
#751, I will follow that decision, and I am glad to adjust the criteria in any direction the committee prefers,
including making them harder than my solution meets.

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

…odel-checking#770)

model-checking#770 (BorrowedBuf) was opened before this one and also claims 0034, so the
two SUMMARY entries would collide. Posting order decides the number: keep
0034 for model-checking#770 and move this page to 0035. Renumber again on merge if the
field moves.
@feliperodri feliperodri added the Challenge Proposal Used to tag a challenge proposal PR / Issue label Nov 18, 2026

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.

3 participants