1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//! FJ-041: Kani bounded model checking proofs for idempotency.
//!
//! These proofs verify core invariants using Kani's bounded model checker.
//! Run with: `cargo kani --harness <name>`
//!
//! Each proof demonstrates that `apply(apply(s)) == apply(s)` for a given
//! resource handler — the fundamental idempotency contract.
//!
//! Proofs are gated behind `#[cfg(kani)]` so normal `cargo build` ignores them.
//!
//! ## Bounded Model Harnesses (FJ-2201)
//!
//! These are **bounded-model harnesses** that call real functions with
//! bounded nondeterministic inputs. They prove properties hold within
//! the bound, not exhaustively over all inputs.
//! - `proof_dag_ordering_bounded` — 3-node DAG determinism
//!
//! ## Production Function Proofs (FJ-2201)
//!
//! These call REAL production functions with no abstract models:
//! - `proof_mutation_grade_monotonic` — `MutationScore::grade()` monotonicity
//! - `proof_mutation_grade_valid` — `grade()` returns only {A,B,C,F}
//! - `proof_mutation_score_pct_bounded` — `score_pct()` in [0,100]
//! - `proof_convergence_pass_rate_bounded` — `pass_rate()` in [0,100]
//! - `proof_applicable_operators_valid` — operator applicability invariant
//!
//! ## Proof Assumptions
//!
//! | Proof | Assumes | Verifies |
//! |-------|---------|----------|
//! ## Seven harnesses removed 2026-08-17 (GH-242) — measured, not assumed
//!
//! Every one of them reached a real BLAKE3 hash, and all seven failed with
//! `call to foreign "C" function syscall is not currently supported by Kani`
//! (blake3 does runtime CPU-feature dispatch). None had ever produced a
//! verdict, while `contracts/*.yaml` cited them as evidence.
//!
//! Three said nothing worth fixing:
//!
//! - `proof_blake3_idempotency` — `hash(x) == hash(x)`. A property of the
//! `blake3` crate, and a tautology at that.
//! - `proof_blake3_collision_resistance` — collision resistance is not
//! establishable by bounded model checking, and the harness hedged about its
//! own conclusion in a comment. GH-248's defect in a different hat.
//! - `proof_converged_state_is_noop` — hashed the SAME content twice and
//! asserted the results matched. Its doc claimed "the core idempotency
//! property"; it proved the hash function is a function.
//!
//! Four made real claims about `hash_desired_state` (determinism, planner
//! idempotency, per-type handler invariants) but **cannot be discharged by a
//! model checker**, because discharging them means verifying through a
//! cryptographic hash. Measured on this box before removing them:
//!
//! ```text
//! blake3 default (SIMD dispatch) fails instantly: foreign "C" syscall
//! blake3 `pure` (portable Rust) 29.1 GB RSS, still running at 36 min
//! ```
//!
//! Stubbing the hash was the other option and was rejected: it would prove the
//! properties hold for the stub, which is not the claim. Those four properties
//! are asserted executably instead — see
//! `src/core/planner/tests_hash_source.rs`
//! (`identical_source_content_hashes_identically` and neighbours), plus the
//! `debug_assert_eq!` determinism postcondition inside `hash_desired_state`
//! itself.
//!
//! Removing a proof that could not fail is not weakening the gate. It is
//! deleting something that read as evidence and was not.
//!
//! | `proof_status_transition_monotonic` | Status ∈ {0,1,2,3} | Converged stays converged |
//! | `proof_plan_determinism` | ≤3 resources | Same input → same plan |
//! | `proof_topo_sort_stability` | 3-node DAG | Deterministic ordering |
/// Resource status transitions: Converged state does not regress to Pending.
/// Plan determinism: same config + same state always produces same plan.
/// Topological sort stability: same DAG always produces same order.
pub
pub
pub
pub
// ── Bounded-Model Harnesses (FJ-2201) ──────────────────────────────
//
// These harnesses operate on actual types with bounded nondeterministic
// inputs. They call real functions but with constrained state space.
/// FJ-2201: DAG ordering determinism.
///
/// Verifies `build_execution_order` on a fixed config produces the same
/// result on two calls. Models deterministic Kahn's algorithm with
/// alphabetical tie-breaking.
// ── OCI Layer / Store Proofs (FJ-2201) ──────────────────────────────
/// FJ-2201: Layer build determinism — same files produce same digest.
///
/// Models the layer construction pipeline: files → tar → compress → digest.
/// Same input files in same order must produce the same digest.
// FJ-2201 `proof_store_idempotency` REMOVED (GH-242). It was a tautology that
// consumed 96% of the proof budget.
//
// The body computed one expression twice and asserted the halves equal:
//
// let addr1 = content.wrapping_mul(2654435761); // "model hash"
// let addr2 = content.wrapping_mul(2654435761); // the same expression
// assert_eq!(addr1, addr2);
// let stored = addr1; let re_stored = addr2;
// assert_eq!(stored, re_stored); // and again
//
// In Rust `f(x) == f(x)` cannot fail, so this proved `x == x`. It touched no
// production code — the hash was hand-written, and the comment said so.
//
// Measured 2026-08-16, per-harness, from the CI log:
//
// proof_store_idempotency 4996s (83 minutes)
// next slowest 37s
// median across 23 harnesses 3s
//
// 83 of the 86 measured minutes, and the reason the 150-minute job never
// reached the end of the suite. CBMC models symbolic 32-bit multiplication as a
// large bit-vector formula, twice, to conclude that a value equals itself.
//
// It is deleted rather than retargeted because it cannot be made meaningful in
// place: any assertion over a locally-computed model is a tautology, and the
// REAL store address function (`composite_hash` via `store_path`) allocates, so
// driving it here reproduces the intractability that
// `proof_disk_budget_hysteresis_total` and `proof_applicable_operators_valid`
// were both fixed for.
//
// The property it claimed to cover is tested where it can actually fail, by
// executing the real function: `tests/falsification_composite_hash_injectivity.rs`
// (GH-235) checks determinism AND injectivity of the true address function over
// real inputs, including the collision this file's model could never have
// detected.
// ── Verus-Style Conditional Proofs (FJ-2202) ────────────────────────
//
// These model the real dual-hash system: plan-time hash vs executor hash.
// The handler invariant states: forall h. handler(h).stored_hash == hash_desired_state(h).
// Under this invariant, the idempotency property holds.
/// FJ-2202: Conditional idempotency — converged + handler invariant → NoOp.
///
/// Models the real planner logic: if status == Converged and the handler
/// invariant holds (stored hash == hash_desired_state), next plan is NoOp.
/// FJ-2202: Fleet convergence — N resources all converge independently.
///
/// Models N resources (bounded to 4): if each has handler invariant and
/// is converged, the entire fleet plan is all-NoOp.
/// FJ-2202: Apply-then-NoOp — after apply, next plan must be NoOp.
///
/// Models: apply stores hash_desired_state as the lock hash.
/// Under handler invariant, re-planning produces NoOp.