Repository navigation
Challenge 2: check the harnesses with -Z valid-value-checks - #777
Draft
feliperodri wants to merge 1 commit into
Draft
feliperodri wants to merge 1 commit into
feliperodri wants to merge 1 commit into
Conversation
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 was referenced Nov 21, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_bytesand mutable casts. It also needs model-checking/kani#5057, which is already in Kanimainbut not in the pinnedc5e65fd. No CBMC change is needed. Thentool_config/kani-version.tomlneeds to move to a Kani commit that has both. Until then, the new job fails: on the pinned Kani, harnesses stop on unsupportedcopy_nonoverlappingand mutable casts, and report false positives afterwrite_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:
Results, on Kani
c5e65fdwith 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 bycopy,copy_nonoverlapping,write_bytesand 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 realdynobjects. 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 toBox(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&boolor&[bool; 32]to memory fromPointerGenerator::any_in_bounds, which may be uninitialized. That's UB under Miri's-Zmiri-recursive-validation, and-Z valid-value-checksreports it. They now assumearb.is_initialized. Under CI's current flags and the pinned Kani, they still pass (4 of 4). Theptr_addressharnesses 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.