Skip to content

[kani] Prove primitive byte validation - #3647

Open
joshlf wants to merge 1 commit into
Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4from
Gcmpgic3rdonowgrcxzylfnswfrlxt6lm
Open

[kani] Prove primitive byte validation#3647
joshlf wants to merge 1 commit into
Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4from
Gcmpgic3rdonowgrcxzylfnswfrlxt6lm

Conversation

@joshlf

@joshlf joshlf commented Sep 7, 2026

Copy link
Copy Markdown
Member

Drive bool, char, NonZeroU16, its niche-optimized Option, and bool arrays from every concrete-size byte sequence. Compare both internal validators and public reads against safe checked standard-library constructors where available and one centralized Reference-backed bool oracle; verify accepted values and valid/invalid reachability.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.


Latest Update: v52 — Compare vs v51

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v51 v50 v49 v48 v47 v46 v45 v44 v43 v42 v41 v40 v39 v38 v37 v36 v35 v34 v33 v32 v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v52 v51 v50 v49 v48 v47 v46 v45 v44 v43 v42 v41 v40 v39 v38 v37 v36 v35 v34 v33 v32 v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v51 v50 Base
v50 v49 Base
v49 v48 Base
v48 v47 Base
v47 v46 Base
v46 v45 Base
v45 v44 Base
v44 v43 Base
v43 v42 Base
v42 v41 Base
v41 v40 Base
v40 v39 Base
v39 v38 Base
v38 v37 Base
v37 v36 Base
v36 v35 Base
v35 v34 Base
v34 v33 Base
v33 v32 Base
v32 v31 Base
v31 v30 Base
v30 v29 Base
v29 v28 Base
v28 v27 Base
v27 v26 Base
v26 v25 Base
v25 v24 Base
v24 v23 Base
v23 v22 Base
v22 v21 Base
v21 v20 Base
v20 v19 Base
v19 v18 Base
v18 v17 Base
v17 v16 Base
v16 v15 Base
v15 v14 Base
v14 v13 Base
v13 v12 Base
v12 v11 Base
v11 v10 Base
v10 v9 Base
v9 v8 Base
v8 v7 Base
v7 v6 Base
v6 v5 Base
v5 v4 Base
v4 v3 Base
v3 v2 Base
v2 v1 Base
v1 Base
⬇️ Download this PR

Branch

git fetch origin refs/heads/Gcmpgic3rdonowgrcxzylfnswfrlxt6lm && git checkout -b pr-Gcmpgic3rdonowgrcxzylfnswfrlxt6lm FETCH_HEAD

Checkout

git fetch origin refs/heads/Gcmpgic3rdonowgrcxzylfnswfrlxt6lm && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/Gcmpgic3rdonowgrcxzylfnswfrlxt6lm && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/Gcmpgic3rdonowgrcxzylfnswfrlxt6lm

Stacked PRs enabled by GHerrit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-09-09T17:20:52.928534Z 1961311 Manual request
🔒 Security Review Completed 2026-09-08T21:37:22.733386Z 0940d6f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@google-cla

google-cla Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.89%. Comparing base (59a2396) to head (1961311).

Additional details and impacted files
@@                        Coverage Diff                         @@
##           Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4    #3647   +/-   ##
==================================================================
  Coverage                              91.89%   91.89%           
==================================================================
  Files                                     20       20           
  Lines                                   6122     6122           
==================================================================
  Hits                                    5626     5626           
  Misses                                   496      496           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread zerocopy/src/impls.rs Outdated
// types, they exhaust every byte pattern on Kani's target. They do not
// establish that Kani detects invalid typed values after construction.

// Evaluate the validator directly on initialized source bytes. This check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
// Evaluate the validator directly on initialized source bytes. This check
// Evaluates the validator directly on initialized source bytes. This check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed while factoring this setup. The direct-validator plumbing moved to the shared validator_accepts_sized! helper, whose comment now explains that it evaluates the validator on initialized source bytes before the end-to-end API may materialize T.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

Comment thread zerocopy/src/impls.rs
}

#[cfg(kani)]
mod proofs {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can you think of a way to more exhaustively generate every possible bit pattern and then categorize each bit pattern as bit valid or not?

For example, perhaps, for a given T: Sized + IntoBytes, we could do:

