fix(proofs): K-U7's overflow harness takes i64::MIN, with the native subtraction
K-U7 and K-U8 found the same thing from two sides: the integer model's subtraction negated the subtrahend first, so x - i64::MIN was refused where it fits. K-U7 assumed the minimum away and asserted the refusal; K-U8 made i64 and i32 subtract natively. With both merged the assumption goes: the harness ranges over the whole i64 domain, minimum included, and asserts -1 - i64::MIN = i64::MAX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8aa0ed985d
commit
4da1c5b30f
2 files changed
+11
-17
No files matched your search
@@ -97,28 +97,22 @@ fn any_employee() -> Employee {
|
||||
|
||||
/// `net_pay` is `None` exactly when some running difference leaves the
|
||||
/// `i64` range, and otherwise the exact result: gross and five
|
||||
/// deductions over the whole `i64` range, checked against an `i128`
|
||||
/// running difference (which cannot overflow here) at every prefix.
|
||||
///
|
||||
/// The one exception is the `i64` instantiation's own: `Amount`'s
|
||||
/// `checked_sub` negates the subtrahend first, and `i64::MIN` has no
|
||||
/// negation, so a deduction of exactly `i64::MIN` is refused even where
|
||||
/// the difference would fit (`-1 - i64::MIN`). That is conservative (a
|
||||
/// refusal, never a wrong figure), and `Decimal`'s range is symmetric,
|
||||
/// so it does not arise in the engine; the harness assumes no deduction
|
||||
/// is `i64::MIN` and asserts the refusal at the fixed case.
|
||||
/// deductions over the whole `i64` range, `i64::MIN` included, checked
|
||||
/// against an `i128` running difference (which cannot overflow here) at
|
||||
/// every prefix. (`Amount` for `i64` subtracts natively since K-U8: the
|
||||
/// default negated the subtrahend first, refusing `-1 - i64::MIN`, which
|
||||
/// fits; this harness and K-U8's both found it.)
|
||||
#[kani::proof]
|
||||
fn net_pay_none_iff_a_prefix_overflows() {
|
||||
let gross: i64 = kani::any();
|
||||
let mut deductions = [0i64; DEDUCTIONS];
|
||||
for deduction in &mut deductions {
|
||||
let d: i64 = kani::any();
|
||||
kani::assume(d != i64::MIN);
|
||||
*deduction = d;
|
||||
*deduction = kani::any();
|
||||
}
|
||||
assert!(
|
||||
net_pay(-1i64, &[i64::MIN]).is_none(),
|
||||
"i64::MIN has no negation: refused, conservatively"
|
||||
assert_eq!(
|
||||
net_pay(-1i64, &[i64::MIN]),
|
||||
Some(i64::MAX),
|
||||
"-1 - i64::MIN fits: the native subtraction answers it"
|
||||
);
|
||||
let mut running = i128::from(gross);
|
||||
let mut overflowed = false;
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ positive).
|
||||
| Harness | Law | Verification |
|
||||
|---|---|---|
|
||||
| `net_pay_is_gross_less_deductions` | 45 | net equals gross less the deductions' `total`, for deductions of either sign; withholdings exceeding gross and a negative net are reached, and `i64::MAX`/`MIN` past the range are `None` (2 covers). 19.5 s verification |
|
||||
| `net_pay_none_iff_a_prefix_overflows` | 45 | gross and five deductions over the whole `i64` range: `None` exactly when some running difference (gross less the first k deductions, in `i128`) leaves the `i64` range, otherwise exactly the `i128` result; both branches reached (2 covers). 4.4 s verification (24.6 s wall). `i64::MIN` as a deduction is assumed away and its refusal asserted at a fixed case: `Amount::checked_sub` negates first and `i64::MIN` has no negation, so it is refused where `-1 - i64::MIN` would fit (conservative; `Decimal` is symmetric) |
|
||||
| `net_pay_none_iff_a_prefix_overflows` | 45 | gross and five deductions over the whole `i64` range: `None` exactly when some running difference (gross less the first k deductions, in `i128`) leaves the `i64` range, otherwise exactly the `i128` result; both branches reached (2 covers). 4.4 s verification (24.6 s wall). `i64::MIN` included: `Amount` for `i64` subtracts natively since K-U8 (the default negated first and refused `-1 - i64::MIN`, which fits; K-U7's and K-U8's harnesses both found it), and the harness asserts `net_pay(-1, [i64::MIN]) = Some(i64::MAX)` |
|
||||
| `net_pay_nonnegative_when` | 45 | non-negative deductions summing to at most gross give exactly gross less their sum, never negative; a zero net and a partial withholding are reached (2 covers). 21.9 s wall, 7.0 s verification |
|
||||
| `payroll_plan_balances` | 45 | one employee: the eight totals `payroll_entry_plan` posts pass `check_lines` (two or more lines, every amount positive and in range, debits equal credits); a net of exactly one unit, payables holding the employer shares alone (a zero employee Social Security and Medicare withholding) and a posted federal or state withholding are reached (3 covers, each able to fail under the assumes). 142 s wall, 135.5 s verification (2026-11-09, machine load average about 18; 62.0 s verification earlier, unloaded). The harness rebuilds the eight totals on `i64` rather than calling `payroll_entry_plan` (that works in `Decimal`/`Money` and maps accounts, neither generic over `Amount`): it proves the arithmetic the plan is made of and `check_lines` accepting that shape, while the assembly is checked by `payroll_entry_plan`'s tests, the goldens and `check_lines` on every posted entry. Two employees timed out in CBMC (over 80 minutes, killed): sixteen symbolic figures into eight totals. Kani covers one employee; Lean's `payroll_run_net_eq` and `payroll_run_plan_balances` carry any number of employees (see Lean below) |
|
||||
|
||||
|
||||
Reference in new issue
Block a user