refactor(core): the kernel and its proofs become modules, one file per sweep unit

kernel.rs is now kernel/: mod.rs keeps the laws and re-exports entries
(the old file, unchanged) plus one file per kernel-sweep unit (U1 fx, U2
round, U3 allocate, U4 total, U5 schedule, U6 ratio, U7 payroll, U8
control). proofs.rs is proofs/: mod.rs holds the original 63 harnesses and
each unit gets a file of its own. tests/kernel_bridge.rs is now
tests/kernel_bridge/main.rs plus one file per unit; Cargo still builds the
single test target named kernel_bridge.

`_kani` now scans proofs/mod.rs and proofs/*.rs and passes the fully
qualified name each file gives its harness (Kani's --exact matches only a
fully qualified name), so a harness resolves wherever it lives. It fails
when kani_slow names no harness, or when two harnesses share a name and
would make the slow list ambiguous; `just prove-list` prints every harness
with its module path and set, showing the slow list resolved without
running it.

Nothing moves in the books: the same 53 fast Kani harnesses and 118 Lean
theorems verify, and the same 1096 tests pass (27 in the bridge).

Docs: verification.md gains the kernel-sweep policy (each unit writes
docs/proofs/<unit>.md; the integrator folds the notes into
verification.md and Audit.lean in one edit per batch), and the file
references in AGENTS.md, testing.md, architecture.md, oracle.md and
spec/rules.md follow the new paths.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 11:30:47 -07:00
1 parent 66d9b7ac54
commit 0cf013b578
36 files changed
+368 -108

No files matched your search

@@ -0,0 +1,5 @@
//! U3: proportional shares, splitting a whole by weights without drift (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
+5
View File
@@ -0,0 +1,5 @@
//! U8: control and aging, what is due or overdue (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
@@ -1,65 +1,6 @@
//! The accounting kernel: the arithmetic every bookkeeping invariant rests
//! on, in one place.
//!
//! Each function here is small, pure, and generic over [`Amount`]. The
//! engine runs it on [`Decimal`]; the Kani harnesses in `proofs.rs` run the
//! very same code on machine integers and prove it correct for every input
//! within their bounds; and the Lean model in `verify/lean` proves the
//! laws it implements hold for books of any size. See
//! `docs/verification.md` for which proof covers which law.
//!
//! The laws, in the order they appear (each traced to its authority in
//! `docs/spec/rules.md`):
//!
//! * a line's signed amount is `+amount` for a debit, `-amount` for a credit
//! (B-2);
//! * an entry is acceptable when it has two or more lines, every amount is
//! positive and in range, and its debits equal its credits exactly (B-1,
//! B-2, B-21);
//! * an acceptable entry nets to zero, account by account summed (B-1);
//! * a reversal flips every side, so it is acceptable exactly when the
//! original is, and the two together net every account to zero (B-9);
//! * an account's balance is its movement read on its normal side, so the
//! balances satisfy the accounting equation whenever movements net to
//! zero (B-5, B-7);
//! * a trial balance puts each movement in exactly one column, so its
//! columns differ by the net of all movements (B-6);
//! * a closing line zeroes the account it closes (B-11);
//! * a payment to a vendor splits, line by line, into what counts toward
//! its 1099, what a card or payment network paid, and what is unknown,
//! and money moved between the company's own sources nets out (B-19);
//! * an early-payment discount never exceeds its stated percentage of the
//! total, and a document line's amount is exactly its quantity times its
//! unit price, neither rounded (B-39);
//! * an allocation's parts sum to the whole, to the last unit, by largest
//! remainder (B-13);
//! * a cumulative allocation hands out exactly the new amount, and leaves
//! each running total one allocation of everything allocated, so it never
//! drifts a unit from its exact share (B-13);
//! * an entry's cash is applied to the sections of the statement of cash
//! flows moving against it, in a fixed order, each up to its own
//! movement: the parts sum to the entry's cash, what no cash settled sums
//! to zero, and a reversal's parts are the original's negated (B-14);
//! * what a member or lender paid or received for the company, with no
//! cash account moving, is split among the kinds it settled, netting to
//! zero, and mirrored by a reversal (B-14 rule 11);
//! * a party's part of an entry is signed as a line on the party's own
//! account would be, a reversal's is its original's negated, and what of
//! it counts as money or as property never exceeds it (B-35);
//! * a span prorated by days (depreciation, B-15; daily schedules, B-16)
//! splits into parts that sum to its total, each but the last its days
//! times the monthly rate within one unit, the last the remainder;
//! * a catch-up run brings the books to the schedule without ever carrying
//! more than it says at a month end already posted (B-15), and a
//! disposal trues what the books carry up or down to the schedule;
//! * an asset's basis figures follow from its basis rule and facts: the
//! §723 basis is the contributor's adjusted basis, the depreciable basis
//! the cost, that basis, or the lesser of it and fair market value, and
//! the §704(c) built-in gain is fair market value less the §723 basis
//! (B-25);
//! * a tax category's deductible amount adds its accounts' exact shares and
//! rounds once to the cent, half away from zero, never share by share
//! (B-32, B-21).
//! The entry arithmetic: signing, validating, netting, reversing and
//! grouping the lines of an entry or a book, unchanged in U0. The laws it
//! serves are listed at the module root, [`super`].
use crate::assets::BasisRule;
use crate::{AccountType, Side};
+5
View File
@@ -0,0 +1,5 @@
//! U1: foreign-currency conversion, the booking of a foreign amount at the transaction-date rate (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
+98
View File
@@ -0,0 +1,98 @@
//! The accounting kernel: the arithmetic every bookkeeping invariant rests
//! on, in one place.
//!
//! Each function here is small, pure, and generic over [`Amount`]. The
//! engine runs it on [`rust_decimal::Decimal`]; the Kani harnesses in `proofs/` run the
//! very same code on machine integers and prove it correct for every input
//! within their bounds; and the Lean model in `verify/lean` proves the
//! laws it implements hold for books of any size. See
//! `docs/verification.md` for which proof covers which law.
//!
//! The laws, in the order they appear (each traced to its authority in
//! `docs/spec/rules.md`):
//!
//! * a line's signed amount is `+amount` for a debit, `-amount` for a credit
//! (B-2);
//! * an entry is acceptable when it has two or more lines, every amount is
//! positive and in range, and its debits equal its credits exactly (B-1,
//! B-2, B-21);
//! * an acceptable entry nets to zero, account by account summed (B-1);
//! * a reversal flips every side, so it is acceptable exactly when the
//! original is, and the two together net every account to zero (B-9);
//! * an account's balance is its movement read on its normal side, so the
//! balances satisfy the accounting equation whenever movements net to
//! zero (B-5, B-7);
//! * a trial balance puts each movement in exactly one column, so its
//! columns differ by the net of all movements (B-6);
//! * a closing line zeroes the account it closes (B-11);
//! * a payment to a vendor splits, line by line, into what counts toward
//! its 1099, what a card or payment network paid, and what is unknown,
//! and money moved between the company's own sources nets out (B-19);
//! * an early-payment discount never exceeds its stated percentage of the
//! total, and a document line's amount is exactly its quantity times its
//! unit price, neither rounded (B-39);
//! * an allocation's parts sum to the whole, to the last unit, by largest
//! remainder (B-13);
//! * a cumulative allocation hands out exactly the new amount, and leaves
//! each running total one allocation of everything allocated, so it never
//! drifts a unit from its exact share (B-13);
//! * an entry's cash is applied to the sections of the statement of cash
//! flows moving against it, in a fixed order, each up to its own
//! movement: the parts sum to the entry's cash, what no cash settled sums
//! to zero, and a reversal's parts are the original's negated (B-14);
//! * what a member or lender paid or received for the company, with no
//! cash account moving, is split among the kinds it settled, netting to
//! zero, and mirrored by a reversal (B-14 rule 11);
//! * a party's part of an entry is signed as a line on the party's own
//! account would be, a reversal's is its original's negated, and what of
//! it counts as money or as property never exceeds it (B-35);
//! * a span prorated by days (depreciation, B-15; daily schedules, B-16)
//! splits into parts that sum to its total, each but the last its days
//! times the monthly rate within one unit, the last the remainder;
//! * a catch-up run brings the books to the schedule without ever carrying
//! more than it says at a month end already posted (B-15), and a
//! disposal trues what the books carry up or down to the schedule;
//! * an asset's basis figures follow from its basis rule and facts: the
//! §723 basis is the contributor's adjusted basis, the depreciable basis
//! the cost, that basis, or the lesser of it and fair market value, and
//! the §704(c) built-in gain is fair market value less the §723 basis
//! (B-25);
//! * a tax category's deductible amount adds its accounts' exact shares and
//! rounds once to the cent, half away from zero, never share by share
//! (B-32, B-21).
//!
//! The kernel is a module directory so each kernel-sweep unit adds its
//! arithmetic in a file of its own (`fx`, `round`, `allocate`, `total`,
//! `schedule`, `ratio`, `payroll`, `control`) and the entries above stay
//! in `entries`. Only this file declares the modules; the units never edit
//! it, and every path still resolves as `crate::kernel::foo`.
mod allocate;
mod control;
mod entries;
mod fx;
mod payroll;
mod ratio;
mod round;
mod schedule;
mod total;
// The unit modules are empty until their sweep unit lands; re-exporting
// them now is what keeps every `crate::kernel::foo` path in place.
#[allow(unused_imports)]
pub use allocate::*;
#[allow(unused_imports)]
pub use control::*;
pub use entries::*;
#[allow(unused_imports)]
pub use fx::*;
#[allow(unused_imports)]
pub use payroll::*;
#[allow(unused_imports)]
pub use ratio::*;
#[allow(unused_imports)]
pub use round::*;
#[allow(unused_imports)]
pub use schedule::*;
#[allow(unused_imports)]
pub use total::*;
+5
View File
@@ -0,0 +1,5 @@
//! U7: payroll arithmetic, withholding and employer taxes (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
+5
View File
@@ -0,0 +1,5 @@
//! U6: ratios, percentages and averages that reports show (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
+5
View File
@@ -0,0 +1,5 @@
//! U2: one rounding primitive, the single place money is rounded to a step (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
@@ -0,0 +1,5 @@
//! U5: schedule plans, the monthly charge a schedule books (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
+5
View File
@@ -0,0 +1,5 @@
//! U4: totals, exact checked sums for books and reports (kernel sweep).
//!
//! Empty in U0: the unit adds its arithmetic here, in this file alone, so
//! no two sweep units ever edit the same file. The module root re-exports
//! it, keeping every path `crate::kernel::foo`.
@@ -0,0 +1,5 @@
//! U3 proof harnesses: proportional shares (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
+5
View File
@@ -0,0 +1,5 @@
//! U8 proof harnesses: control and aging (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
+5
View File
@@ -0,0 +1,5 @@
//! U1 proof harnesses: foreign-currency conversion (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
@@ -19,6 +19,18 @@
//! for any number of parts and any sizes (docs/verification.md says
//! which, and how it ties to the kernel's formula).
// One file per kernel-sweep unit; the harnesses above stay here. `just
// prove` scans every file in this directory, so a new harness only needs
// its own file and no edit to this one.
mod allocate;
mod control;
mod fx;
mod payroll;
mod ratio;
mod round;
mod schedule;
mod total;
use crate::kernel::{self, Amount, LineError, MONTH_L, MonthPart};
use crate::{AccountType, Side};
+5
View File
@@ -0,0 +1,5 @@
//! U7 proof harnesses: payroll arithmetic (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
+5
View File
@@ -0,0 +1,5 @@
//! U6 proof harnesses: ratios (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
+5
View File
@@ -0,0 +1,5 @@
//! U2 proof harnesses: the rounding primitive (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
@@ -0,0 +1,5 @@
//! U5 proof harnesses: schedule plans (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.
+5
View File
@@ -0,0 +1,5 @@
//! U4 proof harnesses: exact totals (kernel sweep).
//!
//! Empty in U0: the unit adds its Kani harnesses here; `just prove` scans
//! every file in `proofs/`, so a harness needs no change to the module
//! root or the recipe.