Skip to content

Commit 9986ca4

Browse files
fix(abi): repair the Idris2 proofs and record proof status against the policy (#277)
I re-checked panic-attack's Idris2 proofs with Idris2 0.7.0, the version `proven-tests.yml` pins. No CI job type-checks `src/abi/`, so the ✅ marks in `PROOF-NEEDS.adoc` had no receipt behind them. ## What the check found on `main` | Module | Result on `main` | Design | |---|---|---| | `ClassificationSoundness.idr` (PA2) | passes | Sound and non-trivial for its model | | `AttestationUnforgeability.idr` | passes | Sound relative to its hypotheses. Two of them are symbolic-model idealisations, and the header overstated them as EUF-CMA and collision resistance. | | `PatternCompleteness.idr` (PA1) | passes | **Vacuous**: `GenericAnalyzer : HasAnalyzer lang` inhabits every language. The model is also stale (see below). | | `Stripping.idr` | **does not compile** | The theorem is true, but the proof had two type errors, hidden behind a parse error. | | `Types.idr` | **does not compile** | No theorems, despite a header claiming three | PA1's staleness: its `Lang` has 50 languages against 52 in Rust, missing `C` and `Php`. `crossLangAlwaysApplied` also says cross-language checks run on every file, but the Rust code now skips them for configuration files. ## Commits 1. **`3dc4728` fix(abi): make the Stripping and Types Idris2 modules type-check** - **`Stripping.idr`:** matching on a `Char` literal only reduces when the character is a literal, so the proof stuck on a variable head. The model now classifies each character once (`Slash`, `Newline`, `Other`) and steps on the class, and each proof carries `cls c = k`. - The theorem statements are unchanged. - All seven sanity checks are unchanged and pass. - The new model equals the old one on all 349,525 strings of length ≤ 9 over `/`, newline, `x` and space. - **`Types.idr`:** syntax-only fixes. Its header now says it declares types only, and notes its drift from `src/types.rs`. 2. **`b1b1419` docs(proofs): record proof status against the estate proof policy** - `PROOF-NEEDS.adoc` now uses the proof policy's §5 tokens and §1.2 verifier mapping, pinned to `metadatastician/standards` `9bdf864`. - It records a receipt for the Idris2 check and an honest status per obligation. - The implementation obligations are listed as `OPEN` for Creusot/Pearlite and Verus: stripping, Patch Bridge reachability and taint analysis. ## Verification - All five `src/abi` modules type-check. The pass criterion is exit 0 and no `Error:` line; `idris2 --check` can exit 0 while printing an error. - **Negative controls:** a planted false lemma and a planted non-terminating definition are both rejected. - **No escape hatches:** every module sets `%default total` and uses none of `believe_me`, `assert_total`, `postulate` or holes. The one `believe_me` match is in a doc comment that bans it. - **Kani note:** `cargo clippy --lib --bins --tests --benches --all-features -- -F unsafe_code` compiles. The only `unsafe` is in `examples/vulnerable_program.rs`, a deliberately buggy scan target. - `PROOF-NEEDS.adoc` renders with Asciidoctor at `--failure-level WARN`. ## Not in this PR - **CI gate for `src/abi`:** the modules are named `PanicAttack.ABI.*` but live in `src/abi/`, so a plain `idris2 --check src/abi/X.idr` fails on the module name. The status file records the gate as `OPEN`, with the invocation to use. - **PA1's redesign or retirement:** recorded as `OPEN`. --- _Generated by [Claude Code](https://claude.ai/code/session_01Jma5ixtpeZyJRmfoSsC98u)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 36f1055 commit 9986ca4

2 files changed

Lines changed: 202 additions & 82 deletions

File tree

‎PROOF-NEEDS.adoc‎

Lines changed: 190 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
== PROOF-NEEDS.md — panic-attack
1+
= Proof status: panic-attack
22

3-
=== Current State
3+
This file records each proof obligation in panic-attack, the verifier it
4+
belongs to, and its status. The rules are the estate proof policy,
5+
https://github.com/metadatastician/standards/blob/9bdf864cc7f2c8e24b4df84bf00d04158eee3ad5/3-practice/PROOF-POLICY.adoc[`standards/3-practice/PROOF-POLICY.adoc`
6+
at `9bdf864cc7f2c8e24b4df84bf00d04158eee3ad5`]. Statuses use its closed §5
7+
vocabulary: `PROVEN`, `PROVEN-WITH-AXIOMS`, `TESTED`, `ASSUMED`, `OPEN`.
8+
9+
None of these obligations is a theory theorem (§1), so none carries a Proof
10+
Witness Grade.
411

512
*Receipts (2026-11-09).* Until this date no CI job type-checked
613
`+src/abi/+`, and as committed none of the five modules checked: their module
@@ -28,23 +35,65 @@ that DETECTS believe_me in other repos); 282 `+unwrap()+` calls
2835
* *ABI layer*: Idris2 with completeness + soundness proofs + Layer-1.0
2936
stripping foundation
3037
31-
=== Completed Proofs
38+
== Where each kind of obligation belongs
39+
40+
* *Behaviour of first-party Rust code* (stripping, reachability, taint
41+
propagation, dispatch): Creusot with Pearlite contracts, and Verus, on the
42+
implementation (§1.2). An Idris2 model of a Rust function is not evidence
43+
that the function is correct (§1, §2.2).
44+
* *Interfaces, ABI encodings and cross-language protocols* (the attestation
45+
chain, the C integer encodings): Idris2.
46+
* *Statements true of any implementation* (for example, a taint lattice
47+
and its fixed point stated abstractly): Agda, rechecked in Rocq and Lean
48+
(§2).
49+
50+
No Kani obligation arises (§4.1). With `unsafe_code` forbidden,
51+
`cargo clippy --lib --bins --tests --benches --all-features -- -F unsafe_code`
52+
compiles at `f2a6a70eaec0cb02331e3264e05f185b5faab0f7`. The only `unsafe`
53+
is in `examples/vulnerable_program.rs`, a deliberately buggy program that
54+
exists to be scanned.
55+
56+
== Receipt for the Idris2 modules
57+
58+
* *Checker:* Idris2 0.7.0, the version `proven-tests.yml` pins, built from
59+
tag `v0.7.0` (`27780073c8631826d846499840b3857d9b9a4fd5`) on Chez Scheme
60+
9.5.8.
61+
* *Source:* `src/abi/*.idr` as committed. `Stripping.idr` is the re-proof
62+
from #281 (see the ledger row below).
63+
* *Invocation:* the modules are named `PanicAttack.ABI.<M>` but live in
64+
`src/abi/`, so `idris2 --check src/abi/<M>.idr` fails on a module-name
65+
mismatch from any directory. `scripts/ci/check-idris-abi.sh` stages the
66+
committed files at `PanicAttack/ABI/<M>.idr` as links and checks those.
67+
A pass is exit 0 *and* no `Error:` line, because `idris2 --check` can
68+
exit 0 while printing an error.
69+
* *Result:* all five modules pass. Every module sets `%default total` and
70+
uses no `believe_me`, `assert_total`, `assert_smaller`, `postulate` or
71+
`idris_crash`.
72+
* *Negative controls:* against this PR's earlier `Stripping.idr`
73+
(`3dc4728`), a planted false lemma and a planted non-terminating
74+
definition were both rejected, so the check can fail.
75+
* *Gate:* the `idris-abi` job in `.github/workflows/proven-tests.yml` runs
76+
this check on every PR and blocks on failure (#281). The statuses here
77+
rest on that job's receipt for the commit in question; it passed on
78+
`main` at `36f1055`.
3279
33-
[width="100%",cols="26%,21%,53%",options="header",]
80+
== Ledger
81+
82+
[cols="3,2,2,5",options="header"]
3483
|===
35-
|Proof |File |What it proves
36-
|PA1 Pattern detection completeness |`+src/abi/PatternCompleteness.idr+`
37-
|All 49 `+Lang+` constructors have an analyzer; all 20 `+WPCategory+`
38-
constructors have at least one detector; cross-language checks applied
39-
unconditionally to all languages. `+completeScanForAll+` is the
40-
top-level theorem.
41-
42-
|PA2 Classification soundness |`+src/abi/ClassificationSoundness.idr+`
43-
|Severity (Low/Medium/High/Critical) is totally ordered (`+LTE+`);
44-
`+maxSeverity+` is commutative and idempotent; numeric ABI encoding
45-
preserves the ordering.
46-
47-
|Layer 1.0 line-comment idempotence |`+src/abi/Stripping.idr+`
84+
|Obligation |Artefact |Status |Trust boundary and notes
85+
86+
|Severity order: `Low < Medium < High < Critical` is a total order;
87+
`sevMax` is an upper bound; the numeric encoding is monotone (PA2)
88+
|`src/abi/ClassificationSoundness.idr`
89+
|`PROVEN` (model)
90+
|The model's `Severity` matches the variant names and order of
91+
`src/types.rs`; that correspondence is `ASSUMED` (a hand transcription).
92+
The Rust order itself comes from `#[derive(PartialOrd, Ord)]`.
93+
94+
|Line-comment stripping is idempotent: `strip (strip s) = strip s`
95+
|`src/abi/Stripping.idr`
96+
|`PROVEN` (model)
4897
|*Re-proved 2026-11-09.* The 2026-06-02 proof (issue #113) never
4998
type-checked: its `+//+` case relied on reductions that do not hold for a
5099
variable character, and it used `+decEq+` without importing it. The new proof
@@ -59,29 +108,81 @@ definitions. A mutant that blanks with `+/+` instead of a space is rejected.
59108
Nine closed sanity theorems, including two comments on different lines and
60109
`+///+`.
61110

62-
|Attestation chain unforgeability
63-
|`+src/abi/AttestationUnforgeability.idr+` |*PROOF-PROGRAMME §3.2
64-
(2026-06-04, issue #123)*: models the intent→evidence→seal chain
65-
(`+chain_hash = H(intent‖evidence‖report)+`, Ed25519-signed) with the
66-
cryptographic facts as a `+parameters+` block (hypotheses, *not*
67-
`+postulate+`). Under `+%default total+` Qed-closes `+integrity+`
68-
(tampering any phase invalidates the seal), `+authenticity+` (a
69-
verifying seal comes from the matching secret key), `+nonRepudiation+`
70-
(a genuine seal verifies), plus 2 corollaries. Conditional on chain-hash
71-
collision-resistance + Ed25519 EUF-CMA (message- and signer-binding) +
72-
signature correctness.
73-
74-
|Hexad↔Octad persistence round-trip |`+src/storage/mod.rs+` (proptest)
75-
|*PROOF-PROGRAMME §3.1 (2026-06-04, #122)*:
76-
`+hexad_json_roundtrip_is_identity+` tests an in-memory
77-
`+serde_json::Value+` serialize/deserialize/serialize round-trip on generated
78-
samples, not by a universal theorem. It does not call `+write_*_hexad+` or
79-
`+load_hexad_dir+`; on-disk persistence correspondence remains a separate
80-
obligation. The gateway octad projection is lossy by design, so this property
81-
also does not establish a faithful hexad↔octad map.
111+
The model does *not* match `strip_proof_comments`, so it is evidence about
112+
the model only. It replaces comment characters with spaces and keeps every
113+
newline. The Rust function deletes comment text and drops a trailing
114+
newline: on `//x` the model gives three spaces and Rust gives the empty
115+
string. The model also covers line comments only; block comments and string
116+
literals are not modelled.
117+
118+
|Attestation chain: integrity, authenticity, non-repudiation
119+
|`src/abi/AttestationUnforgeability.idr`
120+
|`PROVEN` (model), relative to the `ASSUMED` hypotheses listed here
121+
|The module's `parameters` block assumes:
122+
123+
* `chainCR`: the chain hash is *injective*.
124+
* `sigCorrect`: an honest signature verifies.
125+
* `sigBindsMessage`: a signature verifies only on the message signed.
126+
* `sigOnlySigner`: for every verifying signature there is a secret key
127+
whose public key is the verifying key and whose signature on that digest
128+
is that signature.
129+
130+
`sigOnlySigner` says such a key *exists*. It says nothing about who
131+
produced the signature, so `authenticity` inherits that limit: it shows the
132+
seal equals one a matching key would make, not that the key holder made it.
133+
`chainCR` and `sigOnlySigner` are idealisations, stronger than collision
134+
resistance and EUF-CMA, and false of any real fixed-length hash or
135+
signature scheme. So these are theorems of a symbolic (Dolev-Yao style)
136+
model, not a computational security reduction. Model to
137+
`src/attestation/`: `ASSUMED`. A computational proof is not claimed.
138+
139+
|Every language reaches an analyzer; every weak-point category has a
140+
detector; cross-language checks run on every file (PA1)
141+
|`src/abi/PatternCompleteness.idr`
142+
|`PROVEN` (model); supports no claim about the Rust code
143+
|The theorem is vacuous: `GenericAnalyzer : HasAnalyzer lang` inhabits
144+
the witness type for every language, so it holds whatever the dispatch
145+
does. Rust gives the narrower guarantee that actually holds:
146+
`match file_lang` in `src/assail/analyzer.rs` ends in
147+
`_ => analyze_generic`, and `rustc` checks the match is exhaustive. That
148+
covers every file that reaches the match. A file with no source language
149+
and no configuration adapter (`Language::Unknown`, no adapter) is marked
150+
`unsupported` in the coverage ledger and skipped first, so not every file
151+
reaches an analyzer.
152+
153+
The model has also drifted. Its `Lang` has 50 constructors and
154+
`src/types.rs` has 52; `C` and `Php` are missing. `crossLangAlwaysApplied`
155+
says cross-language checks run on every file, but the Rust code skips them
156+
when `configuration.is_some()`. That model claim is false of the
157+
implementation.
158+
159+
|Declarations for the ABI-facing types and their C integer encodings
160+
|`src/abi/Types.idr`
161+
|No theorem
162+
|Repaired in `3dc4728` so it compiles. It contains no proof and nothing
163+
imports it. Drift: its `Severity` is `Info / Warning / Error / Critical`
164+
where `src/types.rs` has `Low / Medium / High / Critical`, and `LangId` is
165+
bounded at 47 against 52 variants.
166+
167+
|Hexad JSON round-trip is the identity
168+
|`src/storage/mod.rs`, `hexad_json_roundtrip_is_identity` (proptest)
169+
|`TESTED`
170+
|A serialize, deserialize, serialize round trip on proptest-generated
171+
hexads, compared as `serde_json::Value`. Bounds: proptest's default 256
172+
cases (the repository sets no override). `id` and `program_path` are 0 to
173+
48 characters from `[A-Za-z0-9:_./-]`; `language` 0 to 12 lowercase
174+
letters; `version` 1 to 8 characters from `[0-9.]`; the four counts are
175+
below 10,000; `robustness_score` is in [0, 1]; `categories` holds 0 to 5
176+
strings of 1 to 16 letters; `attestation_hash` is absent or up to 64 hex
177+
digits. Fixed, not generated: `schema`, `created_at`, `tool`, and
178+
`document` (`{"weak_points": [], "n": total}`), and the `migration`,
179+
`finding`, `campaign` and `crosslang` facets are all `None`. It does not call
180+
`write_*_hexad` or `load_hexad_dir`, so on-disk persistence is a separate
181+
obligation. The gateway octad projection is lossy by design, so this does
182+
not establish a faithful hexad-to-octad map.
82183
|===
83184

84-
=== Model-Checked (TESTED, bounded)
185+
== Model-checked (TESTED, bounded)
85186

86187
[width="100%",cols="26%,30%,44%",options="header",]
87188
|===
@@ -101,43 +202,60 @@ state. *§6 deviation (open)*: TLC is fetched from its release, digest-checked,
101202
because neither Guix nor the container provides it yet.
102203
|===
103204

104-
=== What Still Needs Proving
205+
== Open obligations
105206

106-
[width="100%",cols="51%,27%,22%",options="header",]
107-
|===
108-
|Component |What |Why
109-
|Generation publish: pure decisions (`src/publish.rs`) |*OPEN* (PROOF-POLICY
110-
§1.2): Creusot/Pearlite and Verus contracts for the supersede comparison and
111-
the collect selection (never removes the current or a newer generation; keeps
112-
the `keep` newest older ones) |The model check covers the protocol, not the Rust
113-
code; these tie the implementation to P1 and P2
114-
115-
|*Layer 1.0 — stripBlockComments + Strings + Composition +
116-
Position-Preservation* (issue #114) |Block-comment (`+/* */+`) and
117-
string-literal (`+"..."+`) strippers with same mutual-recursive shape;
118-
composition theorem proving the full pipeline is idempotent given each
119-
component is; position-preservation theorem justifying analyzer
120-
location-reporting against the stripped view as if it were
121-
original-source. |Four slices: `+Stripping_Block.idr+`,
122-
`+Stripping_Strings.idr+`, `+Stripping_Composition.idr+`,
123-
`+Stripping_PositionPreservation.idr+`.
124-
125-
|Bridge reachability soundness |Reachability analysis is sound (no
126-
reachable dep wrongly classified as phantom) |Unreachable code marked
127-
reachable wastes effort; reachable missed = security gap
128-
129-
|Kanren taint analysis |Taint propagation tracks all tainted data flows
130-
|Missed taint flow means missed vulnerability
207+
[cols="3,2,5",options="header"]
131208
|===
209+
|Obligation |Verifier (§1, §1.2) |Notes
210+
211+
|Generation publish: pure decisions (`src/publish.rs`). The supersede
212+
comparison and the collect selection never remove the current or a newer
213+
generation, and keep the `keep` newest older ones
214+
|Creusot/Pearlite and Verus (§1.2)
215+
|*OPEN*. The model check above covers the protocol, not the Rust code;
216+
these contracts tie the implementation to P1 and P2.
217+
218+
|`strip_proof_comments` is idempotent and preserves positions outside
219+
comments and strings
220+
|Fix the implementation first; then Creusot/Pearlite and Verus
221+
|Neither property holds of the current Rust function, so neither can be
222+
proved until it changes. All three cases below were run against the
223+
function as it is on `main`:
132224

133-
=== Recommended Prover
225+
* Not idempotent: `a//*x*/*b*/c` gives `a/*b*/c`, and a second pass gives
226+
`ac`.
227+
* Positions move: `a/*x*/b` gives `ab`, moving `b` from offset 6 to 1.
228+
* Ordering bug: block comments are stripped before line comments, so a
229+
block opener inside a line comment swallows the code after it.
230+
`code // see /* note`, then `hidden();`, then `*/ tail`, gives `code `.
231+
The callers that pass both a line and a block marker are affected:
232+
`analyze_rust`, `is_rust_ffi_safe_wrapper`, `analyze_idris`,
233+
`analyze_lean` and `analyze_agda`. In the Idris, Lean and Agda ProofDrift
234+
detectors such a comment can hide a later `sorry`, `believe_me` or
235+
postulate. `analyze_isabelle` and `analyze_coq` pass no line marker and
236+
are not affected.
134237

135-
*Idris2* — Already in use. Taint analysis correctness proofs could use
136-
*Agda* with relational semantics. The 282 unwrap() calls are a
137-
significant debt (but separate from the proof obligations).
238+
The Idris2 model above can guide the contracts once the function is
239+
fixed; it does not discharge them. The model's own remaining slices
240+
(block comments, strings, composition, position preservation; issue #114)
241+
are optional once the implementation proof exists.
138242

139-
=== Priority
243+
|Patch Bridge reachability is sound: no reachable dependency is classified
244+
as phantom
245+
|Creusot/Pearlite and Verus
246+
|`src/bridge/reachability.rs`. A missed reachable dependency is a security
247+
gap.
140248

141-
*MEDIUM* (was HIGH) — PA1 and PA2 completed 2026-04-11. The highest-risk
142-
false-negative scenario (analyzer dispatch completeness) is now formally
143-
proved. Remaining proofs are deeper semantic properties.
249+
|Kanren taint analysis tracks every tainted flow
250+
|Creusot/Pearlite and Verus; Agda for the abstract theory
251+
|Any implementation-independent statement (the lattice, monotonicity, the
252+
fixed point) is theory and belongs in Agda with Rocq and Lean rechecks.
253+
Its realisation in `src/kanren/` is a Rust obligation.
254+
255+
|Replace or retire PA1
256+
|Creusot/Pearlite and Verus, or retire
257+
|A non-vacuous statement would be, for example, that each language with
258+
a dedicated analyzer is routed to it. If that is not wanted, retire the
259+
module, because `rustc`'s exhaustiveness check already gives the current
260+
guarantee.
261+
|===

‎src/abi/Types.idr‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
44
||| ABI Types for panic-attack static analysis engine
55
|||
6-
||| Defines the formal interface for the scanner's operations.
7-
||| Proves that:
8-
||| 1. Severity levels are totally ordered
9-
||| 2. Scan results cannot be fabricated (constructive)
10-
||| 3. Language coverage is bounded
6+
||| Declares ABI-facing types and their C integer encodings. It contains no
7+
||| theorems, and no other module imports it. The severity order is proved
8+
||| in ClassificationSoundness.idr, over its own Severity type.
9+
|||
10+
||| Known drift (see PROOF-NEEDS.adoc): this Severity type does not match
11+
||| src/types.rs, and LangId is bounded at 47 while src/types.rs has 52
12+
||| Language variants.
1113
module PanicAttack.ABI.Types
1214

1315
import Data.Fin
@@ -18,14 +20,14 @@ import Data.Fin
1820
public export
1921
data Severity = Info | Warning | Error | Critical
2022

21-
||| Equality on severity, required by `Ord`.
2223
public export
24+
||| Equality on severity, required by `Ord`.
2325
Eq Severity where
24-
Info == Info = True
25-
Warning == Warning = True
26-
Error == Error = True
26+
Info == Info = True
27+
Warning == Warning = True
28+
Error == Error = True
2729
Critical == Critical = True
28-
_ == _ = False
30+
_ == _ = False
2931

3032
||| Total ordering on severity
3133
public export

0 commit comments

Comments
 (0)