Merge branch 'main' into t3/k-u3-kernel-shares

This commit is contained in:
swaits committed 2026-11-09 01:05:05 -07:00
commit 73879044b2
44 files changed
+3908 -241

No files matched your search

+26 -4
View File
@@ -19,13 +19,35 @@ instead:
Lean theorem it added;
- anything the solver could not do, and what carries it instead (Lean
at any size, a bridge property, an exhaustive unit test).
- **Workers do not edit `docs/verification.md` or `verify/lean/Audit.lean`.**
The integrator folds the unit notes into `verification.md`'s tables and
prose, and adds the `#print axioms` lines to `Audit.lean` in one place,
in one edit per batch, after the batch's merges.
- **Workers do not edit `docs/verification.md`.** The integrator folds
the unit notes into its tables and prose in one edit per batch, after
the batch's merges.
- **A unit's Lean theorems go into bookspec**, on the unit's bookspec
branch: the theorem in `lean/Bookspec/`, its `#print axioms` line in
bookspec's `lean/Audit.lean`. Wanderbooks keeps no audit list of its
own; `just prove` audits bookspec's, from the pinned package (D-69).
- A unit's note lands in the same commit as its harnesses, so the proof
and its description are never apart in history.
## The harness-to-law table (machine-readable)
The traceability gate
(`crates/ledger-core/tests/bookspec/traceability.rs`) reads every note here
for a table pairing each Kani harness with the bookspec law it proves:
| Harness | Law |
|---|---|
| `round_step_is_multiple` | 40 |
The first cell must be the harness name in backticks and the second a bare
integer (the number in bookspec's `spec/laws.md`); extra columns are allowed
after them (bounds, time, verification). The gate fails:
- a kernel `pub fn` whose harnesses have no such row ("lacks a law");
- a harness listed twice with different law numbers;
- a law whose Rules column shares no `BS-` id with the function's own
`SOURCE:` line, when the function has one.
`just prove` finds the harnesses by scanning `crates/ledger-core/src/proofs/`
(`mod.rs` plus every `<unit>.rs`), not one file; `just prove-list` prints
each harness, its module path, and whether it runs in `prove` or
+58
View File
@@ -0,0 +1,58 @@
# Entries: the party direction and a part's weight
Status: landed 2026-11-08 with the traceability gate's review fixes. Two
kernel functions that had no proof of their own now have one; both were on
the exception list before.
## The functions
| Function | Meaning |
|---|---|
| `kernel::Direction::of` | the direction of a signed amount: paid above zero, received below zero, neither at zero (BS-partner-3) |
| `kernel::part_weight` | a month part's weight in `MONTH_L`ths: `days × MONTH_L / month_days`, exactly; `None` for a part no calendar month has (BS-asset-1, BS-prepaid-1) |
## Kani harnesses (`crates/ledger-core/src/proofs/mod.rs`)
| Harness | Law | Bounds |
|---|---|---|
| `direction_of_is_the_sign` | 23 | any `i64` amount; all three signs covered |
| `part_weight_is_days_of_the_month` | 27 | `days` and `month_days` 0..=40; valid, partial, whole and invalid parts covered |
`part_weight_is_days_of_the_month` proves the weight formula a proration
charge is computed from, which is law 27's statement (each part but the
last is its days times the monthly rate); it is a lemma for laws 26-28,
not a restatement of law 26 (that the parts sum to the total, which is
`prorate_parts_sum_to_total` below).
The bookspec law each harness proves (machine-readable for the
traceability gate, `crates/ledger-core/tests/bookspec/traceability.rs`):
| Harness | Law |
|---|---|
| `direction_of_is_the_sign` | 23 |
| `part_weight_is_days_of_the_month` | 27 |
Times: measured alone with
`cargo kani -p ledger-core --exact --harness proofs::<name>` on 2026-11-08:
`direction_of_is_the_sign` 18 s wall (0.06 s verification, 3 covers, build
included); `part_weight_is_days_of_the_month` 11 s wall (0.49 s
verification, 3 covers, build included).
## Bridge (`crates/ledger-core/tests/kernel_bridge/entries.rs`)
- `direction_of_agrees`: `Direction::of` classifies the same sign at `i64`
and `Decimal`, and each case keeps its meaning (law 23).
- `part_weight_agrees`: `part_weight` is the same weight at `i32`, `i64`
and `i128`, and `None` exactly for a part no month has (laws 26-28).
- `reverse_target_agrees`: `reverse_target` is the exact opposite at both
types. The edge strategy reaches `i64::MIN`, which `i64` refuses because
no negation can hold it; `Decimal` can hold the negation, so the property
compares its answer there (the exact opposite). The refusal is the
integer proof model's bound, not the law's. The earlier bridge only
passed it to `and_then`, which is a mention, not a call; this property
calls it.
Why these laws: `Direction::of` is the sign classification the party
direction law (23) is stated over, and `part_weight` is the weight the
proration charges of laws 26-28 are computed from, its harness numbered
for the law it restates most closely (27).
+10
View File
@@ -88,6 +88,16 @@ carries the same laws to every `Decimal` step, and Lean to any step.
| `fx_booked_positive_for_positive` | positive inputs book non-negative, positive once the product reaches half a unit | 3.2 s (2 covers) |
| `fx_booked_refuses_overflow` | an overflowing product and a non-positive rate are `None`, never a panic | 2.6 s (2 covers) |
The bookspec law each harness proves (machine-readable for the
traceability gate, `crates/ledger-core/tests/bookspec/traceability.rs`):
| Harness | Law |
|---|---|
| `fx_booked_is_whole_unit` | 41 |
| `fx_booked_within_half_unit` | 41 |
| `fx_booked_positive_for_positive` | 41 |
| `fx_booked_refuses_overflow` | 41 |
What the harnesses do and do not prove, stated plainly:
- `fx_booked_refuses_overflow` proves **two concrete overflow cases**
+15
View File
@@ -54,6 +54,21 @@ bookspec's Lean proves them for any step.
| `round_step_sign_preserved` | every mode: `0 <= x` gives `0 <= r`, `x <= 0` gives `r <= 0` | 13 s wall incl. build (3 covers) |
| `round_step_refuses_nonpositive_step` | a step of zero or less is `None` | 8 s total (1 cover) |
The bookspec law each harness proves (machine-readable for the
traceability gate, `crates/ledger-core/tests/bookspec/traceability.rs`):
| Harness | Law |
|---|---|
| `round_step_is_multiple` | 40 |
| `round_step_is_nearest` | 40 |
| `round_step_ties` | 40 |
| `round_step_is_idempotent` | 40 |
| `round_step_never_negative_zero` | 40 |
| `round_step_toward_zero_bounds` | 40 |
| `round_step_toward_neg_inf_is_floor` | 40 |
| `round_step_sign_preserved` | 40 |
| `round_step_refuses_nonpositive_step` | 40 |
The three directed-mode harnesses were added after review: the spec block's
invariants 3, 4 and 6 had no proof of their own (Lean had the ties, Kani
checked these two modes only at exact ties). Demonstrated: with
+12
View File
@@ -34,6 +34,18 @@ model-checking/kani#4904), each with `kani::cover!`.
| `total_try_is_map_sum` | `total_try` of differences is the sum of the differences; a failing map fails the total | 0..=4 pairs, in-range | 5.3 s |
| `total_overflow_is_none` | for two arbitrary `i64`s, `total` is `Some` exactly when the true sum fits; both overflow directions covered | all `i64` pairs | 0.5 s |
The bookspec law each harness proves (machine-readable for the
traceability gate, `crates/ledger-core/tests/bookspec/traceability.rs`):
| Harness | Law |
|---|---|
| `total_empty_is_zero` | 4 |
| `total_append` | 4 |
| `total_is_sound` | 4 |
| `total_of_is_map_sum` | 4 |
| `total_try_is_map_sum` | 4 |
| `total_overflow_is_none` | 4 |
Times: alone, `cargo kani --exact --harness`, the shared dev machine under
`nice -n 10`, 2026-11-08. `total_append` was 115 s at runs of up to 4 and
was reduced to up to 3 (the same law; 60 s) to keep `just prove` fast. A