  • Generate kani::any::<T>()
  • Confirm that the bytes are accepted as a valid T by TryFromBytes
  • Somehow generate every [u8; size_of::<T>()] that's not a valid T
  • Confirm that these bytes are rejected by TryFromBytes

Ideally we could do this in a way that doesn't require manually encoding validity and instead relies on Rust itself to give us an oracle for validity.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Implemented the byte-first form of this idea in the current revision. Each selected fixed-size type starts from kani::any::<[u8; N]>(), so Kani ranges over every byte pattern without first creating a possibly-invalid T. The proofs compare both the raw validator and public read API against safe checked oracles (char::from_u32, NonZeroU16::new, and native-byte APIs); the only residual manual rule is bool, centralized once and tied to versioned language documentation.

There is no fully generic safe negative oracle: generating kani::any::<T>() witnesses only valid values, while materializing arbitrary bytes as T before checking them is already undefined behavior when the bytes are invalid. That limitation is now documented in proof_support.rs and the PR scope.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from 1cf4212 to b721246 Compare September 7, 2026 17:14
@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch 2 times, most recently from 2753765 to 49e0f09 Compare September 7, 2026 17:47
@joshlf

joshlf commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review current head 49e0f0915d393a0fb446058e7a0aa426502d463f; in particular, challenge the documented proof domain and exclusions, and verify that expected behavior comes from an independent safe Rust, standard-library, language, or explicitly labeled policy oracle.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 49e0f0915d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49e0f0915d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread zerocopy/src/impls.rs Outdated
Comment on lines +1392 to +1393
// Domain: Every initialized source byte sequence for `bool`, `char`,
// `NonZeroU16`, `Option<NonZeroU16>`, and `[bool; 4]` on Kani's target.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict the proof domain to exactly sized sources

For calls where try_read_from_bytes receives a slice whose length differs from size_of::<T>(), these harnesses exercise neither acceptance nor the documented size-error behavior: each bytes value is a fixed-size array and validator_accepts_sized! explicitly uses CastSizedExact. Thus “Every initialized source byte sequence” overstates the public-API domain. Either state that only exactly sized byte representations are covered and exclude size mismatches, or add arbitrary-length harnesses with an independent expected size-error oracle.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in the current revision. The domain is now explicitly every exactly sized initialized representation for the listed types. Size-mismatched sources and size-error classification by the public API are explicitly excluded.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

Comment thread zerocopy/src/impls.rs Outdated
Comment on lines +1406 to +1408
// Excludes: Other types and array lengths, non-native byte order, and
// validity or provenance behavior not modeled by Kani. Starting from bytes
// ensures that no invalid destination value exists before validation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound the claim to the verified build configuration

When this theorem is interpreted beyond the exact CI compilation, the stated exclusions are incomplete: the Kani job in .github/workflows/ci.yml:719-743 enables only __internal_use_only_features_that_work_on_stable and uses --randomize-layout, which checks one randomized layout per run rather than every layout for the target. Nothing in these harnesses quantifies over feature configurations or layout seeds, yet the comment excludes only non-native byte order and model limitations. Explicitly restrict the result to the sampled layout and enabled feature set, or add the configurations needed to support a broader claim.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in the current revision. The family comment and PR scope now bound the result to the exact shared Kani CI configuration, including its bundled target/compiler, stable-compatible feature bundle, function-contract flag, and one randomized layout per invocation.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from b721246 to 8c2ad1a Compare September 7, 2026 19:04
@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from 49e0f09 to 4c05617 Compare September 7, 2026 19:04
@joshlf

joshlf commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review current head 4c056173b4a748f5eb79f160d750f2fdf615d2f2; in particular, challenge the documented proof domain and exclusions, and verify that expected behavior comes from an independent safe Rust, standard-library, language, or explicitly labeled policy oracle.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c056173b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread zerocopy/src/impls.rs
Comment on lines +1505 to +1507
#[kani::proof]
#[kani::unwind(5)]
fn prove_bool_array_try_read_from_bytes() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Document the five-step unwind bound

When this module comment is used as the theorem’s proof scope, it omits the concrete loop bound on the [bool; 4] harness: #[kani::unwind(5)] limits every loop reached from this harness, but neither the documented domain nor its exclusions mentions that limitation. The current revision documents exact source sizes and the shared CI configuration, but this is a distinct remaining bound; state the five-step unwind limit and which array iteration it is intended to cover so the claimed domain remains accurate if the implementation’s looping behavior changes.

AGENTS.md reference: zerocopy/AGENTS.md:L67-L73

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in the current revision. The family scope now states that every harness has #[kani::unwind(5)], permitting the [bool; 4] validator and any other reached bytewise operation to examine four bytes or elements and terminate, with unwinding assertions enforcing that bound.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4c056173b4

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from 4c05617 to fdb1983 Compare September 8, 2026 01:12
@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from 8c2ad1a to 99ced13 Compare September 8, 2026 01:12
@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from 4636641 to 4e93d0f Compare September 9, 2026 01:35
@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from dc3f69d to 69aa306 Compare September 9, 2026 01:35
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review current head 69aa30629b84c0a4b5a596308416d4b9f172f155; in particular, challenge the documented proof domain and exclusions, and verify that expected behavior comes from an independent safe Rust, standard-library, language, or explicitly labeled policy oracle.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from 4e93d0f to d2506e1 Compare September 9, 2026 01:53
@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from 69aa306 to 7485956 Compare September 9, 2026 01:53
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 69aa30629b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 74859565e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from 7485956 to 5e538bb Compare September 9, 2026 02:28
@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from d2506e1 to 145f683 Compare September 9, 2026 02:28
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

Please review exact head 5e538bb6d1b5ae57ba3a4ab6b7e83f330a5f7c82.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 5e538bb6d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@codex review

Exact-head review request: 72bf299

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 72bf299a73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Drive bool, char, NonZeroU16, its niche-optimized Option, and bool arrays from every concrete-size byte sequence. Compare both internal validators and public reads against safe checked standard-library constructors where available and one centralized Reference-backed bool oracle; verify accepted values and valid/invalid reachability.

*Authored by an AI agent acting on Josh Liebow-Feeser's behalf.*

gherrit-pr-id: Gcmpgic3rdonowgrcxzylfnswfrlxt6lm
@joshlf
joshlf force-pushed the Gk2g4l26m6qo5bi7nwt5p7s4lbskrcsk4 branch from 8fc739c to 59a2396 Compare September 9, 2026 17:18
@joshlf
joshlf force-pushed the Gcmpgic3rdonowgrcxzylfnswfrlxt6lm branch from 72bf299 to 1961311 Compare September 9, 2026 17:18
@joshlf

joshlf commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@codex review

Exact-head review request: 1961311

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref 1961311de0078863cb9f340acd5b954969cd1388 does not exist
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants