agent-formal-verify 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +34 -0
- package/package.json +1 -1
- package/skills/formal-verify/SKILL.md +15 -7
- package/skills/formal-verify/examples/kani-template/src/lib.rs +6 -0
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.lean +16 -4
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.mutations +1 -1
- package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.statements +14 -0
- package/skills/formal-verify/references/lean-brief.md +22 -5
- package/skills/formal-verify/references/rust-brief.md +5 -3
- package/skills/formal-verify/references/setup.md +1 -1
- package/skills/formal-verify/references/tla-brief.md +1 -1
- package/skills/formal-verify/scripts/baseline.py +472 -0
- package/skills/formal-verify/scripts/kani.py +37 -0
- package/skills/formal-verify/scripts/lean-check.sh +88 -9
- package/skills/formal-verify/scripts/lean-mutations.lean +95 -0
- package/skills/formal-verify/scripts/lean-replay.lean +19 -0
- package/skills/formal-verify/scripts/lean-statements.py +61 -39
- package/skills/formal-verify/scripts/lean-tools.sh +9 -0
- package/skills/formal-verify/scripts/mutate.py +259 -158
- package/skills/formal-verify/scripts/tlc-matrix.sh +4 -167
- package/skills/formal-verify/scripts/tlc.py +328 -0
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 0.4.10 - baselines keep each check's run and each Kani constraint's function
|
|
4
|
+
|
|
5
|
+
The specification baseline now records the checks that apply to each TLA+ run and the inputs selected by each reach check. Moving check lines below a run or changing which run a reach check selects no longer compares unchanged. Kani assumptions, covers and stubs now retain their qualified owning function, and harness names include their modules, so moving a constraint between functions is reported. The Rust reader supports free functions under inline modules and rejects Kani forms in an owner it cannot identify, including macro definitions and implementation or trait bodies. Baseline records use format 2; create a new record after updating rather than reuse a format 1 record.
|
|
6
|
+
|
|
7
|
+
## 0.4.9 - a specification baseline, Lean kernel replay and checked witnesses
|
|
8
|
+
|
|
9
|
+
The specification baseline now preserves whitespace and comment markers inside string literals, so edits to those parts of TLA+ properties and Kani assumptions are reported as changes. Lean kernel replay now selects exact modules and their project imports, leaving out cached objects from deleted, unimported descendants.
|
|
10
|
+
|
|
11
|
+
The Lean checker now replays every built module, and every project module it imports, through the Lean kernel with the pinned toolchain's `leanchecker`, after its existing checks. A declaration that a command added to the environment without a kernel check used to pass the build and the audit. The replay rejects it, and the checker exits 1 with `leanchecker`'s output. A pin that ships no `leanchecker`, such as Lean 4.20.0, prints `UNAVAILABLE kernel replay` and still passes. The PASS line says whether the replay passed or was unavailable.
|
|
12
|
+
|
|
13
|
+
The Lean checker now checks hypothesis witnesses. For a public theorem with hypotheses, a `private theorem <Property>.witness` in the same file proves that some values satisfy all of them at once. The checker derives the statement such a witness must prove from the property on every run. It prints the statement when the witness is missing or states something else, and fails only in the second case. Each property gets a WITNESS line, and the PASS line counts witnesses checked, absent and unavailable. The Lean brief no longer accepts an `example` as a witness. The Lean template now proves a witness for each of its two theorems with hypotheses. Its statements are re-frozen to record them, and no existing fingerprint changed. The mutation runner does not count a failing witness as a detection, so a mutation that breaks only a witness reads MISSED, and it does not list a public witness as UNCOVERED.
|
|
14
|
+
|
|
15
|
+
A new helper, `baseline.py`, records what each existing model specifies before the modelling agents run and names each part that changed afterwards. For a TLA+ matrix it records the matrix lines and the definitions of `Spec`, of the initial state, of the checked and reach operators, and of the operators they reference, but not the actions that `Spec` names under `[][...]_vars`, `WF_` or `SF_`. A column-0 definition whose header it cannot read, such as an infix operator, is recorded whether or not a property references it. For a Lean model it records the `.statements` file, and for a Kani harness file each harness name, assumption (`kani::assume` or `kani::any_where`), cover and stub, including those under `cfg_attr(kani, ...)`. A removed or changed item fails the comparison, and so does an added Kani assumption or stub. A Kani assumption, cover, stub or harness attribute in a form the helper cannot read, such as an import that renames `kani::assume`, fails the record instead of going unrecorded. An added Lean declaration, TLA+ check or run, or Kani cover or harness does not. The skill's main thread now runs this comparison where it used to read `git diff` for those changes, and records an accepted specification correction again with its old and new digests. `git diff` still covers what the record leaves out, such as a theorem newly marked `private` or a removed assertion in a Kani harness. The record keeps cooperative agents to their briefs; it does not stop an agent that edits it, and the skill says so.
|
|
16
|
+
|
|
17
|
+
Rust mutation runs now preserve the crate's workspace and local path dependencies in their temporary copies. Copying only the harness crate left sibling dependencies and inherited workspace settings behind, so a harness that passed the checker could fail mutation testing before Kani checked its property. The runner uses the bundled Cargo to find the required workspaces and packages, including transitive and optional path dependencies.
|
|
18
|
+
|
|
19
|
+
Lean mutation coverage now reads declaration identities and source ranges from the pinned Lean frontend. Indented public theorems remain covered, and equal short names in different namespaces remain separate targets. Structure and class projections and instance declarations are not property targets, including local and scoped instances. Wrapped guards and examples remain detectable, and their reported locations refer to the original model. Guard and example failures cannot cover named theorems; errors outside recognized properties are rejected. The runner checks that the original module elaborates before testing mutations.
|
|
20
|
+
|
|
21
|
+
A Lean mutation that changed a theorem's statement used to count as breaking its proof. Renaming a definition that a statement names makes the statement fail to elaborate, or makes Lean bind the old name as an automatic implicit variable so that only the proof fails. The runner printed DETECTED for both and counted the theorem as covered, although Lean checked no proof of the frozen statement against the mutated code. The runner now compares each failing theorem's elaborated statement with the unmutated model's, and a mutation that changes or adds one reaches no verdict. The comparison ignores binder names, which Lean 4.20 numbers by a counter that edits to earlier commands shift.
|
|
22
|
+
|
|
23
|
+
`example` and `#guard` commands have no declaration to compare, so a rename that broke one still printed DETECTED and exited 0. The runner now compares an example's elaborated header type and a guard's elaborated term with the unmutated model's, after closing them over section variables, whose internal ids shift when an earlier command changes. A mutation that changes one reaches no verdict. So does a mutation whose replacement adds a check that the unmutated model lacks, which used to count as DETECTED.
|
|
24
|
+
|
|
25
|
+
Lean mutation results explicitly measure whether existing proofs break; they do not establish that a statement is false or its hypotheses can hold. The skill reports those evidence gaps separately. Existing properties may be corrected and re-frozen when the main thread accepts source-backed specification evidence, even when production code is unchanged; unsupported weakening remains prohibited.
|
|
26
|
+
|
|
27
|
+
The mutation runner reads and applies every mutation before it runs any tool. A mutation whose replaced text does not occur exactly once in the model used to be found only when its turn came, after every earlier mutation had run its checker; it now stops the run first. A TLA+ or Rust mutation without a `detects` line, and a mutation with two `detects` or two `only` lines, now fail by name instead of reporting a property named by an empty string or keeping the last line. A Lean mutation with an `only` line now fails instead of ignoring it. Because these checks run first, a malformed mutations file fails before a missing tool reports `UNAVAILABLE`.
|
|
28
|
+
|
|
29
|
+
The mutation runner checks that a Lean project's pinned toolchain is ready once per run, not once per mutation. The check and its remedy now live in `lean-tools.sh`, where `lean-check.sh` reads them too, and a Lean project without a pin reports that directly instead of as an analysis that did not complete.
|
|
30
|
+
|
|
31
|
+
The Lean checker derives each source's module name once and passes it to the frozen-statement step, which derived it a second time from the same path. When Lake reports a build file outside `.lake/build/lib/lean`, the checker now names it and stops instead of auditing a wrong import.
|
|
32
|
+
|
|
33
|
+
The TLA+ matrix runner moved from bash into `tlc.py`, and `tlc-matrix.sh` now checks for Python 3 and runs it, as `kani-check.sh` runs `kani.py`. Its output and exit status are unchanged, except that a matrix saved with CRLF line ends now runs, where the bash runner reported its spec as not found. The mutation runner now reads the matrix with the same parser and runs each mutation through the same runner, instead of parsing the matrix a second time and reading verdicts back out of printed lines. So it now finds its spec's section when the `spec` line writes the path another way, such as `./Name.tla`, and it checks TLC once per run instead of once per mutation. Any line the matrix runner rejects now stops the mutation runner wherever it is in the matrix, including an unknown directive, a run before any `spec` line and a check after an empty `spec` line; before, it noticed only a malformed check or reach in its own spec's section. It also reads a matrix whose words are separated by tabs, as the matrix runner always did.
|
|
34
|
+
|
|
35
|
+
The Lean and Kani templates now ask the adapter to record the source files, line ranges, covered functions and `Source read at <commit>` line in the model's header, as the TLA+ template and all three briefs already did.
|
|
36
|
+
|
|
3
37
|
## 0.4.8 - pin Lean 4.35.0
|
|
4
38
|
|
|
5
39
|
The Lean template pins Lean 4.35.0 in place of 4.34.1. The template records the same 34 declarations with the same statement types under both versions. Lean 4.35.0 builds the bodies of three generated `match_1` matchers differently, so their value fingerprints changed, and the template's statements are re-frozen. A project copied from the template keeps its own pin. After its `lean-toolchain` changes, the checker asks for a review and a fresh `--freeze`, as before. The checker still supports pins from Lean 4.20.0.
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@ Then read `git log -p <sync>..HEAD -- <paths collected>`, which includes commits
|
|
|
35
35
|
Record the sync commit, the commits read and the answers to two questions in the row:
|
|
36
36
|
|
|
37
37
|
- Does the model still describe the code as it is now? If not, the model changes.
|
|
38
|
-
- Does a doc comment, test, changelog entry or commit message in those commits say the guarantee changed? If so, the property changes with it, citing that evidence.
|
|
38
|
+
- Does a doc comment, test, changelog entry or commit message in those commits say the guarantee changed? If so, the property changes with it, citing that evidence. Otherwise preserve the property unless step 3 accepts an evidenced specification correction; a failure after updating the transcription is a bug candidate.
|
|
39
39
|
|
|
40
40
|
Then search for new targets in code no model covers, unless the user asked only to recheck the existing models.
|
|
41
41
|
|
|
@@ -70,11 +70,12 @@ The helpers:
|
|
|
70
70
|
|
|
71
71
|
- The setup helper, [`scripts/setup.sh`](scripts/setup.sh), verifies the pinned TLC JAR and is the only helper that installs a Lean toolchain.
|
|
72
72
|
- The matrix runner, [`scripts/tlc-matrix.sh`](scripts/tlc-matrix.sh), runs TLC with a matrix of constants and prints one PASS or FAIL per run with its state count, then a SUMMARY line with the totals. A failing run prints its error trace reduced by [`scripts/tlc-trace.py`](scripts/tlc-trace.py) to the variables each step changed. Copy [`examples/tla-template/`](examples/tla-template/BoundedQueue.tla) to start a spec and its matrix.
|
|
73
|
-
- The Lean checker, [`scripts/lean-check.sh`](scripts/lean-check.sh), builds every `.lean` file in the pinned Lake project and audits every declaration of every built module. It fails on a build error, a `sorry`, a declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a `.lean` file that no Lake library owns. Use `--freeze` before the file names to record statement types and definition bodies in each model's `.statements` file before proving it. Freezing permits `sorry` and reports FROZEN, not a proof PASS. Later checks enforce those records and permit proof changes and added declarations. Given file names after the project, it checks only those files. Copy [`examples/lean-template/Model/BoundedQueue.lean`](examples/lean-template/Model/BoundedQueue.lean) to start a model.
|
|
73
|
+
- The Lean checker, [`scripts/lean-check.sh`](scripts/lean-check.sh), builds every `.lean` file in the pinned Lake project and audits every declaration of every built module. It fails on a build error, a `sorry`, a declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a `.lean` file that no Lake library owns. It checks each `<Property>.witness` theorem against its property's hypotheses, and fails on a witness that states something else, as the [Lean brief](references/lean-brief.md) describes. It then replays every built module, and every project module it imports, through the Lean kernel with the pin's `leanchecker`, which rejects a declaration that a command added without a kernel check. A pin without `leanchecker`, such as Lean 4.20.0, passes with the replay reported as unavailable. Use `--freeze` before the file names to record statement types and definition bodies in each model's `.statements` file before proving it. Freezing permits `sorry` and reports FROZEN, not a proof PASS. Later checks enforce those records and permit proof changes and added declarations. Given file names after the project, it checks only those files. Copy [`examples/lean-template/Model/BoundedQueue.lean`](examples/lean-template/Model/BoundedQueue.lean) to start a model.
|
|
74
74
|
- The Rust checker, [`scripts/kani-check.sh`](scripts/kani-check.sh), runs the pinned Kani on the crate's proof harnesses. It reports each harness's unwind bound and check count, rejects failed checks and unsatisfied cover conditions, and prints concrete playback tests when available. Copy [`examples/kani-template/`](examples/kani-template/src/lib.rs) for a bounded-queue example.
|
|
75
|
-
- The mutation runner, [`scripts/mutate.py`](scripts/mutate.py), takes a model's `<Name>.mutations` file and applies each listed bug to a temporary copy of the model. It prints DETECTED or MISSED per mutation with what failed, UNCOVERED for a TLA+ property or Kani harness that no mutation targets or for a public theorem in a Lean model's `.statements` file
|
|
75
|
+
- The mutation runner, [`scripts/mutate.py`](scripts/mutate.py), takes a model's `<Name>.mutations` file and applies each listed bug to a temporary copy of the model. It prints DETECTED or MISSED per mutation with what failed, UNCOVERED for a TLA+ property or Kani harness that no mutation targets or for a public theorem in a Lean model's `.statements` file whose proof no mutation makes fail, and a SUMMARY line. Lean names are fully qualified. A Lean DETECTED line means the existing proof fails; it does not establish that the statement is false or its hypotheses can hold. A Lean mutation that changes the statement of a theorem, example or `#guard`, such as renaming a definition that the statement names, reaches no verdict. A Lean model needs its `.statements` file before its mutations run. All three templates include a mutations file.
|
|
76
|
+
- The baseline helper, [`scripts/baseline.py`](scripts/baseline.py), records what each model specifies and later names each part that changed. For TLA+ it records each run's inputs and effective checks, each reach check's selected run and inputs, and the definitions of `Spec`, of the checked and reach operators, and of the operators those reference, including the initial state. It shares the matrix runner's execution plan, so a check applies only to the runs after it in its section. It does not follow `Spec` into the actions it names under `[][...]_vars`, `WF_` or `SF_`, because every correction of the transcription changes them. An operator that `Spec` names outside those, such as a fairness definition, is followed into its actions. A column-0 definition whose header it cannot read, such as an infix operator, is recorded whether or not a property references it, with the operators it references. For Lean it records the `.statements` file. For Kani it records each qualified harness name and each `kani::assume`, `kani::any_where`, `kani::cover!` and `#[kani::stub]` with its qualified owning function, including helper functions. The Rust reader supports free functions under inline modules; a Kani form in a macro, implementation or trait body, or another owner it cannot identify, fails the record. A spelling it cannot read, such as an import that renames `kani::assume`, also fails. It does not record a harness's assertions, input construction, surrounding guards or calls to assumption helpers; read `git diff` for those. Create a new record after updating the helper if it reports an unsupported record format.
|
|
76
77
|
|
|
77
|
-
Run every existing model's checker and mutations once, before any agent changes a model, and record the results. For a TLA+ or Lean model a pass shows only that the old description still holds; a Kani harness runs the code as it is now. A model that still describes the code needs no agent. When it passes, refresh its header as step 5 says; when it fails, take the failure through step 4. A Kani compile error means the harness no longer fits the code, so give it to an agent. An UNCOVERED line means the mutations file lacks a bug that the property detects, not that the code fails; give the model to an agent to add one. A check that passes here and fails after the update was passing on a stale description; say so in the reply.
|
|
78
|
+
Run every existing model's checker and mutations once, before any agent changes a model, and record the results. Then record what the models specify with `python3 <skill-dir>/scripts/baseline.py record <record-file> <model files>`, naming each existing `.matrix`, `.statements` and Kani harness file. Put `<record-file>` in a temporary directory outside the repository, and leave its path out of every brief. For a TLA+ or Lean model a pass shows only that the old description still holds; a Kani harness runs the code as it is now. A model that still describes the code needs no agent. When it passes, refresh its header as step 5 says; when it fails, take the failure through step 4. A Kani compile error means the harness no longer fits the code, so give it to an agent. An UNCOVERED line means the mutations file lacks a bug that the property detects, not that the code fails; give the model to an agent to add one. A check that passes here and fails after the update was passing on a stale description; say so in the reply.
|
|
78
79
|
|
|
79
80
|
## 3. Model one target per agent
|
|
80
81
|
|
|
@@ -90,7 +91,9 @@ Name the brief file and leave its text out of the prompt. The [TLA+ brief](refer
|
|
|
90
91
|
|
|
91
92
|
An agent writes only its own files, `tla/<Name>.tla`, `.matrix` and `.mutations`, `lean/Model/<Name>.lean`, `.mutations` and `.statements`, or the assigned Rust harness and `.mutations` files in a separate crate, so parallel agents share none. An existing Lean project keeps its layout and must pin Lean 4.20.0 or later.
|
|
92
93
|
|
|
93
|
-
When the agents have reported, rerun every check in this thread: the matrix runner on each matrix file, the Lean checker on the whole project without a file name, the Rust checker on each crate, and the mutation runner on each mutations file. Take each verdict from these runs, not from an agent's report. Then
|
|
94
|
+
When the agents have reported, rerun every check in this thread: the matrix runner on each matrix file, the Lean checker on the whole project without a file name, the Rust checker on each crate, and the mutation runner on each mutations file. Take each verdict from these runs, not from an agent's report. Then run `python3 <skill-dir>/scripts/baseline.py compare <record-file>`. It exits 1 and prints CHANGED with the changed parts when a recorded property, fairness condition, matrix line, `.statements` record, Kani cover or stub changed, a Kani harness was removed or renamed, or a Kani assumption was added or changed. Also read `git diff` for each model that existed before this run, for the changes the record does not cover, such as a theorem newly marked `private`, a new guard in a TLA+ action, or a removed assertion or narrowed input in a Kani harness. Each such change needs the evidence its row cites, a specification correction accepted below, or for a re-freeze another reason the Lean brief permits. Revert any change without it and give the model back to its agent with the reason. Run the comparison again until it exits 0.
|
|
95
|
+
|
|
96
|
+
Accept a specification correction when a reviewer finding, a missed mutation, an UNCOVERED result with source evidence, or a checked witness demonstrates a gap in the old statement. Read the old and proposed guarantees against the callers, record the evidence and decision in the target's row, and permit the corresponding re-freeze even when production code is unchanged. The correction must preserve the intended guarantee or strengthen it over the intended inputs. A broken proof alone does not justify changing a statement. A weaker guarantee or a new assumption excluding shipped inputs needs evidence of an intentional production contract change or the user's explicit agreement. Rerun all checks after the accepted correction and re-freeze. Then run `baseline.py record <record-file>` again on that model's file, and add the previous and new digests it prints to the row.
|
|
94
97
|
|
|
95
98
|
When the user chose the review, spawn one reviewer per model once these checks pass, on a different model from the modelling agents when the host offers a choice. Its brief contains the target's row, the source files with line ranges, the model's files, `<skill-dir>` and the instruction to read `<skill-dir>/references/review-brief.md` in full and follow it. The [review brief](references/review-brief.md) holds the questions and the report. Leave out the modelling agent's report, so the reviewer judges the properties against the code alone. Append the mutations the reviewer proposes to the model's mutations file and run the mutation runner. Remove a proposal that the runner rejects, such as one whose text does not occur once or whose `detects` names no checked property, and rerun. Keep a DETECTED proposal. Drop a MISSED proposal that changes nothing a caller could observe, such as a reordered sum. Any other MISSED proposal shows a property that lets a plausible bug pass; give the model, the proposal and the reviewer's reason to a new modelling agent, then repeat the checks above. Run one review round per model, and report what is still open after it. Report each finding that no mutation can express as an open question in the reply, and leave the model as it is.
|
|
96
99
|
|
|
@@ -126,6 +129,8 @@ Do not add a report file per bug, and do not paste run tables or traces into sev
|
|
|
126
129
|
|
|
127
130
|
These models do not check memory ordering below the mutex. Keep the project's ThreadSanitizer or race-detector checks. Model floating-point results as the integers they round to, unless the property concerns the rounding itself.
|
|
128
131
|
|
|
132
|
+
The baseline record and these steps detect a modelling agent that weakens a specification while it follows its brief. They do not stop an agent that sets out to defeat them. An agent runs as the same user, with a shell, and can edit any file, including the record and the helpers. Say so when a report states that a specification did not change.
|
|
133
|
+
|
|
129
134
|
A passing TLA+ or Lean model establishes its stated properties under its assumptions. It describes the code by hand. Kani checks the Rust function itself, within the reported input and unwind bounds. Neither result establishes correctness of the whole program.
|
|
130
135
|
|
|
131
136
|
## Reply
|
|
@@ -141,9 +146,12 @@ Write the reply, and any pull request or document, for a reader who knows the co
|
|
|
141
146
|
| TLC passes | TLC tried every ordering of the modelled steps at the listed small sizes and found none that breaks the property. The SUMMARY line's state total is the size of that search, not a count of real runs. |
|
|
142
147
|
| Kani passes | Kani checked every input within the stated bounds and found no violation. Larger inputs are not covered. |
|
|
143
148
|
| Lean passes | Lean proved the property for every input, under the listed assumptions. |
|
|
149
|
+
| Kernel replay passed | Lean's kernel checked every declaration of the built modules a second time, including any that a command added without a check. `unavailable` means the pinned Lean has no `leanchecker`, so this second check did not run. |
|
|
150
|
+
| Witness checked | A Lean proof shows that some concrete values satisfy all of a property's hypotheses at once, so the property is not true merely because nothing meets its conditions. `absent` and `unavailable` mean this was not checked. |
|
|
144
151
|
| A bounded search passes | Every input up to the stated bound was tried. |
|
|
145
|
-
| Mutations detected | Deliberate bugs were planted in copies of the model, and the checks caught each one.
|
|
146
|
-
| Past fix detected | The checks fail on the behaviour
|
|
152
|
+
| Mutations detected | Deliberate bugs were planted in copies of the model, and the checks caught each one. For Lean, this shows that existing proofs fail, not that the mutated statements are false. |
|
|
153
|
+
| Past fix detected | The checks fail on the behaviour before a recorded bug fix. For Lean, report proof sensitivity separately from whether a checked counterexample establishes that the property rules out that bug. |
|
|
154
|
+
| Specification unchanged | The baseline comparison preserved each recorded run's inputs and checks, reach check's selected inputs, property and fairness definition, statement record, qualified Kani harness name and function-owned assumption, cover and stub. It does not cover a Kani harness's assertions, input construction, surrounding guards or calls to assumption helpers; `git diff` does. |
|
|
147
155
|
| UNAVAILABLE | The tool could not run. This target was not checked; give the printed remedy. |
|
|
148
156
|
| reproduced | A deterministic test or race-detector run fails on the production code. |
|
|
149
157
|
| reachable at shipped settings | The shipped constants and callers permit the counter-example, but no production reproduction has confirmed it yet. |
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// Copyright (c) 2026 Michael Denyer
|
|
2
2
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
3
|
+
//
|
|
4
|
+
// The harnesses in `proofs` check `claim` and `consume` of a bounded queue with
|
|
5
|
+
// ordered output. To adapt them, replace this comment with the production
|
|
6
|
+
// source files and line ranges the harnesses call, the functions they cover,
|
|
7
|
+
// the commit they were read at as `Source read at <commit>`, and each caller
|
|
8
|
+
// constraint and stub assumption.
|
|
3
9
|
|
|
4
10
|
#[derive(Clone, Copy)]
|
|
5
11
|
pub struct State {
|
|
@@ -5,11 +5,17 @@ This model checks the counters of a bounded queue with ordered output.
|
|
|
5
5
|
`next` counts claimed items, `consumed` counts consumed items, and at most
|
|
6
6
|
`w` items may be in flight. To adapt it:
|
|
7
7
|
|
|
8
|
-
1.
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
1. Replace this description with the source files and line ranges the model
|
|
9
|
+
follows, the functions it covers, the commit they were read at as
|
|
10
|
+
`Source read at <commit>`, and each assumption it makes.
|
|
11
|
+
2. Transcribe the state and steps from the code with the same arithmetic.
|
|
12
|
+
3. State the invariant as a `Prop` with a `Decidable` instance.
|
|
13
|
+
4. Run `#eval badPairs` to find states where a step violates the invariant
|
|
11
14
|
within the chosen bound, and keep the `#guard` that fails the build on one.
|
|
12
|
-
|
|
15
|
+
5. Prove the invariant for every size by cases on the step.
|
|
16
|
+
6. For each theorem with hypotheses, prove `<theorem>.witness` on concrete
|
|
17
|
+
values that satisfy all of them at once. `lean-check.sh` prints the
|
|
18
|
+
statement it expects and checks the one it finds.
|
|
13
19
|
|
|
14
20
|
Name any unfinished proof that uses `sorry`. `lean-check.sh` fails on it, on
|
|
15
21
|
any declaration that rests on a declared axiom, and on a `.lean` file that no
|
|
@@ -78,6 +84,9 @@ theorem claim_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h :
|
|
|
78
84
|
omega
|
|
79
85
|
· cases h
|
|
80
86
|
|
|
87
|
+
private theorem claim_keeps_invariant.witness : ∃ w s t, Invariant w s ∧ claim w s = some t :=
|
|
88
|
+
⟨1, ⟨0, 0⟩, ⟨1, 0⟩, by decide, by decide⟩
|
|
89
|
+
|
|
81
90
|
theorem consume_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h : consume s = some t) :
|
|
82
91
|
Invariant w t := by
|
|
83
92
|
unfold consume at h
|
|
@@ -87,6 +96,9 @@ theorem consume_keeps_invariant (w : Nat) (s t : State) (hs : Invariant w s) (h
|
|
|
87
96
|
omega
|
|
88
97
|
· cases h
|
|
89
98
|
|
|
99
|
+
private theorem consume_keeps_invariant.witness : ∃ w s t, Invariant w s ∧ consume s = some t :=
|
|
100
|
+
⟨1, ⟨1, 0⟩, ⟨1, 1⟩, by decide, by decide⟩
|
|
101
|
+
|
|
90
102
|
def vectors : List (Nat × State) :=
|
|
91
103
|
[(0, ⟨0, 0⟩), (1, ⟨0, 0⟩), (1, ⟨1, 0⟩), (1, ⟨1, 1⟩),
|
|
92
104
|
(4, ⟨0, 0⟩), (4, ⟨3, 0⟩), (4, ⟨4, 0⟩), (4, ⟨5, 1⟩), (4, ⟨5, 5⟩)]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Mutations for mutate.py. Each one swaps a piece of BoundedQueue.lean for a
|
|
2
2
|
# plausible bug. The text after `- ` must occur exactly once in the model;
|
|
3
3
|
# `+ ` lines replace it. mutate.py reports the declarations that fail on each,
|
|
4
|
-
# and every public theorem in BoundedQueue.statements must fail on one.
|
|
4
|
+
# and every public theorem's proof in BoundedQueue.statements must fail on one.
|
|
5
5
|
|
|
6
6
|
mutation count an item as consumed before any claim
|
|
7
7
|
- def init : State := ⟨0, 0⟩
|
|
@@ -143,6 +143,13 @@
|
|
|
143
143
|
"typeHash": "a62ef6d7676b1be25d6f5adc855db00967122a1664301f089eddcbc5b7425716",
|
|
144
144
|
"valueHash": null
|
|
145
145
|
},
|
|
146
|
+
{
|
|
147
|
+
"name": "BoundedQueue.claim_keeps_invariant.witness",
|
|
148
|
+
"kind": "theorem",
|
|
149
|
+
"type": "∃ w s t, BoundedQueue.Invariant w s ∧ BoundedQueue.claim w s = some t",
|
|
150
|
+
"typeHash": "345ce2f56368ae1d973c198de43581007e5a656e2115d3c9101fd3013b3d8430",
|
|
151
|
+
"valueHash": null
|
|
152
|
+
},
|
|
146
153
|
{
|
|
147
154
|
"name": "BoundedQueue.consume",
|
|
148
155
|
"kind": "definition",
|
|
@@ -157,6 +164,13 @@
|
|
|
157
164
|
"typeHash": "8f97727457cdc622aff37bd77a07265ab79e8ad8c1fe7124db33cef3aacc0b3f",
|
|
158
165
|
"valueHash": null
|
|
159
166
|
},
|
|
167
|
+
{
|
|
168
|
+
"name": "BoundedQueue.consume_keeps_invariant.witness",
|
|
169
|
+
"kind": "theorem",
|
|
170
|
+
"type": "∃ w s t, BoundedQueue.Invariant w s ∧ BoundedQueue.consume s = some t",
|
|
171
|
+
"typeHash": "3667894d6b0a22c93ce6d8dae29d88713eb74e7f218a2f854d4272d41fb160ca",
|
|
172
|
+
"valueHash": null
|
|
173
|
+
},
|
|
160
174
|
{
|
|
161
175
|
"name": "BoundedQueue.init",
|
|
162
176
|
"kind": "definition",
|
|
@@ -10,7 +10,7 @@ Every `.lean` file in the project must belong to a library in the lakefile. With
|
|
|
10
10
|
|
|
11
11
|
## Existing model
|
|
12
12
|
|
|
13
|
-
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the transcription where it no longer describes the code. Change a theorem statement only
|
|
13
|
+
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the transcription where it no longer describes the code. Change a theorem statement only with that evidence or a specification correction accepted by the main thread under step 3 of the skill. Re-freeze after either change, as the Check section allows, and rerun the differential vectors. Add a mutation for each branch or step the update adds. Update the header to the code you read.
|
|
14
14
|
|
|
15
15
|
## Model
|
|
16
16
|
|
|
@@ -18,7 +18,8 @@ The row in your task gives the commits since the model was last synced and says
|
|
|
18
18
|
2. State the property as a `Prop` with a `Decidable` instance. It may describe an invariant, an encoder round trip, an index bound or states the machine must never reach.
|
|
19
19
|
3. Write every theorem statement with `sorry` for its proof, then freeze the model with `bash <skill-dir>/scripts/lean-check.sh <absolute-project-path> --freeze Model/<Name>.lean`. This records types and definition bodies even while proofs are unfinished. The FROZEN line confirms the record, not a proof. Added axioms still fail.
|
|
20
20
|
4. Write and evaluate a bounded exhaustive check before proving the theorem. The template's `badPairs` finds states where one step breaks the invariant; evaluating `badPairs 2 6` at top level, as the template does, prints concrete counter-examples and `#guard` fails the build while any exist. Set the bound above the code's slot count, batch size, window and other constants so it includes boundary cases. Add a `#guard` that a bounded search from the initial state reaches the states the property depends on. The template's `reachable` search requires a full window.
|
|
21
|
-
5. Prove one theorem per step or function for every size. Split on the guards, use `simp only [...]` to expose arithmetic, then use `omega` or `decide` for a finite type. If a proof needs a fact about the real code that the model lacks, state it as a theorem hypothesis and name it in a comment. Do not declare it as an `axiom`. Mark each helper lemma `private`; every public theorem is a property
|
|
21
|
+
5. Prove one theorem per step or function for every size. Split on the guards, use `simp only [...]` to expose arithmetic, then use `omega` or `decide` for a finite type. If a proof needs a fact about the real code that the model lacks, state it as a theorem hypothesis and name it in a comment. Do not declare it as an `axiom`. Mark each helper lemma `private`; every public theorem is a property whose proof the mutations must be able to break. An unfinished proof may use `sorry`, but the Lean checker reports it as a failure. The checker also fails every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, which also rules out `native_decide`.
|
|
22
|
+
6. For each public theorem with hypotheses, prove on concrete values that all of them can hold at once, as `private theorem <Property>.witness` in the same file. The template does this for each of its theorems with hypotheses.
|
|
22
23
|
|
|
23
24
|
After a proof closes, print differential test vectors by evaluating them at top level, as the template does. Include boundary inputs and a spread of in-range inputs, with each input and the model's output on one line. Write a test in the target repository's own framework that calls the production function on those inputs and compares its output. A mismatch is a bug in the production code or the transcription; establish which before reporting. State how many vectors agree and the integer widths in both implementations. If the production comparison was not run, say so beside the proof verdict.
|
|
24
25
|
|
|
@@ -41,13 +42,27 @@ bash <skill-dir>/scripts/lean-check.sh <absolute-project-path> Model/<Name>.lean
|
|
|
41
42
|
python3 <skill-dir>/scripts/mutate.py <absolute-project-path>/Model/<Name>.mutations
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
The checker enforces the `.statements` file beside each checked source. Changing a theorem type, a definition type or body, or deleting a frozen declaration fails with its name. Adding lemmas and definitions and changing proofs is allowed. Re-freeze only after the production code changes, after a production test contradicts the transcription,
|
|
45
|
+
The checker enforces the `.statements` file beside each checked source. Changing a theorem type, a definition type or body, or deleting a frozen declaration fails with its name. Adding lemmas and definitions and changing proofs is allowed. Re-freeze only after the production code changes, after a production test contradicts the transcription, after reviewing a toolchain bump, or after the main thread accepts a specification correction under step 3 of the skill. Record the evidence, the old and new guarantees, and the reason for re-freezing in the report. Records are specific to the pinned Lean toolchain. Fingerprints use structural expressions, including the module identity of private references. If two private declarations share a name in one model, give them distinct names before freezing. A project-wide check also rejects records whose source files were deleted. Named-file checks remain limited to those files. A model without a record retains the usual proof and axiom checks, so keep the records under version control. Deleting a record removes that protection.
|
|
45
46
|
|
|
46
47
|
The file name limits the Lean checker to your model, so another agent's unfinished file does not fail your check.
|
|
47
48
|
|
|
48
|
-
List plausible bugs in the mutations file, such as `<` instead of `≤`, a missing `+ 1` or a swapped argument. The mutation runner checks each on a copy of the file and names the theorems and `#guard` lines that fail. Expect both the bounded search's `#guard` and the theorem. It rejects a mutation that stops a definition compiling. Revise the properties behind each MISSED line.
|
|
49
|
+
List plausible bugs in the mutations file, such as `<` instead of `≤`, a missing `+ 1` or a swapped argument. The mutation runner checks each on a copy of the file and names the theorems and `#guard` lines that fail. Expect both the bounded search's `#guard` and the theorem. It rejects a mutation that stops a definition compiling or changes the statement of a theorem, example or `#guard`, such as renaming a definition that a statement names. Revise the properties behind each MISSED line.
|
|
49
50
|
|
|
50
|
-
The mutation runner
|
|
51
|
+
The mutation runner reads the `.statements` file and uses Lean's elaborated names and source ranges to report each frozen public theorem whose proof no mutation makes fail. Structure and class projections and instance declarations are not property targets. Names remain fully qualified, including nested namespaces. A failing `#guard` or example does not cover a named theorem. Guard and example locations point into the original model; a command introduced by the mutation is labelled as a replacement at the edit's original location. Add a mutation that breaks the proof, or propose a specification correction with evidence for the main thread to accept before re-freezing. A helper lemma that shows here should be `private`; a property marked `private` to hide it is a change the main thread reverts. Lean mutations take no `detects` line. For each fix commit in your row, add a mutation that restores the behaviour the code had before the fix, with the commit's short hash in its label.
|
|
52
|
+
|
|
53
|
+
A broken proof does not establish that the mutated statement is false. Even a theorem with contradictory hypotheses can have a proof that breaks when the implementation changes. Check that each theorem's hypotheses can hold together, using concrete inputs and Lean-checked witnesses where practical, and report where this was not checked. Keep proof sensitivity, hypothesis satisfiability and a checked counterexample as separate evidence. Do not claim non-vacuity or that a historical bug is ruled out from a DETECTED line alone.
|
|
54
|
+
|
|
55
|
+
The checker derives the statement a witness must prove from its property: `∃ (v1 : T1), …, ∃ (vn : Tn), H1 ∧ … ∧ Hk`, with the theorem's variables and hypotheses in binder order. It rebuilds this statement on every run, so a changed property needs a new witness. When the witness is missing or states something else, the checker prints the statement, which can be pasted as the witness's type. Only a `theorem` named `<Property>.witness` in the property's file counts; an `example`, `def` or `axiom` does not. A witness, private or public, is not a mutation-coverage property. Adding one needs no re-freeze. A mutation that breaks only a witness reads MISSED, because the witness proves chosen values, not the property. Do not make an existing property private to avoid coverage. Each check prints one WITNESS line per property:
|
|
56
|
+
|
|
57
|
+
| Status | Meaning |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `checked` | The witness states the property's hypotheses, and Lean proved it. |
|
|
60
|
+
| `failed` | The witness states something else. The check exits 1 and prints the statement expected. |
|
|
61
|
+
| `absent` | No witness exists. The check passes; report non-vacuity as not checked. |
|
|
62
|
+
| `no-hypotheses` | The theorem has no hypotheses written as binders. The checker does not look inside definitions or at the variable types, so a property whose statement unfolds to an implication, or whose variable has an empty type such as `Fin 0`, also reads `no-hypotheses`. |
|
|
63
|
+
| `unavailable` | A variable's type uses a hypothesis's proof, or deriving the statement failed. The check passes with the reason; report non-vacuity as not checked. |
|
|
64
|
+
|
|
65
|
+
After these checks the checker replays every built module, and every project module it imports, through the Lean kernel with the pinned toolchain's `leanchecker`. The replay rejects a declaration that a command added to the environment without a kernel check, and the checker then exits 1 with `leanchecker`'s output. A pin without `leanchecker`, such as Lean 4.20.0, prints `UNAVAILABLE kernel replay` and still exits 0; report the kernel replay as not checked. This differs from a missing tool, which exits 3.
|
|
51
66
|
|
|
52
67
|
Check the reach guard as well as the absence of bad pairs. A search that cannot reach a boundary state does not establish the intended coverage.
|
|
53
68
|
|
|
@@ -61,4 +76,6 @@ Report only after reading the output of both commands. If either exits 3 with `U
|
|
|
61
76
|
- for each counter-example, concrete inputs to the code's function, the source line of the failing arithmetic, a unit test with those inputs and whether it fails on the production code, whether shipped callers can pass those inputs, and the proposed fix;
|
|
62
77
|
- the `.statements` path and any reason for re-freezing;
|
|
63
78
|
- for a closed proof, its assumptions, including integer widths, bounds and each theorem hypothesis;
|
|
79
|
+
- each theorem's WITNESS status, with `absent` and `unavailable` reported as non-vacuity not checked;
|
|
80
|
+
- whether the kernel replay passed or was unavailable;
|
|
64
81
|
- the number of differential vectors on which the model and production code agree, their integer widths, or an explicit statement that the comparison was not run.
|
|
@@ -26,7 +26,8 @@ The row in your task gives the commits since the harness was last synced and
|
|
|
26
26
|
says whether any of them changed the guarantee on purpose. The harness calls the
|
|
27
27
|
production code, so drift shows as a compile error or a failed check. Update its
|
|
28
28
|
bounds, stubs, contracts and covers where they no longer fit the code. Change a
|
|
29
|
-
property only
|
|
29
|
+
property only with that evidence or a specification correction accepted by the
|
|
30
|
+
main thread under step 3 of the skill. Add a mutation, with `detects`
|
|
30
31
|
naming the harness, for each branch or step the update adds. Update the header
|
|
31
32
|
to the code you read.
|
|
32
33
|
|
|
@@ -65,8 +66,9 @@ printed installation remedy before making any claim about the code. A compilatio
|
|
|
65
66
|
error, missing harness or incomplete verifier report fails.
|
|
66
67
|
|
|
67
68
|
Put `<Name>.mutations` beside the assigned `<Name>.rs`. Use
|
|
68
|
-
`detects <fully-qualified-harness>` for each mutation. The mutation runner
|
|
69
|
-
the
|
|
69
|
+
`detects <fully-qualified-harness>` for each mutation. The mutation runner uses
|
|
70
|
+
the bundled Cargo to find the crate's workspace and local dependencies, copies
|
|
71
|
+
them to temporary storage with their relative paths intact, and checks the named harness. A compiler
|
|
70
72
|
error never counts as detection. Every discovered harness needs a mutation.
|
|
71
73
|
|
|
72
74
|
For each fix commit in your row whose fixed code is in the file beside the
|
|
@@ -43,7 +43,7 @@ Kani supports Linux and macOS on x86_64 and aarch64. See the [pinned installatio
|
|
|
43
43
|
|
|
44
44
|
The Rust checker discovers proof harnesses and checks each selected harness separately. It reports the unwind bound and check count, rejects an insufficient bound and any cover condition that was not satisfied, and prints a concrete playback test for a failed assertion when Kani can produce one. Larger inputs and loops remain outside the reported bounds. Crate builds may obtain dependencies declared in Cargo; the template has none.
|
|
45
45
|
|
|
46
|
-
The mutation runner reads `Name.mutations` beside `Name.rs`,
|
|
46
|
+
The mutation runner reads `Name.mutations` beside `Name.rs`, uses the bundled Cargo to find the crate's workspace and local dependencies, and copies them to a temporary directory with their relative paths intact. It checks the harness named by `detects` and leaves the source crate unchanged. Each harness must have a mutation that its property detects.
|
|
47
47
|
|
|
48
48
|
## Lean 4
|
|
49
49
|
|
|
@@ -8,7 +8,7 @@ Write `tla/<Name>.tla`, `tla/<Name>.matrix` and `tla/<Name>.mutations` in the ta
|
|
|
8
8
|
|
|
9
9
|
## Existing model
|
|
10
10
|
|
|
11
|
-
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the spec where it no longer describes the code. Change a property only
|
|
11
|
+
The row in your task gives the commits since the model was last synced and says whether any of them changed the guarantee on purpose. Change the spec where it no longer describes the code. Change a property only with that evidence or a specification correction accepted by the main thread under step 3 of the skill. Add a mutation for each step, branch or wait the update adds, naming the property that must fail on it. Update the header to the code you read.
|
|
12
12
|
|
|
13
13
|
## Model
|
|
14
14
|
|