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

+3 -2
View File
@@ -1150,7 +1150,7 @@ impl Direction {
}
/// The direction of a signed amount: paid above zero, received below,
/// neither at zero.
/// neither at zero. SOURCE: BS-partner-3 (the party direction law).
pub fn of<T: Amount>(amount: T) -> Self {
if amount > T::ZERO {
Direction::Paid
@@ -1461,7 +1461,8 @@ impl MonthPart {
}
/// A part's weight in `MONTH_L`ths of a month: `days × (MONTH_L /
/// month_days)`, exactly. `None` for a part no month has.
/// month_days)`, exactly. `None` for a part no month has. SOURCE:
/// BS-asset-1, BS-prepaid-1 (proration by days; laws 26-28).
pub fn part_weight<T: Units>(p: MonthPart) -> Option<T> {
if !p.is_valid() {
return None;
+42 -2
View File
@@ -1288,7 +1288,7 @@ fn constructive_mirrors() {
let (mut fa, mut ta) = ([0i64; M], [0i64; M]);
let (mut fb, mut tb) = ([0i64; M], [0i64; M]);
let a = kernel::constructive(way, &s, &u, &mut fa, &mut ta);
let b = kernel::constructive(way.mirror(), &ns, &nu, &mut fb, &mut tb);
let b = kernel::constructive(kernel::OnBehalf::mirror(way), &ns, &nu, &mut fb, &mut tb);
assert_eq!(a.is_some(), b.is_some());
if a.is_some() {
for k in 0..M {
@@ -1374,6 +1374,25 @@ fn party_target_direction_is_its_sign() {
);
}
/// BS-partner-3: the direction of a signed amount is its sign: paid above
/// zero, received below zero, and neither exactly at zero. This is the
/// classification `party_target` builds its four items on (law 23).
#[kani::proof]
fn direction_of_is_the_sign() {
let amount: i64 = kani::any();
let direction = kernel::Direction::of(amount);
if amount > 0 {
assert_eq!(direction, kernel::Direction::Paid);
} else if amount < 0 {
assert_eq!(direction, kernel::Direction::Received);
} else {
assert_eq!(direction, kernel::Direction::Neither);
}
kani::cover!(amount > 0, "a paid amount");
kani::cover!(amount < 0, "a received amount");
kani::cover!(amount == 0, "nothing moved");
}
/// BS-partner-3 item 3 and BS-ledger-5: the target is odd. Negating the lines negates the
/// capital movement, the money net and the own-account movement, and the
/// property comes from the other side, so it keeps its size: the result
@@ -1426,7 +1445,7 @@ fn reverse_target_is_an_involution() {
};
match kernel::reverse_target(t) {
Some(r) => {
assert_eq!(r.direction, t.direction.flip());
assert_eq!(r.direction, kernel::Direction::flip(t.direction));
assert_eq!(r.amount, -t.amount);
assert_eq!(kernel::reverse_target(r), Some(t));
}
@@ -1475,6 +1494,27 @@ fn any_proration() -> (i64, u32, [MonthPart; PR], usize, i64) {
(total, months, parts, n, unit)
}
/// BS-asset-1 and BS-prepaid-1: a part's weight is its days times the
/// month's share of `MONTH_L` (`days × MONTH_L / month_days`), exactly, and
/// a part no calendar month has is refused. The weight is what the
/// proration charges of laws 26-28 are computed from.
#[kani::proof]
fn part_weight_is_days_of_the_month() {
let days: u32 = kani::any();
let month_days: u32 = kani::any();
kani::assume(days <= 40 && month_days <= 40);
let part = MonthPart { days, month_days };
let got: Option<i64> = kernel::part_weight(part);
if part.is_valid() {
assert_eq!(got, Some(i64::from(days) * i64::from(MONTH_L / month_days)));
} else {
assert_eq!(got, None);
}
kani::cover!(part.is_valid() && days < month_days, "a partial month");
kani::cover!(part.is_valid() && days == month_days, "a whole month");
kani::cover!(!part.is_valid(), "a part no month has");
}
/// The weight of parts, in MONTH_L-ths of a month.
fn weight(parts: &[MonthPart]) -> i64 {
parts
@@ -1747,7 +1747,7 @@ fn every_claim_is_backed() {
}
assert_eq!(
EXCEPTIONS.len(),
16,
14,
"the kernel exception list changes only on purpose"
);
@@ -1876,11 +1876,6 @@ const EXCEPTIONS: &[(&str, &str, &str)] = &[
"a bridge property",
"it maps a three-variant enum with no amount to bridge; engine tests check it",
),
(
"Direction::of",
"a Kani harness, a bridge property and a law",
"it is a three-way sign classification, exercised through `party_target`; no harness or law states it directly",
),
(
"Direction::key",
"a Kani harness, a bridge property and a law",
@@ -1891,11 +1886,6 @@ const EXCEPTIONS: &[(&str, &str, &str)] = &[
"a Kani harness, a bridge property and a law",
"it is a range predicate with no arithmetic; `part_weight` and the proration harnesses exercise it",
),
(
"part_weight",
"a Kani harness, a bridge property and a law",
"it is generic over `Units`, not `Amount`; laws 26-28 are stated through `prorate_by_days`, which calls it",
),
(
"fx_booked_minor",
"a Kani harness and a law",