Skip to content

Challenge 2: check the harnesses with -Z valid-value-checks - #777

Draft
feliperodri wants to merge 1 commit into
model-checking:mainfrom
feliperodri:valid-value-checks-challenge-2
Draft

feliperodri wants to merge 1 commit into
model-checking:mainfrom
feliperodri:valid-value-checks-challenge-2

Conversation

@feliperodri

@feliperodri feliperodri commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #649, like #775 is for -Z uninit-checks. Challenge 2 requires proofs to rule out "Producing an invalid value", which Kani checks only under -Z valid-value-checks, and CI doesn't pass that flag today. This PR adds a CI job that runs the challenge's harnesses with it, so the solution can claim the property.

Depends on

This is a draft until verify-rust-std's Kani includes model-checking/kani#5205, which checks typed reads of untyped bytes instead of reporting copy_nonoverlapping, write_bytes and mutable casts. It also needs model-checking/kani#5057, which is already in Kani main but not in the pinned c5e65fd. No CBMC change is needed. Then tool_config/kani-version.toml needs to move to a Kani commit that has both. Until then, the new job fails: on the pinned Kani, harnesses stop on unsupported copy_nonoverlapping and mutable casts, and report false positives after write_bytes. The other jobs are unaffected.

What is proven, before and after

#733 lists where #649 stands on each UB item of Challenge 2. This PR changes one row:

UB item Before With this PR and the Kani changes
Producing an invalid value ❌ not checked in CI ✅ checked by the new job, for the types the harnesses instantiate

Results, on Kani c5e65fd with model-checking/kani#5057 and model-checking/kani#5205 ported to it, with the job's command: all 474 harnesses verify (57 minutes on 2 jobs, peak memory 9.8 GB). This is rust-lang#5205 at 7d06f8342, after its review fixes; I'll rerun it if rust-lang#5205 changes again.

What a passing harness establishes under -Z valid-value-checks. For every input the harness allows, and that satisfies the contract's preconditions, no value of a type with validity requirements is produced or read from bytes that aren't a valid value of that type: transmutes, union reads, typed reads through pointers, and typed reads of bytes written by copy, copy_nonoverlapping, write_bytes and the volatile variants. Writing invalid bytes is not reported by itself, because it isn't UB; reading them as a value is. Kani also requires the target of a reference to be valid, which Rust hasn't decided (UCG #77), so this is the stricter reading.

What it doesn't cover. The generic intrinsics are proven for the types the harnesses instantiate them with: integers, char, bool, NonZero, tuples, arrays and real dyn objects. Kani can't check some types yet, and none of the harnesses use them: multi-variant enums with restricted fields (model-checking/kani#3761), enums whose layout isn't a scalar or scalar pair (model-checking/kani#5023), function pointers (model-checking/kani#3760), references to Box (model-checking/kani#3759) and vtable validity of wide pointers (model-checking/kani#3738). If a harness reached one of them on bytes that may be invalid, Kani would report an unsupported check, not pass.

Harness changes

check_transmute{,_unchecked}_{ref_address,slice_metadata} make a &bool or &[bool; 32] to memory from PointerGenerator::any_in_bounds, which may be uninitialized. That's UB under Miri's -Zmiri-recursive-validation, and -Z valid-value-checks reports it. They now assume arb.is_initialized. Under CI's current flags and the pinned Kani, they still pass (4 of 4). The ptr_address harnesses only cast pointers and are unchanged.

Cost

The job took 57 minutes on 2 jobs locally. The job runs on its own runner, alongside the partitions.

Add a CI job that runs Challenge 2's harnesses with -Z valid-value-checks, so that the solution can claim the absence of "Producing an invalid value". It needs a Kani with model-checking/kani#5057 and model-checking/kani#5205.

The four check_transmute{,_unchecked}_{ref_address,slice_metadata} harnesses made a reference to PointerGenerator memory that may be uninitialized; they now assume it is initialized.

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

Maintenance Maintenance related issues for the challange

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant