proofs.rs

Claim #3 — Cloning a buffer creates a fresh buffer without panics

<itoa::Buffer as Clone>::clone

impl Clone for Buffer
pub fn clone(self: &Self) -> Self

Tool: creusot 0.11.0-dev+itoa-toolpatch

Overview

clone delegates to Buffer::new and passes panic-freedom checks in both recorded configurations. It creates fresh storage rather than preserving any previous formatted bytes.

Preconditions

true

Evidence

https://github.com/nyuichi/rust-crate-proofs/blob/ae01d2538298d1873485477ef1ccc85a111a6925/itoa/1.0.18/src/runtime.rs

What is trusted

From the report

The sole local trusted operation is assume_init_slice, which casts a borrowed slice of MaybeUninit<u8> to a borrowed slice of u8. Its caller proves that every selected slot is initialized; its assumed contract preserves the slice length and each byte, without assuming decimal correctness or ASCII. Source reasoning supports this narrow boundary: MaybeUninit<u8> has u8's size and alignment, the cast retains the slice metadata, every u8 bit pattern is valid, and the returned shared borrow is tied to the input borrow. The conversion allocates nothing and selects only the suffix proved initialized. This reasoning is not a formal proof of the raw view or physical memory-permission transfer, which remain trusted and are necessary for the returned string guarantee.

The proof also relies on external contracts for core operations, including MaybeUninit writes, unchecked slice selection, array indexing and slice-to-array borrowing, signed unsigned_abs, and from_utf8_unchecked. Callers prove the relevant initialization, bounds, exact lengths and UTF-8 conditions. The array contracts describe the same elements and preserve changes through the borrowed view; unsigned_abs gives the mathematical magnitude even at signed MIN, consistent with core's wrapping absolute-value implementation. The string conversion is assumed to retain bytes when its proved UTF-8 precondition holds. These contracts describe narrow standard operations, but their runtime core bodies are not proved by this crate verification.

Technical limitations

From the report

This is verification of a source adaptation of itoa 1.0.18, not formal equivalence to the published release. To let Creusot analyze the public path, each writer replaces the original raw typed-prefix view with a checked prefix slice-to-array conversion; its exact length and successful unwrap are proved. The initialized byte-slice reinterpretation is factored into the trusted helper described above. These changes retain the buffer, selected output bytes and optimized arithmetic by source reasoning, but release-to-adaptation equivalence has not been formally established. Proof-only decimal-table data is checked byte-for-byte against the ordinary-build table by a compile-time assertion. Three private no-panic checker annotations were removed because their helpers require caller-proved bounds; their executable bodies were unchanged, and public checker annotations remain.

The proof target is x86_64; 16- and 32-bit pointer-sized implementations are not covered. The established output, initialization and panic properties do not constitute a complete proof of Rust memory safety, notably at the trusted slice conversion. No claim is made that an unpatched toolchain reproduces these results. Native regression checks supplement the proof but do not expand its target or input coverage.

Tool limitations

Pinned derivative of Creusot 0.11.0-dev at commit 437d3d8d00b8114d7a3b4f7b8738d594a395f5bc, with the backend narrowing-cast compatibility patch and Why3 overlay/driver changes documented in https://github.com/nyuichi/rust-crate-proofs/tree/ae01d2538298d1873485477ef1ccc85a111a6925/tools/creusot-toolpatch (use the full immutable source commit in each report). This is not upstream Creusot 0.13.0. Verification is relative to supplied contracts, standard-library models, trusted boundaries, selected compilation configuration, and target architecture. Successful proofs do not constitute a complete Rust undefined-behavior or physical memory-permission proof. Allocation failure is outside the guarantees. Each report must disclose its local trusted helpers and source accommodations.

Updated 2026-10-04 02:12 UTC

creusot 0.11.0-dev+itoa-toolpatch — version details

Read and join the discussion on the report →