Skip to content

Proofs (jcs): first-party key ordering and escaping with Pearlite contracts and a Verus model, not yet run - #53

Draft
hyperpolymath wants to merge 1 commit into
mainfrom
claude/beta-proof-jcs
Draft

hyperpolymath wants to merge 1 commit into
mainfrom
claude/beta-proof-jcs

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Proof module 1 of the beta track: src/jcs.rs. No verifier has been run. The owner ruled that provers run from the pinned hyperpolymath/prover-images, which has no Creusot or Verus image yet, so every proof row in this PR is OPEN. What this PR does is make the code provable, write the contracts, and give executed TESTED evidence that behaviour is unchanged.

Design decision (for the owner)

Key ordering used str::encode_utf16().cmp() and escaping used serde_json::to_string. Neither can be given more than an assumed contract in Creusot, so a proof "on the production code" would have proved almost nothing first-party.

  • Implemented, and my recommendation (most elegant and correct): move both into src/jcs_core.rs, a dependency-free byte-level module. UTF-16 code-unit order on well-formed UTF-8 is plain byte order after one permutation of the byte values EE..=F4; escaping only ever touches bytes below 0x20, " and \. Both become short loops over &[u8] that Creusot handles directly, and the trusted base for these two properties shrinks to "a str is UTF-8".
  • Alternative, most conservative: leave the code alone and record assumed contracts for encode_utf16 and serde_json::to_string. Zero production change; the two properties stay ASSUMED for good.
  • Further option not taken here: after sorting keys, check by a linear scan that they are strictly increasing, and refuse otherwise. That would prove member order without trusting sort_by (creusot-std 0.15.0 has no contract for it), at the cost of a new error path. Needs an owner ruling because it touches the public error enum.

What is in the PR

Path Content
src/jcs_core.rs cmp_utf16, write_string_literal, Pearlite contracts and lemmas behind cfg(creusot), differential unit tests
src/jcs.rs calls the core; std::cmp::Ordering import and the serde_json escaping calls removed
verification/creusot/ harness crate that includes src/jcs_core.rs by path; controls.rs has 2 true controls and 2 false controls (feature false-control); tests/contracts_parse.rs is a syntax check
verification/verus/jcs_model.rs Verus model of the same definitions
verification/PROOF-STATUS.adoc new section with rows J-1 to J-9 and assumptions A-1 to A-5
Cargo.toml check-cfg for cfg(creusot) only; no new dependency in the shipped crate

The Verus file is a separately written model. Per policy §1.2 a Verus result on it would not be a proof of the production code and is not a second independent witness: one author, one specification, SMT solvers on both sides.

Evidence (executed here, rustc 1.99.1, Linux x86_64)

Check Result
cargo test --locked --all-features 166 passed, 0 failed
cargo test --locked --lib jcs_core (differential, vs the old implementation) 6 passed
Escaping: every Unicode scalar value vs serde_json::to_string 1,112,064 values, all equal
Ordering: every scalar value vs 29 boundary values, both argument orders, vs encode_utf16().cmp() all equal
Ordering: all 1,111 strings of up to 3 characters over 10 boundary characters, pairwise all equal
Planted mutants of src/jcs_core.rs (false control for the tests) 5 of 5 fail the tests
cargo test --manifest-path verification/creusot/Cargo.toml (pearlite-syn 0.15.0) 33 + 4 contract terms parse; 3 malformed terms refused
cargo clippy --locked --all-targets --all-features -- -D warnings, cargo fmt --check clean
cargo bench --locked, median of 9, canonical-object-v1 1,228,646 ns before, 997,985 ns after (one local run each; not a baseline)
scripts/proven-coverage.sh no new uncovered line; one new unreachable exclusion (bytes F5..FF); still exits 1 for the pre-existing parse_jcs lines reported in #50

Not executed: Creusot, Why3, Verus, Z3, CVC5, Kani. No image digests exist to cite. The pearlite-syn check is syntax only: it does not type-check the contracts, and I expect some to need adjustment on first contact with the verifier (lemma bodies are empty; Seq equalities may need ext_eq hints). MSRV, macOS and Windows jobs were not run locally.

Kani: not applicable. #[forbid(unsafe_code)] holds in the library and the binary and there is no FFI.

Row census

Denominator: the 9 obligations J-1 to J-9 added to PROOF-STATUS.adoc.

Token Count Rows
PROVEN 0
PROVEN-WITH-AXIOMS 0
TESTED 3 J-3 UTF-16 conformance, J-5 escape table, J-9 number rendering
ASSUMED 0
OPEN 6 J-1, J-2, J-4, J-6, J-7, J-8

Assumptions recorded: 5 (serde_json, ryu-js, sort_by, i64::to_string, str is UTF-8), all ASSUMED. Engineering proofs are not PWG-graded.

Open points

  • J-3 (the permutation trick really is UTF-16 order) is tested exhaustively only for single characters against a boundary set and for short strings. A proof needs a first-party model of UTF-8 and UTF-16 encoding, because creusot-std's char::to_utf8 is opaque. This is the hardest remaining statement and may be better stated once as theory.
  • creusot-std is LGPL-2.1-or-later. It is a dependency of the harness only and is not linked into ijson-jcs. No licence file was touched.
  • Independent of Holes first: fail closed under serde_json arbitrary_precision; no CLI panic on unwritable stderr #50; the two touch different lines of .proven/coverage-exclusions.tsv.

Generated by Claude Code

…ts (not yet run)

Move UTF-16 key ordering and string escaping out of str::encode_utf16 and
serde_json::to_string into src/jcs_core.rs, a dependency-free byte-level
module, so both properties can be proved on shipped code.

- cmp_utf16: lexicographic byte order after one permutation of EE..F4,
  which is UTF-16 code-unit order on well-formed UTF-8.
- write_string_literal: RFC 8785 section 3.2.2.2 escaping, per byte.
- Pearlite contracts behind cfg(creusot), written against creusot-std
  0.15.0. No verifier has been run; every proof row is OPEN.
- verification/creusot: harness that includes the production file by path,
  with true and false controls, and a pearlite-syn syntax check.
- verification/verus/jcs_model.rs: a model of the same definitions, not run.
- Differential tests: exhaustive over all scalar values for escaping and
  against a boundary set for ordering; counted tests for the new lines.
- verification/PROOF-STATUS.adoc: ledger section for the canonical writer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDfneftEg71bUadt3v3
@gitnotebooks

gitnotebooks Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/hyperpolymath/ijson-jcs/pull/53

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 959ec83a-cc43-4756-9de6-6b18ff364eac
Commits

Reviewing files that changed from the base of the PR and between 67b89d9 and c688884.

Files ignored due to path filters: 2

  • .proven/coverage-exclusions.tsv is excluded by !**/*.tsv
  • verification/creusot/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 12

  • .gitignore
  • Cargo.toml
  • src/jcs.rs
  • src/jcs_core.rs
  • src/lib.rs
  • tests/proven_mutation_kills.rs
  • verification/PROOF-STATUS.adoc
  • verification/creusot/Cargo.toml
  • verification/creusot/src/controls.rs
  • verification/creusot/src/lib.rs
  • verification/creusot/tests/contracts_parse.rs
  • verification/verus/jcs_model.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

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