rust_decimal's checked_add and checked_mul return None only when the integer part overflows. When the exact result needs more than 96 bits of mantissa, or a scale past 28, they round it and return Some: MAX + 0.4 is Some(MAX) (K-U4), 0.01 + 792281625142643375935439503.35 is ...503.4 (K-U8), 1050000010.0000000001 x 9.9999999999 is 10500000099.895 where the exact product is 10500000099.89499999999999999999 (K-U1), and 123456789.0123456789 squared loses its last digits (K-U3). The kernel's contract is exact or None, and BS-ledger-1 says a product the arithmetic cannot hold MUST be refused. impl Amount for Decimal now runs rust_decimal's operation and checks, in 256-bit integers (kernel/decimal_exact.rs), that the figure equals the exact sum or product as a rational; otherwise None. It builds no rounded figure of its own, and an exact result is returned as rust_decimal gave it, scale and all, so nothing exact moves. Comparing values is complete where the K-U10 row's "result scale fell below the operands'" test is not: 100 x 0.3333333333333333333333333333 is exact with a full-scale mantissa past 96 bits (trailing zeros), and percent_of computes it for every ratio. checked_sub is rust_decimal's subtraction under the same check (the trait default gave -0 for 0 - 0). Money::checked_add and checked_sub go through Amount; sum_exact*, add_exact and sub_exact already did. Two products could not simply become exact, and the suite found both: - Shares multiply a cent amount by a many-place percent (33.333333333333333333333333333, 27 places) and then divide, which rounds anyway (spec_cash_flow's government payment). They use the new Amount::checked_mul_rounded, rust_decimal's own product, so every share is the figure it always was. - A foreign amount at a rate (fx_booked) rounds once, from the exact product: Amount::checked_mul_round_to_step holds it in 256 bits, cuts it only as far as Decimal needs with a sticky digit for what was cut, and rounds with round_step. The one posted-range figure that moves is the one the old double rounding got wrong: 1050000010.0000000001 x 9.9999999999 books 10500000099.89, the exact product's cent, not 10500000099.90. checked_div and checked_div_exact are unchanged. Inherent Decimal::checked_* calls outside the kernel are listed in docs/proofs/k-u10.md and not converted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Proof notes for the kernel sweep
docs/verification.md is the one place the proofs are described: the law
table, the bounds, the times, and what is and isn't proved. The kernel
sweep (plan/kernel-sweep-audit.md) runs several units in parallel, so
editing that file from every branch would collide on every hunk. The rule
instead:
- Each unit that adds proofs writes
docs/proofs/<unit>.md, where<unit>is the lowercase name of its code files (fx,round,allocate,total,schedule,ratio,payroll,control;U9display adds no proofs). The note lists, for that unit:- every Kani harness it added, with the law each proves;
- the bounds Kani explores (lines, accounts, amounts, scales), and why they are enough;
- the measured time, alone or in a
just proverun, with the machine and date; - every bridge property in
tests/kernel_bridge/<unit>.rs, and every 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. 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 axiomsline in bookspec'slean/Audit.lean. Wanderbooks keeps no audit list of its own;just proveaudits 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 fnwhose 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 ownSOURCE: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
prove-slow.