diff --git a/scripts/tests/proof-gate-test.sh b/scripts/tests/proof-gate-test.sh index 3b149e2..ed5b0f3 100755 --- a/scripts/tests/proof-gate-test.sh +++ b/scripts/tests/proof-gate-test.sh @@ -16,7 +16,7 @@ fail=0 fixture() { local dir=$work/$1 mkdir -p "$dir/src" "$dir/verification" - cp src/jcs_core.rs src/ijson_core.rs "$dir/src/" + cp src/jcs_core.rs src/ijson_core.rs src/framing_core.rs "$dir/src/" cp -r verification/creusot "$dir/verification/" rm -rf "$dir/verification/creusot/target" git -C "$dir" init -q @@ -34,7 +34,7 @@ stub() { chmod +x "$path" echo "$path" } -honest=$(stub honest 'if [[ $1 == false ]]; then echo "error: false_control_ordering: goal not proved"; echo "error: false_control_literal: goal not proved"; echo "error: false_control_noncharacter: goal not proved"; exit 1; fi') +honest=$(stub honest 'if [[ $1 == false ]]; then echo "error: false_control_ordering: goal not proved"; echo "error: false_control_literal: goal not proved"; echo "error: false_control_noncharacter: goal not proved"; echo "error: false_control_framing: goal not proved"; exit 1; fi') accepts_all=$(stub accepts-all 'exit 0') refuses_all=$(stub refuses-all 'echo "error: toolchain missing"; exit 1') wrong_reason=$(stub wrong-reason 'if [[ $1 == false ]]; then echo "error: could not compile"; exit 1; fi') @@ -71,7 +71,7 @@ receipt=$work/honest/target/receipt.json commit=$(git -C "$work/honest" rev-parse HEAD) digest=$(sha256sum "$work/honest/src/jcs_core.rs" | cut -d' ' -f1) for want in "\"commit\":\"$commit\"" "\"src/jcs_core.rs\":\"$digest\"" '"verifier":"stub"' \ - '"false_refused":["false_control_ordering","false_control_literal","false_control_noncharacter"]'; do + '"false_refused":["false_control_ordering","false_control_literal","false_control_noncharacter","false_control_framing"]'; do grep -qF "$want" "$receipt" || { echo "FAIL receipt lacks $want" >&2; fail=1; } done diff --git a/src/framing_core.rs b/src/framing_core.rs new file mode 100644 index 0000000..6cf8bb0 --- /dev/null +++ b/src/framing_core.rs @@ -0,0 +1,151 @@ +//! SPDX-License-Identifier: MPL-2.0 +//! Copyright (c) 2026 Hyperpolymath Estate +//! +//! First-party byte framing: canonical-form comparison and line splitting. +// +// Like `jcs_core.rs`, this file is compiled by this crate and, from the same +// bytes, by the Creusot harness in `verification/creusot`. It depends on +// nothing but `core`, and every contract is behind `cfg(creusot)`. +// +// STATUS: the contracts have NOT been run through Creusot; the rows are +// `OPEN` in `verification/PROOF-STATUS.adoc`. The behaviour is `TESTED` by +// the tests at the end of this file. + +#[cfg(creusot)] +use creusot_std::prelude::*; + +/// The line feed that ends an estate file and every JSON Lines record. +pub(crate) const LINE_FEED: u8 = b'\n'; + +/// Whether the first `n` bytes of `a` and of `b` are the same. +#[cfg_attr(creusot, check(terminates))] +#[cfg_attr(creusot, requires(n@ <= a@.len() && n@ <= b@.len()))] +#[cfg_attr(creusot, ensures(result == (forall 0 <= j && j < n@ ==> a@[j] == b@[j])))] +fn prefix_equal(a: &[u8], b: &[u8], n: usize) -> bool { + let mut i = 0; + #[cfg_attr(creusot, variant(n@ - i@))] + #[cfg_attr(creusot, invariant(i@ <= n@))] + #[cfg_attr(creusot, invariant(forall 0 <= j && j < i@ ==> a@[j] == b@[j]))] + while i < n { + if a[i] != b[i] { + return false; + } + i += 1; + } + true +} + +/// Whether `input` is exactly `canonical`, or, when `allow_final_lf` is set, +/// `canonical` followed by exactly one line feed. +/// +/// With `allow_final_lf` false and `canonical` the JCS bytes this is the +/// library profile; with `canonical` already ending in its line feed it is +/// the estate file profile; with `allow_final_lf` true it is the tolerant +/// rule `ijson-jcs check` has always applied. +#[cfg_attr(creusot, check(terminates))] +#[cfg_attr(creusot, ensures(result == (input@ == canonical@ + || (allow_final_lf && input@ == canonical@.snoc(0x0Au8)))))] +pub(crate) fn matches_canonical(input: &[u8], canonical: &[u8], allow_final_lf: bool) -> bool { + let n = canonical.len(); + if input.len() == n { + return prefix_equal(input, canonical, n); + } + allow_final_lf + && input.len() > n + && input.len() - 1 == n + && input[n] == LINE_FEED + && prefix_equal(input, canonical, n) +} + +/// The end of the line that starts at `start`: the index of the first line +/// feed at or after `start`, or the length of `input` if there is none. +#[cfg_attr(creusot, check(terminates))] +#[cfg_attr(creusot, requires(start@ <= input@.len()))] +#[cfg_attr(creusot, ensures(start@ <= result@ && result@ <= input@.len()))] +#[cfg_attr(creusot, ensures(forall start@ <= j && j < result@ ==> input@[j]@ != 0x0A))] +#[cfg_attr(creusot, ensures(result@ < input@.len() ==> input@[result@]@ == 0x0A))] +pub(crate) fn line_end(input: &[u8], start: usize) -> usize { + let mut i = start; + #[cfg_attr(creusot, variant(input@.len() - i@))] + #[cfg_attr(creusot, invariant(start@ <= i@ && i@ <= input@.len()))] + #[cfg_attr(creusot, invariant(forall start@ <= j && j < i@ ==> input@[j]@ != 0x0A))] + while i < input.len() { + if input[i] == LINE_FEED { + return i; + } + i += 1; + } + i +} + +#[cfg(test)] +mod tests { + use super::*; + + /// The rule this module replaces, as `profile.rs` wrote it. + fn reference_matches(input: &[u8], canonical: &[u8], allow_final_lf: bool) -> bool { + input == canonical + || (allow_final_lf + && input + .strip_suffix(&[LINE_FEED]) + .is_some_and(|stripped| stripped == canonical)) + } + + /// Every byte string of length up to 5 over `{a, b, LF}`. + fn short_strings() -> Vec> { + let mut all = vec![Vec::new()]; + let mut last = all.clone(); + for _ in 0..5 { + let mut next = Vec::new(); + for prefix in &last { + for byte in [b'a', b'b', LINE_FEED] { + let mut s = prefix.clone(); + s.push(byte); + next.push(s); + } + } + all.extend(next.iter().cloned()); + last = next; + } + assert_eq!(all.len(), 1 + 3 + 9 + 27 + 81 + 243); + all + } + + /// All pairs of short strings, both settings: 364 x 364 x 2 comparisons + /// against the previous rule. + #[test] + fn matches_canonical_as_before() { + let strings = short_strings(); + for input in &strings { + for canonical in &strings { + for allow in [false, true] { + assert_eq!( + matches_canonical(input, canonical, allow), + reference_matches(input, canonical, allow), + "{input:?} vs {canonical:?}, allow {allow}" + ); + } + } + } + // Exactly one line feed: two are refused, and so is CR LF. + assert!(matches_canonical(b"{}\n", b"{}", true)); + assert!(!matches_canonical(b"{}\n\n", b"{}", true)); + assert!(!matches_canonical(b"{}\r\n", b"{}", true)); + assert!(!matches_canonical(b"{}\n", b"{}", false)); + assert!(!matches_canonical(b"", b"{}", true)); + } + + /// `line_end` finds the first line feed at or after every start. + #[test] + fn line_end_is_the_first_line_feed() { + for input in short_strings() { + for start in 0..=input.len() { + let want = input[start..] + .iter() + .position(|byte| *byte == LINE_FEED) + .map_or(input.len(), |offset| start + offset); + assert_eq!(line_end(&input, start), want, "{input:?} from {start}"); + } + } + } +} diff --git a/src/lib.rs b/src/lib.rs index a644867..44de0bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,6 +67,7 @@ #![allow(clippy::needless_doctest_main)] mod error; +mod framing_core; mod ijson; mod ijson_core; mod jcs; diff --git a/src/profile.rs b/src/profile.rs index c58e43e..4299a3c 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -50,6 +50,7 @@ use std::fmt; use serde_json::Value; use crate::error::{CanonicalizationError, IJsonError}; +use crate::framing_core; use crate::{JsonMode, parse_json_bytes, to_jcs}; /// The single byte the estate file profile appends to canonical bytes. @@ -169,13 +170,7 @@ pub fn classify(input: &[u8], profile: CanonicalProfile) -> Result bool { - if input == canonical { - return true; - } - profile == CanonicalProfile::Tolerant - && input - .strip_suffix(&[FINAL_LF]) - .is_some_and(|stripped| stripped == canonical) + framing_core::matches_canonical(input, canonical, profile == CanonicalProfile::Tolerant) } /// Library canonical bytes for JSON text: no trailing line feed. diff --git a/src/records.rs b/src/records.rs index 955ff85..fe27f1a 100644 --- a/src/records.rs +++ b/src/records.rs @@ -35,6 +35,7 @@ use std::fmt; use crate::error::IJsonError; +use crate::framing_core; use crate::profile::{Conformance, canonicalize_bytes}; /// Why a JSON Lines document is not a well-framed sequence of records. @@ -94,18 +95,14 @@ impl<'a> Records<'a> { /// framing *finding*, which [`classify_records`] reports as /// [`Conformance::NotCanonical`], not a parse error. pub fn parse(input: &'a [u8]) -> Result { + // Each line runs from `start` to the next line feed, or to the end of + // the input when the last line has none. let mut lines = Vec::new(); - if !input.is_empty() { - let mut start = 0; - for (index, byte) in input.iter().enumerate() { - if *byte == b'\n' { - lines.push(&input[start..index]); - start = index + 1; - } - } - if start < input.len() { - lines.push(&input[start..]); - } + let mut start = 0; + while start < input.len() { + let end = framing_core::line_end(input, start); + lines.push(&input[start..end]); + start = end + 1; } for (index, line) in lines.iter().enumerate() { if line.is_empty() { @@ -269,4 +266,51 @@ mod tests { assert!(crate::to_jcs(&value).is_ok()); } } + + /// The splitter agrees with the previous one (split at every line feed, + /// keep a final unterminated line) on every byte string of length up to + /// 7 over `{a, LF, CR}`: 3,280 inputs. + #[test] + fn splitting_is_unchanged() { + fn reference(input: &[u8]) -> Vec<&[u8]> { + let mut lines = Vec::new(); + let mut start = 0; + for (index, byte) in input.iter().enumerate() { + if *byte == b'\n' { + lines.push(&input[start..index]); + start = index + 1; + } + } + if start < input.len() { + lines.push(&input[start..]); + } + lines + } + let mut inputs = vec![Vec::new()]; + let mut last = inputs.clone(); + for _ in 0..7 { + let mut next = Vec::new(); + for prefix in &last { + for byte in *b"a\n\r" { + let mut s = prefix.clone(); + s.push(byte); + next.push(s); + } + } + inputs.extend(next.iter().cloned()); + last = next; + } + assert_eq!(inputs.len(), 3280); + for input in &inputs { + let want = reference(input); + match Records::parse(input) { + Ok(records) => assert_eq!(records.as_slice(), &want[..], "{input:?}"), + Err(FramingError::BlankLine { line }) => { + let first_blank = want.iter().position(|l| l.is_empty()).unwrap(); + assert_eq!(line, first_blank + 1, "{input:?}"); + } + Err(other) => panic!("{input:?}: {other}"), + } + } + } } diff --git a/tests/integer_rendering.rs b/tests/integer_rendering.rs new file mode 100644 index 0000000..2542fb9 --- /dev/null +++ b/tests/integer_rendering.rs @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright (c) 2026 Hyperpolymath Estate +// +// PROOF-STATUS J-9, TESTED evidence. `to_jcs` writes a safe integer through +// a decimal fast path and every other number through ryu-js. For an integer +// in ±(2^53−1) the two must give the same bytes, because RFC 8785 defines +// the output by the ECMAScript algorithm that ryu-js implements. +// +// The same integer is canonicalised twice: as an integer `Value` (fast +// path) and as the equal double (ryu-js path). +// +// Bounds: exhaustive for |i| <= 2^17, boundary neighbourhoods, and a +// fixed-seed sample. The whole domain has about 1.8e16 values. A wider run +// of the same comparison is recorded in `verification/PROOF-STATUS.adoc`. + +use ijson_jcs::to_jcs; +use serde_json::{Number, Value}; + +const SAFE_MAX: i64 = (1 << 53) - 1; + +fn both_paths_agree(i: i64) { + let fast = to_jcs(&Value::Number(Number::from(i))).unwrap(); + let double = to_jcs(&Value::Number(Number::from_f64(i as f64).unwrap())).unwrap(); + assert_eq!(fast, double, "{i}"); + assert_eq!(fast, i.to_string().into_bytes(), "{i}"); +} + +#[test] +fn small_integers_exhaustively() { + for i in -(1i64 << 17)..=(1i64 << 17) { + both_paths_agree(i); + } +} + +#[test] +fn boundary_neighbourhoods() { + let mut centres = vec![0, SAFE_MAX]; + centres.extend((0..=53).map(|e| 1i64 << e)); + let mut power = 1i64; + while power <= SAFE_MAX { + centres.push(power); + power *= 10; + } + let mut checked = 0; + for centre in centres { + for sign in [1i64, -1] { + for delta in -8..=8 { + let i = sign * centre + delta; + if (-SAFE_MAX..=SAFE_MAX).contains(&i) { + both_paths_agree(i); + checked += 1; + } + } + } + } + assert!(checked > 2000, "{checked}"); +} + +#[test] +fn fixed_seed_sample_over_the_safe_range() { + let mut x = 0x9E37_79B9_7F4A_7C15u64; + for _ in 0..200_000 { + x ^= x << 13; + x ^= x >> 7; + x ^= x << 17; + let magnitude = ((x >> 11) as i64).min(SAFE_MAX); + both_paths_agree(if x & 1 == 0 { magnitude } else { -magnitude }); + } +} diff --git a/tests/proven_mutation_kills.rs b/tests/proven_mutation_kills.rs index 1ea70a7..9a7db9b 100644 --- a/tests/proven_mutation_kills.rs +++ b/tests/proven_mutation_kills.rs @@ -315,3 +315,26 @@ fn prefix_keys_and_reordered_keys_sort_together() { ); assert_eq!(text(&to_jcs(&Value::Object(object)).unwrap()), want); } + +/// framing_core.rs `prefix_equal`: an input of the same length as its +/// canonical form, differing only in member order, is valid and not +/// canonical under every profile. +#[test] +fn same_length_reordering_is_not_canonical() { + use ijson_jcs::{CanonicalProfile, Conformance, classify}; + for profile in [ + CanonicalProfile::LibraryBytes, + CanonicalProfile::EstateFile, + CanonicalProfile::Tolerant, + ] { + assert_eq!( + classify(br#"{"b":1,"a":2}"#, profile).unwrap(), + Conformance::NotCanonical, + "{profile}" + ); + } + assert_eq!( + classify(b"{\"b\":1,\"a\":2}\n", CanonicalProfile::EstateFile).unwrap(), + Conformance::NotCanonical + ); +} diff --git a/verification/PROOF-STATUS.adoc b/verification/PROOF-STATUS.adoc index 7d405b3..b2a796d 100644 --- a/verification/PROOF-STATUS.adoc +++ b/verification/PROOF-STATUS.adoc @@ -308,14 +308,26 @@ in `tests/proven_properties.rs` (sampled). |Not run. `TESTED` evidence: canonical idempotence proptests on the strict input domain (sampled). -|J-9 Number rendering over finite binary64 +|J-9 Number rendering over finite binary64, including that the integer fast +path gives the bytes ECMAScript `Number::toString` gives |`write_number_jcs`: integers in ±(2^53−1) through `i64::to_string`, every -other number through ryu-js. Nothing first-party to prove beyond the branch -choice +other number through ryu-js. Owner ruling of 2026-12-02: keep the fast path +and prove it relative to A-2 and A-4. The statement to prove: for a safe +integer, its decimal numeral equals the ECMAScript rendering of the equal +double. Not written yet; it needs the two boundary contracts first |Not modelled |`TESTED` -|RFC 8785 Appendix B vectors and a proptest over random bit patterns -(`tests/rfc8785.rs`). Rests on A-2 and A-4. +|Fast path against the ryu-js path, same integer, byte for byte. +`tests/integer_rendering.rs` (in the suite): exhaustive for magnitudes up to +2^17, ±8 around every power of two and ten, 200,000 sampled. A wider run on +2026-12-02 (scratch program, ryu-js 1.0.3, rustc 1.99.1, not committed): +exhaustive for magnitudes up to 2^26 (134,217,729 values), ±64 around the +same boundaries (18,448), 200,000,000 sampled with xorshift64 seed +`0x9E3779B97F4A7C15`; all equal. The domain has about 1.8e16 values, so this +is sampled. Speed in that run: 26.0 against 43.8 ns per value on integers +uniform over the range, 17.3 against 53.6 on 0..100000 (one machine, one +run). Other numbers: RFC 8785 Appendix B vectors and a proptest over random +bit patterns (`tests/rfc8785.rs`). Rests on A-2 and A-4. |=== Trust boundaries for this section (policy §1.1): @@ -461,4 +473,218 @@ Assumptions: 2, both `ASSUMED`. Whole ledger, the two sections J and R: 16 obligations. `PROVEN` 0, `PROVEN-WITH-AXIOMS` 0, `TESTED` 8, `ASSUMED` 0, `OPEN` 8. Assumptions: 7. +== `src/profile.rs`, `src/records.rs`, `src/jsonld.rs` and `src/framing_core.rs`: profiles and framing + +Owner ruling of 2026-12-02: beta covers every ledger surface, so these +modules carry obligations too. *No verifier has been run.* + +`src/framing_core.rs` holds the two byte-level decisions these modules make, +dependency-free and included by path in `verification/creusot`: +`matches_canonical` (is the input the canonical bytes, optionally plus one +line feed) and `line_end` (where the current line stops). `profile.rs` and +`records.rs` now call them. Everything else in the three modules is +composition over `parse_json_bytes` and `to_jcs`, which are the reader and +writer sections above. + +[cols="3,3,3,1,3",options="header"] +|=== +|Obligation |Creusot / Pearlite scope |Verus scope |Status |Reason / evidence + +|F-1 `matches_canonical(input, canonical, allow)` is true exactly when +`input` is `canonical`, or `allow` holds and `input` is `canonical` followed +by one `0x0A` +|Creusot on `matches_canonical` and `prefix_equal` +|Not modelled +|`TESTED` +|Proof not run. `matches_canonical_as_before`: all pairs of the 364 byte +strings of length up to 5 over three bytes, both settings, against the +previous rule; 2 planted mutants fail. + +|F-2 `line_end(input, start)` is the first `0x0A` at or after `start`, or +the length +|Creusot on `line_end` +|Not modelled +|`TESTED` +|Proof not run. `line_end_is_the_first_line_feed`: every start in the same +364 strings; `splitting_is_unchanged`: 3,280 inputs against the previous +splitter; 2 planted mutants fail. + +|F-3 `classify` returns `Canonical` exactly for the bytes the profile +defines: library = `to_jcs(v)`, estate file = `to_jcs(v)` plus one line +feed, tolerant = either; invalid input is an error, never a verdict +|Contract on `profile::classify`, relative to the reader and writer +contracts and F-1. Needs `IJsonError` and `Value` in scope (A-1) +|Not modelled +|`TESTED` +|Not written. Tests: `tests/profile.rs`, unit tests in `profile.rs`. + +|F-4 `Records::parse` yields the lines between line feeds in order, and +fails at the first empty line with its one-based number +|Contract on `Records::parse` using F-2. Needs `Vec<&[u8]>` and range +indexing contracts from creusot-std +|Not modelled +|`TESTED` +|Not written. Tests: `splitting_is_unchanged`, `tests/records.rs`. + +|F-5 `canonicalize_records` is each record's canonical bytes followed by one +line feed, concatenated; `classify_records` is equality with that +|Contract on both, relative to F-3 and F-4 +|Not modelled +|`TESTED` +|Not written. Tests: `tests/records.rs`, unit tests in `records.rs`. + +|F-6 `canonicalize_jsonld_document` is `canonicalize_bytes` and reads +nothing else (no context fetch, no network) +|Contract: result equals `canonicalize_bytes(input)`. The absence of network +access is by inspection of one line, and `supports_rdf_dataset_canonicalization` +is the constant `false` +|Not modelled +|`TESTED` +|Not written. Tests: `tests/jsonld.rs`. +|=== + +Census for this section: 6 obligations. `PROVEN` 0, `PROVEN-WITH-AXIOMS` 0, +`TESTED` 6, `ASSUMED` 0, `OPEN` 0. Under the beta gate `TESTED` blocks the +tag exactly as `OPEN` does. + +== `src/bin/ijson-jcs.rs`: the command-line tool + +In scope for beta by the same ruling. Nothing is written yet, by agreement +with the hub: the `std::fs` and `std::io` boundary specification is held +until the first Creusot run shows how such contracts must be written. + +[cols="3,3,1,3",options="header"] +|=== +|Obligation |Creusot / Pearlite scope |Status |Reason / next action + +|C-1 A read never returns more than `--max-bytes` bytes and refuses an input +of `limit + 1` bytes or more +|`read_bounded`, relative to `Read::take` and `read_to_end` (boundary A-8) +|`TESTED` +|`input_limits_are_enforced_at_the_boundary` and counted boundary tests. + +|C-2 The exit status is the documented function of the per-file verdicts: 0 +all canonical or fixed, 1 some not canonical and none invalid, 2 otherwise, +including write failures and usage errors +|`run`, `files_command`, `records_command`, `stdin_command`, `main` +|`TESTED` +|`tests/cli.rs`, including unwritable stdout and stderr (pull request 50). + +|C-3 `fix` never installs bytes the strict profile would refuse +|`files_command`, `records_command` +|`TESTED` +|`fix_refuses_to_install_output_outside_the_strict_token_profile`. + +|C-4 Replacement is atomic absent a concurrent writer; no temporary file +is left on any failure path; permission bits are kept +|`atomic_replace`, relative to A-8. Not a lock: the code says so, and a +concurrent or hostile writer is outside the statement +|`TESTED` +|Unix tests in `tests/cli.rs` and `tests/proven_mutation_kills.rs`. + +|C-5 `fix` refuses symlinks, non-regular files, read-only files and, on +Unix, hard-linked files, before opening the target +|`fix_permissions`, relative to A-8 +|`TESTED` +|`fix_refuses_links_and_read_only_files_without_mutating_targets` (Unix). +|=== + +[cols="1,4,1",options="header"] +|=== +|Id |Assumption |Status +|A-8 |Rust std `fs` and `io` on the supported platforms. To be written as a +boundary specification naming, at least: `rename` within one directory is +atomic (POSIX; Windows semantics differ and must be stated separately); +`create_new` is exclusive; `symlink_metadata` does not follow links; `nlink` +on Unix; `Read::take` bounds a read; standard streams ignore `SIGPIPE` and +report `EPIPE` as an error. Not yet written |`ASSUMED` +|=== + +Census for this section: 5 obligations, all `TESTED`. One assumption, `ASSUMED`, +whose specification is not yet written. + +== Tests, fixtures and benchmarks: oracles, generators, evidence boundaries + +Owner ruling of 2026-12-02: specify, do not prove. No proof about test code +is planned. Each line says what the oracle is, how inputs are produced and +what a pass does and does not show. + +[cols="2,3,3,3",options="header"] +|=== +|File |Oracle |Inputs |A pass shows + +|`tests/rfc8785.rs` +|RFC 8785 Appendix B expected strings +|The appendix's binary64 bit patterns, fixed +|Agreement on those vectors only + +|`tests/binary64_reader.rs` +|Round trip: `parse_jcs(to_jcs(x))` has the bits of `x`; fixed cases for +duplicates, depth and tokens +|Fixed cases; one proptest over `any::()` bit patterns, default case count +|Sampled round trip; not all 2^64 patterns + +|`tests/integer_rendering.rs` +|The ryu-js path for the equal double +|Exhaustive to 2^17, boundary neighbourhoods, 200,000 from a fixed seed +|J-9 on those values + +|`tests/properties.rs` +|Self-consistency (idempotence, whitespace invariance, no panic) +|proptest, 512 cases, generators for values and arbitrary bytes up to 4,096 +|Sampled; the file states it is not a proof + +|`tests/proven_properties.rs` +|Self-consistency over every public entry point and CLI command +|proptest with the fixed seed `support::SEED`, at least 100 cases each +|Sampled, replayable; counted by the coverage gate + +|`tests/proven_vectors.rs` +|Expected outputs pinned by SHA-256, with exit status and a required phrase +|Fixed vectors +|Those vectors; a re-pin must still match status and phrase + +|`tests/proven_mutation_kills.rs` +|Hand-written expected values +|Fixed cases, each naming the mutant it kills +|That those mutants die; not mutation adequacy in general + +|`tests/conformance.rs`, `tests/profile.rs`, `tests/records.rs`, +`tests/jsonld.rs`, `tests/cli.rs` +|Hand-written expected verdicts, bytes and exit codes +|Fixed cases; some are Unix or Linux only +|Those cases on the platforms that run them + +|`tests/feature_unification.rs` +|Invariants that hold with and without `serde_json/arbitrary_precision` +|Fixed cases, run in both configurations +|R-7 on those inputs + +|`tests/pipeline.rs`, `tests/standards_pin.rs` +|The pinned standards revision, its contract and receipts +|Repository files +|Internal agreement of the pin; nothing about the library's behaviour + +|Unit tests in `src/jcs_core.rs`, `src/ijson_core.rs`, `src/framing_core.rs` +|The previous implementation (differential), or the Unicode list +|Exhaustive over stated finite domains +|Equality with the old behaviour on those domains; the old behaviour is not +itself proved + +|`tests/fixtures/ecmascript-oracle.mjs` +|A JavaScript engine's `JSON.stringify` +|Not read for this ledger +|Not assessed here + +|`benches/jcs.rs` +|A checksum per workload; timings are measurements +|Four frozen workloads, 2,000 iterations, 9 repetitions +|That the workload ran correctly. No performance claim without a baseline +|=== + +Whole ledger after this section: J 9, R 7, F 6, C 5: 27 obligations. +`PROVEN` 0, `PROVEN-WITH-AXIOMS` 0, `TESTED` 19, `ASSUMED` 0, `OPEN` 8. +Assumptions: 8, all `ASSUMED`. The plan table for `parse_jcs` earlier in this +file predates these sections and is not counted twice. + Canonical policy: metadatastician/standards `3-practice/PROOF-POLICY.adoc`. diff --git a/verification/creusot/SCOPE b/verification/creusot/SCOPE index 9be0245..70e87b6 100644 --- a/verification/creusot/SCOPE +++ b/verification/creusot/SCOPE @@ -5,3 +5,4 @@ # so the verified scope cannot silently become empty. src/jcs_core.rs src/ijson_core.rs +src/framing_core.rs diff --git a/verification/creusot/src/controls.rs b/verification/creusot/src/controls.rs index 19c9e9e..06db58d 100644 --- a/verification/creusot/src/controls.rs +++ b/verification/creusot/src/controls.rs @@ -64,3 +64,19 @@ pub fn true_control_noncharacter(code_point: u32) -> bool { pub fn false_control_noncharacter(code_point: u32) -> bool { crate::ijson_core::is_noncharacter(code_point) } + +/// TRUE control: the production contract of `matches_canonical`, restated. +#[cfg_attr(creusot, check(terminates))] +#[cfg_attr(creusot, ensures(result == (input@ == canonical@ + || (allow_final_lf && input@ == canonical@.snoc(0x0Au8)))))] +pub fn true_control_framing(input: &[u8], canonical: &[u8], allow_final_lf: bool) -> bool { + crate::framing_core::matches_canonical(input, canonical, allow_final_lf) +} + +/// FALSE control: claims a final line feed is never accepted. Must be refused. +#[cfg(feature = "false-control")] +#[cfg_attr(creusot, check(terminates))] +#[cfg_attr(creusot, ensures(result == (input@ == canonical@)))] +pub fn false_control_framing(input: &[u8], canonical: &[u8], allow_final_lf: bool) -> bool { + crate::framing_core::matches_canonical(input, canonical, allow_final_lf) +} diff --git a/verification/creusot/src/lib.rs b/verification/creusot/src/lib.rs index 872de31..0355599 100644 --- a/verification/creusot/src/lib.rs +++ b/verification/creusot/src/lib.rs @@ -10,4 +10,7 @@ pub mod jcs_core; #[path = "../../../src/ijson_core.rs"] pub mod ijson_core; +#[path = "../../../src/framing_core.rs"] +pub mod framing_core; + pub mod controls; diff --git a/verification/creusot/tests/contracts_parse.rs b/verification/creusot/tests/contracts_parse.rs index d0e740c..368000b 100644 --- a/verification/creusot/tests/contracts_parse.rs +++ b/verification/creusot/tests/contracts_parse.rs @@ -92,7 +92,8 @@ fn every_contract_is_well_formed_pearlite() { for (file, expected) in [ ("../../src/jcs_core.rs", 37), ("../../src/ijson_core.rs", 7), - ("src/controls.rs", 6), + ("../../src/framing_core.rs", 13), + ("src/controls.rs", 8), ] { let contracts = contracts_in(file); assert!(