test(core): Kani for Direction::of and part_weight

Both were exceptions for lacking all three backing kinds; neither is a
wrapper or an enum map. `Direction::of` is the sign classification the
party direction law is stated over (law 23), and `part_weight` is the
weight the proration charges are computed from (laws 26-28).

- `direction_of_is_the_sign` explores any `i64` and covers paid,
  received and neither (`kani::cover!`).
- `part_weight_is_days_of_the_month` explores `days` and `month_days`
  up to 40 and covers a partial month, a whole month and an invalid
  part.
- each spec block now carries its `SOURCE:` line, so the gate's
  right-law check applies to them.
- `docs/proofs/entries.md` records each harness's law in the
  machine-readable table; the exception list drops from 16 to 14
  (`Direction::key` and `MonthPart::is_valid` stay, with their reasons).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 21:54:10 -07:00
1 parent 6f2e2cf1eb
commit 080a3ffbf5
4 files changed
+94 -15

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
# 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` | 26 | `days` and `month_days` 0..=40; valid, partial, whole and invalid parts covered |
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` | 26 |
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 and refuses the same out-of-range inputs (law 24). 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.