From 4f6cbefeb27de11e9058aee82427e7f741477842 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 09:38:13 -0700 Subject: [PATCH] test(core): the split harness proves divisibility at step 3 The harness split with step 1, where every integer is a multiple, so its "the rounded side is a whole multiple of the step" claim was vacuous and the assertion absent. Step 3 makes it mean something, and the harness asserts `part % step == 0`; the sum and the two covers are unchanged. Record the re-run (3.1 s wall, 0.66 s verification), note that the Lean model is total where the kernel is partial (a + b = 0), and refresh the traceability counts from the merged bookspec branch. Co-Authored-By: DeepSeek V4.1 Flash --- crates/ledger-core/src/proofs/ratio.rs | 16 ++++++++++++---- docs/proofs/k-u6.md | 15 +++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/ledger-core/src/proofs/ratio.rs b/crates/ledger-core/src/proofs/ratio.rs index 74efb16c..84d15bff 100644 --- a/crates/ledger-core/src/proofs/ratio.rs +++ b/crates/ledger-core/src/proofs/ratio.rs @@ -34,8 +34,9 @@ //! whole). //! 2. A zero or negative whole is None for every part and mode; a //! non-positive step is None too. -//! 3. split_ratio(amount, 1, 2): the rounded part plus the exact rest -//! is the amount, and the part is a whole multiple of the step. +//! 3. split_ratio(amount, 1, 2, 3): the rounded part plus the exact rest +//! is the amount, and the part is a whole multiple of the step (three, +//! so the claim is not vacuous). //! 4. Never a panic; an unrepresentable result is None. //! SCENARIOS: //! 1. IF the exact percent is not a whole multiple of the step: the @@ -45,7 +46,7 @@ //! ``` //! //! Bounds: parts -512 to 512 by whole multiples of eight, amounts -1,000 -//! to 1,000, steps 3 and 1. The laws are about the shape of the +//! to 1,000, every step 3 (the percent's and the split's). The laws are about the shape of the //! arithmetic, not its magnitude; Lean proves the same laws of the exact //! ratio at any size, and the bridge checks the `Decimal` engine against //! an independent exact reference. @@ -58,6 +59,9 @@ const WHOLE: i64 = 8; const STEP: i64 = 3; /// The percent harness's quotient bound: `part = WHOLE × k`. const QUOTIENT: i64 = 64; +/// The split harness's step: three units, so the part is a multiple of a +/// step that is not one and the divisibility claim has content. +const SPLIT_STEP: i64 = 3; fn any_half_mode() -> Rounding { if kani::any() { @@ -125,8 +129,12 @@ fn split_ratio_sums() { let amount: i64 = kani::any(); kani::assume((-1_000..=1_000).contains(&amount)); let mode = any_mode(); - let (part, rest) = split_ratio(amount, 1, 2, 1, mode).expect("in range"); + let (part, rest) = split_ratio(amount, 1, 2, SPLIT_STEP, mode).expect("in range"); assert_eq!(part + rest, amount, "the two parts sum to the whole"); + assert!( + part % SPLIT_STEP == 0, + "the rounded side is a whole multiple of the step" + ); kani::cover!( part * 3 != amount, "the rounded side is not the exact share" diff --git a/docs/proofs/k-u6.md b/docs/proofs/k-u6.md index 1476d581..fcf3669a 100644 --- a/docs/proofs/k-u6.md +++ b/docs/proofs/k-u6.md @@ -74,13 +74,14 @@ On `i64`, each with `kani::cover!`. The whole is fixed at 8 (both functions divide by a whole or a ratio, and a symbolic divisor did not finish in K-U2); the percent harness takes the part as `8 × k` so the model's division is exact, and steps at 3 so a rounded percent moves. The -split is fixed at 1 : 2 and the amount runs −1,000 to 1,000. +split is fixed at 1 : 2 with step 3 (so divisibility is not vacuous) and +the amount runs −1,000 to 1,000. | Harness | Law | Verification | |---|---|---| | `percent_of_within_half_step` | 44 | with the model's division exact (`part = 8 k`), the half modes put the percent within half a step of `100 k`; a percent not already a multiple of the step and a negative part are reached (2 covers). 7.4 s wall, 0.79 s verification | | `percent_of_zero_whole_is_none` | 44 | a zero whole, a negative whole and a zero step are `None` for every part and mode; a nonzero part is reached (1 cover). 16.8 s wall, 0.13 s verification | -| `split_ratio_sums` | 44 | a 1 : 2 split's rounded part plus its exact rest is the amount, for positive and negative amounts; a part off the exact share and a negative amount are reached (2 covers). 16.5 s wall, 0.41 s verification | +| `split_ratio_sums` | 44 | a 1 : 2 split at step 3: the rounded part plus its exact rest is the amount and the part is a whole multiple of the step, for positive and negative amounts; a part off the exact share and a negative amount are reached (2 covers). 3.1 s wall, 0.66 s verification | Times: `cargo kani -p ledger-core --exact --harness proofs::ratio::`, the verifier's own verification time and the wall time including Kani's @@ -135,6 +136,9 @@ the exact-quotient lemmas. The model rounds `100 × part` to a multiple of `whole × step` and divides by `whole` (exact, so the quotient is never rounded twice), reusing `Round.near_halfEven`; it does not model `Decimal`'s 28-digit division, which the bridge's exact reference carries. +The model is total where the kernel is partial: `splitRatio_sum` holds at +`a + b = 0` (there is no division), while the kernel returns `None` for +that ratio. No `sorry`; `#print axioms` shows only `propext`, `Quot.sound` and `Classical.choice`. @@ -184,10 +188,9 @@ Left, with why: moves the pin. - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`. - Kani: the three harnesses above. -- The traceability gate against the `k-u6` bookspec branch (patched +- The traceability gate against the merged `k-u6` bookspec branch (patched checker/runner), with `Cargo.lock` restored afterwards: 62 kernel - functions (47 fully backed), 44 law rows, 133 claims sections, 1929 - backticked tokens, 404 source clauses; 15 exceptions, the pinned - skipped set unchanged. + functions (47 fully backed), 44 law rows, 133 claims sections, 1962 + backticked tokens; 15 exceptions, the pinned skipped set unchanged. - bookspec: `lake build`, `lake env lean Audit.lean` (standard axioms), `cargo test --workspace`, `render -- --check`, `scripts/spec-floors.sh main`.