diff --git a/.machine_readable/6a2/STATE.a2ml b/.machine_readable/6a2/STATE.a2ml index 44682e5..190b064 100644 --- a/.machine_readable/6a2/STATE.a2ml +++ b/.machine_readable/6a2/STATE.a2ml @@ -44,19 +44,19 @@ property-tests = "9 (2026-04-03 assessment, not re-derived)" regression-tests = "5 (2026-04-03 assessment, not re-derived)" idris2-proofs = "12 PROVEN ledger rows (the former 30 counted lemmas before the tautology purge; PROOF-NEEDS.adoc is authoritative)" benchmarks = "5 Criterion groups (no baseline recorded)" -total = "143 tests + 5 benchmark groups + 12 PROVEN ledger rows — as declared in READINESS.adoc and measured by dashboard-check" +total = "144 tests + 5 benchmark groups + 12 PROVEN ledger rows — as declared in READINESS.adoc and measured by dashboard-check" [proof-grades] # Proof Witness Grades, standards 3-practice/PROOF-POLICY.adoc §8 (the # Mathesis brief's §5/§6 ladder, adopted with corrections). Never a # percentage. Receipts, lineage and per-row records: docs/theory/PROOF-GRADES.adoc. -grade-3 = "PWG-3: G-1, T-2, T-3, E-1m; PWG-2ii: T-1 (Rocq and Lean legs re-proved and reconciled) — census 4 + 1 of 5 theory theorems (G-3 and T-10 are engineering under PROOF-POLICY §1; T-2 and T-3 are stated over the abstract SingleActiveLog)" -receipt-commit = "see docs/theory/PROOF-GRADES.adoc, The PWG-3 receipt (the 4afb710 and fc188c4 receipts are superseded)" +grade-3 = "derived from verification/receipts/januskey_praxis.deed by the pinned standards reader: PWG-1 for T-1 (Agda, Rocq and Lean receipts at b503488); PWG-3 for G-1, T-2, T-3, E-1m, whose Rocq and Lean legs are re-proved and reconciled but have no receipt yet — census 4 + 1 of 5 theory theorems (G-3 and T-10 are engineering under PROOF-POLICY §1; T-2 and T-3 are stated over the abstract SingleActiveLog)" +receipt-commit = "verification/receipts/januskey_praxis.deed: source commit b503488, run 43213340167; earlier runs superseded (see docs/theory/PROOF-GRADES.adoc)" receipt-prover = "Agda 2.6.4.3 (agda-bin=2.6.4.3-1+b2); no standard library; resource-algebra pinned at cf9235c" receipt-flags = "--safe --without-K --cubical-compatible --no-libraries --ignore-interfaces --double-check (PROOF-POLICY §2.1 canonical, plus two stricter flags)" not-graded = "the 7 Idris2 PROVEN rows (ABI/interface contracts, PROOF-POLICY §8.1); all 33 TESTED rows (observed behaviour); ASSUMED/DESIGNED/OPEN rows" -open-obligations = "Rocq and Lean legs for the four PWG-3 rows (PROOF-POLICY §2); no Creusot or Verus proof on the Rust, so no Rust behaviour is proved" -claimed-higher = "PWG-2ii for T-1 only (Rocq and Lean legs re-proved and reconciled); no PWG-2i or PWG-1 is claimed" +open-obligations = "record the first green main run of the recheck legs of G-1, T-2, T-3 and E-1m in the receipt; no Creusot or Verus proof on the Rust, so no Rust behaviour is proved" +claimed-higher = "PWG-1 for T-1 only, as derived from the receipt; no PWG-2i or PWG-2ii, and no foundation-diverse witness" [test-categories-complete] unit = true diff --git a/PROOF-NEEDS.adoc b/PROOF-NEEDS.adoc index 6148558..d8a17ab 100644 --- a/PROOF-NEEDS.adoc +++ b/PROOF-NEEDS.adoc @@ -62,15 +62,15 @@ tables must agree. | C-3 | A transaction containing an obliteration is not all-reversible | PROVEN | `+Layout.obliterateNotReversible+` | C-4 | Replacing a chain entry by one with a different hash breaks the link | PROVEN | `+Proofs.tamperBreaksLink+` | C-5 | Struct sizes 32/16/112 and 8-byte alignment as divisibility (statements about the literals) | PROVEN | `+Layout.{contentHashSize,keyIdSize,oblitProofSize,hashAligned,keyIdAligned,oblitAligned}+` -| G-1 | Reversibility as a Loss grade: lossless traces have only lossless steps; obliteration absorbs; a wrap/unwrap pair carries its cancellation law (its grade 𝟙 is assigned, not derived from that law) | PROVEN | `+verification/proofs/agda/Reversibility.agda+` (Agda kernel, resource-algebra pinned at `+cf9235c+`); `+tests/reject-agda/*+` refused; the cancellation premise is the TESTED row `+execute_then_undo_is_identity+` +| G-1 | Reversibility as a Loss grade: lossless traces have only lossless steps; obliteration absorbs; a wrap/unwrap pair carries its cancellation law (its grade 𝟙 is assigned, not derived from that law) | PROVEN | `+verification/proofs/agda/Reversibility.agda+` (Agda kernel, resource-algebra pinned at `+cf9235c+`); `+tests/reject-agda/*+` refused; rechecked in Rocq and Lean (`+verification/proofs/{rocq,lean}/Reversibility+`, the Loss grade restated, legs not yet in the receipt); the cancellation premise is the TESTED row `+execute_then_undo_is_identity+` | G-2 | The Idris2 `+IsCNO+`/`+ReversibleOp+` pair corresponds to Agda `+ReversiblePair+` (by transcription) | ASSUMED | no mechanical link claimed | G-3 | The FFI bridge preserves grade 𝟙 (homomorphism) | OPEN | resource-algebra lists homomorphisms OPEN; to file from JNK-01 | E-1 | An attacker cannot recover obliterated content or use a revoked key | OPEN | `+Types.adversaryCannotKnow+` holds only because `+Knows+` has no Adversary constructor; the *model-level* half is now proved in Agda as row E-1m (#145 item 3) -| E-1m | In a world model, an adversary whose observation excludes the store does not know what it holds; obliteration leaves nothing to recover; rotation to a different key leaves no agent able to use the old one (premise `+old ≠ new+`; true by the definition of `+rotate+` in the model; that an unusable key cannot decrypt is X-1) | PROVEN | `+verification/proofs/agda/Epistemic.agda+`; `+tests/reject-agda/{AdversaryKnows,OldKeyStillUsable}.agda+` refused +| E-1m | In a world model, an adversary whose observation excludes the store does not know what it holds; obliteration leaves nothing to recover; rotation to a different key leaves no agent able to use the old one (premise `+old ≠ new+`; true by the definition of `+rotate+` in the model; that an unusable key cannot decrypt is X-1) | PROVEN | `+verification/proofs/agda/Epistemic.agda+`; rechecked in Rocq and Lean (`+verification/proofs/{rocq,lean}/Epistemic+`, legs not yet in the receipt); `+tests/reject-agda/{AdversaryKnows,OldKeyStillUsable}.agda+` refused | X-1 | Hash one-wayness; physical erasure (cryptographic and physical assumptions, external to this repository) | ASSUMED | not theorems of this repo | T-1 | Undoing a fully executed transaction's operations in reverse order restores the state it began in, given each step's undo restores its execute (the sequential Theorem 3.4) | PROVEN | `+TransactionAtomicity.rollback-restores+`; rechecked in Rocq and Lean (`+verification/proofs/{rocq,lean}/Rollback+`, `+PWG-1+`); `+tests/reject-agda/ForwardRollback.agda+` refused -| T-2 | In any single-active log (records with a decidable key and an active or settled phase), opening a fresh active record, a key- and phase-preserving edit, and a settling transition each preserve the invariant and rewrite only the active record, so a settled one is never modified | PROVEN | `+SingleActiveLog.{begin-good,modify-good,finish-good,update-active}+`; `+tests/reject-agda/SettleWithoutSettling.agda+` refused; januskey's instance is `+TransactionAtomicity.lifecycle-preserves-good+`; `+tests/reject-agda/CommitWhenIdle.agda+` refused -| T-3 | In any single-active log satisfying the invariant, at most one record is active, and exactly one when the pointer is set | PROVEN | `+SingleActiveLog.at-most-one-active+` (januskey's transactions are an instance) +| T-2 | In any single-active log (records with a decidable key and an active or settled phase), opening a fresh active record, a key- and phase-preserving edit, and a settling transition each preserve the invariant and rewrite only the active record, so a settled one is never modified | PROVEN | `+SingleActiveLog.{begin-good,modify-good,finish-good,update-active}+`; rechecked in Rocq and Lean (`+verification/proofs/{rocq,lean}/SingleActiveLog+`, legs not yet in the receipt); `+tests/reject-agda/SettleWithoutSettling.agda+` refused; januskey's instance is `+TransactionAtomicity.lifecycle-preserves-good+`; `+tests/reject-agda/CommitWhenIdle.agda+` refused +| T-3 | In any single-active log satisfying the invariant, at most one record is active, and exactly one when the pointer is set | PROVEN | `+SingleActiveLog.at-most-one-active+`; rechecked in Rocq and Lean (`+verification/proofs/{rocq,lean}/SingleActiveLog+`, legs not yet in the receipt) (januskey's transactions are an instance) | T-4 | A rollback that fails part-way can be retried to completion | TESTED | `+rollback_resume_test+` drives the real `+jk+`: after one undo error and a repair, `+jk rollback+` skips the already undone operation and finishes (before the fix the retry stopped at it every time, reproduced 2026-10-26); fixed in `+cmd_rollback+` | T-5 | The transaction log is never left disagreeing with memory by a failed save, and is replaced by rename rather than overwritten in place, with an fsync before the rename by construction (no test observes the fsync) (a randomly named temporary file opened with the old file's mode, removed only if this save created it) rather than overwritten in place | TESTED | `+transaction::tests::failed_save_*+`: a save that fails at the final step leaves begin, add_operation, commit and rollback unapplied in memory; mutants (memory first, plain `+fs::write+`, no temp cleanup, shared temp name, truncating open, no permission copy) each fail a test. Not claimed: crash-safety of the rename itself is by construction, not crash-injected; the directory fsync is best effort (owner decision 2026-11-09), because failing the save after the rename would leave disk new and memory old; concurrent writers are out of scope (each save's content is intact, the last rename wins) | T-6 | A failed execute leaves the filesystem unchanged, and each undo restores the state its execute started from (premises of T-1; single steps are TESTED by `+execute_then_undo_is_identity+`) | ASSUMED | not checked for the failure path @@ -150,9 +150,11 @@ link:docs/theory/PROOF-GRADES.adoc[`+docs/theory/PROOF-GRADES.adoc+`]. *PWG census, theory theorems of this repository (denominator 5):* `+PWG-3+` 4 (G-1, T-2, T-3, E-1m) · `+PWG-2i+` 0 · `+PWG-2ii+` 0 · `+PWG-1+` 1 (T-1) · `+ungraded+` 0. G-3 names this repository's FFI bridge, so PROOF-POLICY §1 -classes it as engineering and it is outside the ladder. T-1's Rocq and Lean legs are re-proved and reconciled -(`+docs/theory/PROOF-GRADES.adoc+`, §T-1); the other four have not been -attempted, and each still owes both (§8.4: a grade is not a discharge). +classes it as engineering and it is outside the ladder. Every row now has a Rocq leg and a Lean leg, re-proved by hand and +reconciled statement by statement (`+docs/theory/PROOF-GRADES.adoc+`, §The recheck +legs). The legs of G-1, T-2, T-3 and E-1m enter the receipt's claim list once a +CI run on `+main+` has checked them; the reader then derives their grade. A grade +is not a discharge (§8.4): the premises each row names stay where they are. The other seven PROVEN rows — A-1, A-2, C-1 to C-5 — are Idris2 theorems. Under PROOF-POLICY §1 those are interface and ABI contracts, so the theory ladder does diff --git a/READINESS.adoc b/READINESS.adoc index 686e2fd..f3a9ff9 100644 --- a/READINESS.adoc +++ b/READINESS.adoc @@ -8,7 +8,7 @@ standards/testing-and-benchmarking/TESTING-TAXONOMY.adoc v1.0 === CRG Grade: D (Alpha — Unstable) -*Justification:* 143 tests declared (`cargo test --workspace --locked -- --list`; rust-ci runs them); the +*Justification:* 144 tests declared (`cargo test --workspace --locked -- --list`; rust-ci runs them); the Idris2 ABI typechecks and 12 proofs are checked (PROVEN ledger rows: ABI, grade, transaction-model and epistemic-model lemmas, not the security obligations); benchmarks exist (5 Criterion groups). But: no fuzz testing, no mutation testing, 241 unwrap() calls, E2E mostly skips, @@ -65,7 +65,7 @@ handling (run by idris-abi.yml, agda-proofs.yml and dashboard-check) |=== -*Total declared:* 143 tests + 5 benchmark groups; 12 proofs checked (PROVEN ledger rows; five are theory theorems under PROOF-POLICY §8: four at PWG-3 and T-1 at PWG-2ii — see `docs/theory/PROOF-GRADES.adoc`) *Total +*Total declared:* 144 tests + 5 benchmark groups; 12 proofs checked (PROVEN ledger rows; five are theory theorems under PROOF-POLICY §8, graded from the receipt: T-1 at PWG-1 and four at PWG-3, whose Rocq and Lean legs check but have no CI receipt yet — see `docs/theory/PROOF-GRADES.adoc`) *Total missing:* Fuzz, mutation, chaos, compatibility === Aspect Matrix diff --git a/TOPOLOGY.adoc b/TOPOLOGY.adoc index ba10832..fcb8922 100644 --- a/TOPOLOGY.adoc +++ b/TOPOLOGY.adoc @@ -79,7 +79,7 @@ INTERFACES & RESEARCH MPR Methodology ████░░░░░░ ~40% Design documented; FORMAL PROOFS PENDING (Idris2 ABI typechecks; 12 proofs checked: ABI, grade, transaction-model and epistemic-model lemmas, not the security obligations; MPR not linked to the Rust) - Testing (READINESS matrix) ██████░░░░ ~60% 143 tests + 5 benches; missing fuzz, mutation, + Testing (READINESS matrix) ██████░░░░ ~60% 144 tests + 5 benches; missing fuzz, mutation, chaos, compatibility (Grade D) REPO INFRASTRUCTURE diff --git a/docs/theory/PROOF-GRADES.adoc b/docs/theory/PROOF-GRADES.adoc index 4d47116..0675b5e 100644 --- a/docs/theory/PROOF-GRADES.adoc +++ b/docs/theory/PROOF-GRADES.adoc @@ -16,7 +16,9 @@ repository, and none is introduced here. `PWG-3` 4 (G-1, T-2, T-3, E-1m) · `PWG-2i` 0 · `PWG-2ii` 0 · `PWG-1` 1 (T-1) · `ungraded` 0. `+foundation-diverse`: none. Axioms: none. Derived by the pinned standards reader from `verification/receipts/januskey_praxis.deed` (§The -machine-readable receipt below), not typed. +machine-readable receipt below), not typed. G-1, T-2, T-3 and E-1m now also have +Rocq and Lean legs (§The recheck legs below). They join the receipt once a CI +run on `main` has checked them, and the reader then derives their grade. The denominator is the ledger rows whose source of truth is an Agda theorem. PROOF-POLICY §1 puts a statement that names one repository's type, function or @@ -128,6 +130,14 @@ run the §8.5.3 git checks (each manifest holds at its commit, the and warn when a leg's inputs have changed since the receipt's source commit. This page is the human reading of that file. +The change that added the Rocq and Lean legs of G-1, T-2, T-3 and E-1m added +files to `verification/proofs/rocq` and `verification/proofs/lean`, which are +T-1's recheck inputs, and changed their checker, `scripts/check-recheck.sh`. The +receipt still describes `b503488` and stays true of it, so T-1 is `PWG-1` there; +the CI job warns that HEAD has moved on. The follow-up that records the first +green `main` run after that change adds it to the run ledger, adds the four +rows' legs to the claim list, and the reader derives all five grades afresh. + The receipt describes commit `b5034884dbe945139d03b38fe80cfdf1106a77e1` on `main`. The gate changed twice before it, in hyperpolymath/januskey#170 (the import-cone postulate scan) and #174 (a token may start after a skipped literal), and #171 @@ -143,7 +153,7 @@ changes is `superseded`, and the current one is a run on `main` after all three. https://github.com/hyperpolymath/januskey/actions/runs/43213340167[43213340167], branch `main`, conclusion **success**: job "Reversibility as a grade (Loss instance), expected rejections" (Agda) and job "Rocq and Lean recheck legs, - expected rejections" (T-1's legs, §T-1 below) + expected rejections" (T-1's legs, §The recheck legs below) | Commit | `b5034884dbe945139d03b38fe80cfdf1106a77e1` (started 2026-11-12T11:55:42Z) | Prover | `agda-bin=2.6.4.3-1+b2` on Debian trixie-slim (`@sha256:a29215f6…`), asserted by a passing step: @@ -204,22 +214,27 @@ Earlier receipts, kept with their lineage (§8.4) here and in the receipt file: Those are the `PWG-3` facts: the propositions type-check in Agda under the §2.1 invocation, in CI, at a named commit, with the prover version pinned and -the import cone recorded. For G-1, T-2, T-3 and E-1m no Rocq or Lean leg exists, so -no recheck leg counts and their grade is `PWG-3`. T-1 has both legs, and each +the import cone recorded. For G-1, T-2, T-3 and E-1m the Rocq and Lean legs +exist (§The recheck legs below), but no CI run on `main` has checked them yet, so +no receipt counts them and their grade is `PWG-3`. T-1 has both legs, and each counted witness (Agda, Rocq and Lean) has a current receipt from a pinned CI checker run on the receipt's source commit itself, so the reader derives -`PWG-1` (§8.2; §T-1 below). No witness in another foundation exists, so +`PWG-1` (§8.2; §The recheck legs below). No witness in another foundation exists, so `foundation_diverse` is false throughout. -=== Why four rows stop at PWG-3 +=== Why four rows are at PWG-3 -PWG-2i and above require an Agda → Dedukti → Rocq/Lean transport or a -re-proof, with the outcome recorded as `transported`, `re-proved` or -`unavailable` (PROOF-POLICY §2). For T-1 that work is done (§T-1 below, now -`PWG-1`); for G-1, T-2, T-3 and E-1m it has not been done and is not -claimed. A recheck would not change what these modules prove: §2.2 is explicit that compiling -in a second prover does not establish the same proposition unless the -correspondence is checked too. +`PWG-2i` and above require Rocq or Lean legs, with the outcome recorded as +`transported`, `re-proved` or `unavailable` (PROOF-POLICY §2), and a current +receipt for each counted leg. All four rows now have both legs, re-proved and +reconciled (§The recheck legs below). What they lack is the receipt: the first +green `main` run of the recheck job after the legs landed. When that run is +recorded in the receipt's run ledger and claim list, the reader derives their +grade: `PWG-1` if every counted witness is checked at the receipt's source +commit, as for T-1 (§8.2). A recheck would not change what these modules prove: +§2.2 is explicit that compiling in a second prover does not establish the same +proposition unless the correspondence is checked too, which is why each leg +carries its statement comparison. == The §2.1 invocation: adopted, and measured (2026-11-01) @@ -338,9 +353,12 @@ repeated the counts, and the two copies drifted apart. ==== Leg records (PROOF-POLICY §8.5) -The same record holds for each of G-1, T-2, T-3 and E-1m, so it is given once. -`pwg: 3`, `foundation_diverse: false`. T-1 has its own record below -(§T-1: the first recheck legs). +Every theory row now has both recheck legs, re-proved by hand, so one record +serves all five; only the receipts differ. T-1: `pwg: 1`, derived by the reader +from run 43213340167 at `b503488`, which checked all three of its witnesses. +G-1, T-2, T-3 and E-1m: `pwg: 3`. Their legs have no CI receipt yet, so the +receipt's claim list does not include them, and the reader counts none. +`foundation_diverse: false` throughout. [cols="1,1,1,1,3",options="header"] |=== @@ -352,83 +370,81 @@ The same record holds for each of G-1, T-2, T-3 and E-1m, so it is given once. | `AGDA-VERIFIED` | §The receipt above, with its lineage -| Rocq -| none: not attempted -| `OPEN` -| none: no target statement exists to compare -| none - -| Lean -| none: not attempted -| `OPEN` -| none: no target statement exists to compare -| none -|=== - -§8.5's route values (`transported`, `re-proved`, `waived`, `unavailable`) each -describe a leg that was tried, excused or found impossible. None applies to a -leg nobody has started, so the route field says that instead of borrowing one. -When a leg is started, its row gets the route, the target statement, the -comparison with the Agda statement and its receipts, and the PWG is recomputed. - -==== T-1: the first recheck legs (2026-11-09) - -T-1 is the pilot for PROOF-POLICY §2, chosen because its statement is small and -abstract. Its Agda module imports `ResourceAlgebra.Prelude` from the pinned -sibling, but the `Rollback` part uses only three things from it: `_≡_` (Agda's -builtin equality, re-exported) and the elementary `trans` and `cong`. Those are -accounted for in the comparison below. `pwg: 1` (derived by the reader: both legs count, and every counted -witness has a current receipt at the source commit), `foundation_diverse: -false`. - -[cols="1,1,1,1,3",options="header"] -|=== -| Leg | Route | §5 token | §2.2 state | Receipts - -| Agda (source) -| source of truth -| `PROVEN` -| `AGDA-VERIFIED` -| §The receipt above - | Rocq | `re-proved` | `PROVEN` | `RECONCILED` -| `agda-proofs.yml` job "Rocq and Lean recheck legs", on this change and then - on `main`; current receipt: run 43213340167 at `b503488`, the receipt's - source commit +| T-1: run 43213340167, job "Rocq and Lean recheck legs", at `b503488`, in the + receipt. The other four: none yet. Their first receipt is that job's first + green run on `main` after the legs landed, which then joins the receipt's run + ledger | Lean | `re-proved` | `PROVEN` | `RECONCILED` -| the same job +| as for Rocq +|=== + +[cols="1,2,2,2",options="header"] +|=== +| Row | Agda source | Rocq leg | Lean leg + +| G-1 | `Reversibility.agda` | `rocq/Reversibility.v` | `lean/Reversibility.lean` +| T-1 | `TransactionAtomicity.agda`, module `Rollback` | `rocq/Rollback.v` | `lean/Rollback.lean` +| T-2, T-3 | `SingleActiveLog.agda` | `rocq/SingleActiveLog.v` | `lean/SingleActiveLog.lean` +| E-1m | `Epistemic.agda` | `rocq/Epistemic.v` | `lean/Epistemic.lean` |=== +Paths are under `verification/proofs/`. + +==== The recheck legs (T-1 2026-11-09, then G-1, T-2, T-3 and E-1m) + +T-1 was the pilot, chosen because its statement is small and abstract. The other +four followed the same route. + *Why re-proved.* §2 asks for transport first. The Agda → Dedukti translator (`Deducteam/Agda2Dedukti`, last changed 2022-01-24 at `c7c7d67`) builds against a forked Agda branch of that period and its documentation pins Lambdapi 2.1.0. It cannot read modules checked by the pinned Agda 2.6.4.3, so no transport route exists for this toolchain. For Lean, §2 already says to re-prove until a -released Lambdapi has a Lean exporter. Both legs are therefore re-proved by -hand, in each prover's core library: no Mathlib, no imports in the Lean file, -only the prelude in the Rocq file. +released Lambdapi has a Lean exporter. Every leg is therefore re-proved by +hand, in each prover's core library: no Mathlib and no imports in the Lean +legs, and only the prelude in the Rocq legs. -*The statements, side by side.* +*The statements, side by side.* Each leg restates every theorem the row cites, +and the lemmas they rest on, under the same name in each prover's identifier +syntax (`-` becomes `_`, `𝟙` becomes `one`, `++` becomes `app`). + +[cols="1,3",options="header"] +|=== +| Row | Theorems restated in both legs + +| G-1 | `all-lossless-trace`, `lossless-trace-all`, `obliterate-absorbs`, + `obliterated-not-lossless`, `wrap-unwrap-𝟙`, `wrap-unwrap-id` +| T-1 | `rollback-restores` +| T-2 | `begin-good`, `modify-good`, `finish-good`, `update-active`, and the + three refusal lemmas +| T-3 | `at-most-one-active`, with `settled-count` and `count-++` +| E-1m | `knows-observation`, `different-store-unknown`, `adversary-ignorant`, + `obliterate-cuts-recovery`, `obliterate-ignorance`, `rotate-keeps-new`, + `rotate-forgets-old`, `rotate-forgets-canUse` +|=== + +For example, T-1 in all three: [cols="1,3",options="header"] |=== | Prover | Proposition -| Agda (`TransactionAtomicity.agda`, module `Rollback (S : Set)`) +| Agda | `rollback-restores : ∀ {os x z} → Executed os x z → rollback os z ≡ x` -| Rocq (`verification/proofs/rocq/Rollback.v`) +| Rocq | `rollback_restores : forall (S : Type) (os : list (Op S)) (x z : S), Executed os x z -> rollback os z = x` -| Lean (`verification/proofs/lean/Rollback.lean`) +| Lean | `rollback_restores {S : Type} {os : List (Op S)} {x z : S} : Executed os x z → rollback os z = x` |=== @@ -436,48 +452,114 @@ only the prelude in the Rocq file. *How the comparison was made.* By reading, definition by definition. It was not done by a round trip, since no translator exists. -* `Op`: a record of `execute : S → Maybe S`, `undo : S → S` and +* *Common to all.* Agda's builtin `List`, `Maybe`, `Nat` and `Bool` and the + targets' `list`/`option`/`nat`/`bool` and `List`/`Option`/`Nat`/`Bool` are + the same free inductive types. Each module parameter in `Set` is a `Type` + parameter (level 0) in the targets: Rocq's `Section` variables and Lean's + `variable`s become arguments of every theorem that uses them, as an Agda + module parameter does when the theorem is used from outside. +* *T-1.* `Op` is a record of `execute : S → Maybe S`, `undo : S → S` and `undoes : execute x ≡ just y → undo y ≡ x`. The targets have the same three fields over `option`/`Option`. Agda binds `x` and `y` implicitly and Rocq - explicitly, which is the same proposition. -* `Executed`: an inductive family in `Set` with constructors `done` and `next`. - The targets put it in `Type`, the same universe level, with the same two - constructors and the same indices. -* `rollback`: the same structural recursion on the list, undoing the head after - the tail. -* The source type `S` is a parameter in `Set` in all three (`Type` at level 0). -* Builtins: Agda's `List`/`Maybe` and the targets' `list`/`option` and - `List`/`Option` are the same free inductive types. -* The sibling's prelude: `_≡_` is `Agda.Builtin.Equality` re-exported, and - `trans` and `cong` are the usual one-clause definitions by pattern matching on - `refl`. Rocq's `eq` with `eq_trans`/`f_equal`, and Lean's `Eq` with - `Eq.trans`/`congrArg`, are the same inductive equality and the same - eliminations. The re-proofs use `rewrite` instead, which needs nothing beyond - the equality type. No other sibling definition reaches T-1's statement or - proof. - -*Residual differences, listed rather than hidden.* The logics differ in -what they add to equality. Axiom-free Rocq has neither K nor uniqueness of -identity proofs, like Agda under `--without-K`, and `Print Assumptions` confirms -that this leg adds no axiom that would supply them. Lean is stronger: its `Eq` -lives in a proof-irrelevant `Prop`, so it has uniqueness of identity proofs -definitionally. Neither proof uses these: each is the same -induction on `Executed`, a rewrite with the induction hypothesis and one use of -`undoes`. Proving the statement in a stronger logic adds no assumption to the -Agda source. - -*Axioms.* Rocq `Print Assumptions rollback_restores` reports "Closed under the -global context". Lean `#print axioms` reports that it "does not depend on any -axioms". The gate (`scripts/check-recheck.sh`) fails if either line is missing: -a mutant with `Admitted` in Rocq and one with `sorry` in Lean were each caught. - -*Non-vacuity.* `tests/reject-rocq/ForwardRollback.v` and -`tests/reject-lean/ForwardRollback.lean` are twins of -`tests/reject-agda/ForwardRollback.agda`. They build real double and increment -operations against the leg's own definitions and claim that undoing them in -execution order restores the start. Rocq refuses with `Unable to unify "1" with -"0"`, and Lean with "`decide` proved that the proposition … is false". The gate -checks each refusal message. + explicitly, which is the same proposition. `Executed` is an inductive family + in `Set` with constructors `done` and `next`; the targets put it in `Type`, + the same level, with the same constructors and indices. `rollback` is the + same structural recursion, undoing the head after the tail. The sibling's + prelude: `_≡_` is `Agda.Builtin.Equality` re-exported, and `trans` and + `cong` are the usual one-clause definitions by matching on `refl`. Rocq's + `eq` with `eq_trans`/`f_equal`, and Lean's `Eq` with `Eq.trans`/`congrArg`, + are the same inductive equality and the same eliminations. The re-proofs use + `rewrite`, which needs nothing beyond the equality type. No other sibling + definition reaches T-1's statement or proof. +* *T-2 and T-3.* The log is parameterised the same way in all three: a record + type `R`, a key type `I`, decidable key equality, `key` and `phase`. The + decision procedure returns Agda's `(a ≡ b) ⊎ (a ≢ b)`, Rocq's + `{a = b} + {a <> b}` and Lean's `PSum (a = b) (a ≠ b)`, the same sum of the + same two propositions. `update`, `begin`, `modify` and `finish` have the same + clauses, matching on the log's pointer as Agda does. `Good` has the same two + constructors with the same premises. Lean writes `Settled` and `Fresh` + unfolded (`phase u = settled`, `key u ≠ i`), which are their definitions. + `countActive` adds one with `suc` in Agda and Rocq and with `+ 1` in Lean, + the same number by definition. +* *G-1.* The legs cannot import `resource-algebra`, so they restate what G-1 + uses of `ResourceAlgebra.Instances.Loss` at `cf9235c`: the carrier + `Grade = fin Nat | inf`, the sequence product `_+g_` with its three clauses, + its left unit and both annihilation laws. The alternatives operation `_⊓g_` + and the dioid laws are not used by G-1 and are not restated. `Step`, + `Trace` (its own datatype in all three, not a list), `AllLossless`, + `Contains`, `Obliterating` and `ReversiblePair` have the same fields and + constructors. `wrapStep` and `unwrapStep` *assign* grade `fin 0`, as in the + Agda, so `wrap-unwrap-𝟙` holds by computation in all three and does not use + `cancels`. Rocq names the trace constructors `tnil`/`tcons` and the pair + constructor `mkPair`, because its prelude already has `pair`. +* *E-1m.* `_==_` on `Nat` has the same four clauses. Agda's `if_then_else_` is + its own function on `Bool`. Rocq's `if` on a `bool` is the same match, and + Lean's leg defines `ite'` by matching, since Lean's `if` decides a `Prop`, a + different construct. `World` has the same three fields, and `Knows`, + `CanUse`, `x₁`, `x₂`, `obliterate` and `rotate` the same definitions. Agda's + record update becomes a full constructor with the unchanged fields copied. + `Recovers` is a `Σ` in `Set`; the targets use `sigT` and `PSigma` in `Type`. + `¬ Recovers …` is written `Recovers … → False`, which is its definition. + +*Residual differences, listed rather than hidden.* + +* *Equality.* Axiom-free Rocq has neither K nor uniqueness of identity proofs, + like Agda under `--without-K`, and `Print Assumptions` confirms that no leg + adds an axiom that would supply them. Lean is stronger: its `Eq` lives in a + proof-irrelevant `Prop`, so it has uniqueness of identity proofs + definitionally. No proof uses it: each leg proves its statements by the same + inductions and case splits as the Agda. +* *Where the invariants live.* Agda puts `Good`, `All`, `AllLossless` and + `Contains` in `Set`, as proof-relevant data. The targets put them in `Prop` + (`Executed` stays in `Type`, because `rollback` is defined over the list, not + over the derivation). No restated theorem eliminates one of these predicates + into data: each concludes another predicate or an equation, so the placement + removes nothing the statements use. +* *Arithmetic.* Lean's `Nat.add` recurses on its second argument, Agda's and + Rocq's on the first. So `fin 0 +g a ≡ a` holds by computation in Agda and + Rocq and by the lemma `Nat.zero_add` in Lean, which reports no axioms. +* *Axioms in Lean's core library.* `Nat.succ_ne_zero`, and `nomatch` on two + different numerals, depend on `propext` in Lean 4.35.0. The legs use neither + (`Nat.noConfusion`, and comparison by `==`), so the axiom report stays empty. + The axiom report caught both while the legs were being written. + +*Axioms.* Each leg ends with one `Print Assumptions` (Rocq) or `#print axioms` +(Lean) for each theorem the row cites and each refusal lemma: 22 in Rocq and 22 +in Lean. A report covers every lemma the theorem uses. Every one reports "Closed under the global context" or "does not depend on any +axioms". The gate (`scripts/check-recheck.sh`) counts them and fails unless +every report is clean, so a file with several theorems cannot pass on the +strength of one. Mutants with `Admitted` on `modify_good` in Rocq and with +`sorry` on `finish_good` in Lean each fail it ("6 of 7"), and so do the same +mutants on the refusal lemma `modify_refused_when_idle`. Before that change +the gate looked for one clean line per file, which was enough while each file +held one theorem. The gate also counts the commands as the provers parse them, +with any run of whitespace between the two words, and fails outright on any +report that lists an axiom: an `Admitted` theorem whose report was written +`Print Assumptions` (two spaces), beside one clean report, passed the +count-only gate and fails this one, and so does the Lean twin. + +*Non-vacuity.* Each leg has a twin of one Agda fixture, built against the leg's +own definitions: + +[cols="1,2,3",options="header"] +|=== +| Row | Twin of | Refused with + +| G-1 | `HiddenLoss.agda` | Rocq `Unable to unify "fin 0" with "fin 1"`; Lean + "`decide` proved that the proposition … is false" +| T-1 | `ForwardRollback.agda` | Rocq `Unable to unify "1" with "0"`; Lean the + same `decide` message +| T-2, T-3 | `SettleWithoutSettling.agda` | Rocq + `Unable to unify "Some 0" with "Some 1"`; Lean the same `decide` message +| E-1m | `OldKeyStillUsable.agda` | Rocq `Unable to unify "true" with + "false"`; Lean the same `decide` message +|=== + +Each twin is a closed instance evaluated to a value, so its refusal shows the +claim is false, not only that it fails to reduce. Its true counterpart (the +value the refusal names) checks. The gate checks each refusal message. The Agda +fixtures `AdversaryKnows`, `CommitWhenIdle` and `ReviveAfterObliterate` have no +twin. *Pins and inputs.* @@ -491,28 +573,31 @@ checks each refusal message. release tarball `lean-4.35.0-linux.tar.zst`, SHA-256 `7289597a44543246c9227b8cae501767e095ce17f6d448b95fc4a8dc97268f6d`, checked before unpacking. `lean -o .olean `. -| Inputs (SHA-256) | `Rollback.v` - `662d51bf0b642ac28f816853c7d2c6a851583487a15e9f79c3b8184a53ff28e2`, - `Rollback.lean` - `808c32585ad582fced7497b93607668f92d9140b36ae4bd90b14f6b26bcd36c6`, the Rocq - fixture `4b2c01d4f70d1b60080babdf64aeaf873ec4db98c4682a6694e1981127160410`, - the Lean fixture - `813cae57494bee9c6457a63553489d83ad47c2ac538c18a0de8e86956cc477ee`, - `check-recheck.sh` - `5171d9d27a888e79dc9544f7b84d2a3557428c918a25194f9a88bcb2944f8483` -| Observed | Locally, with the same two versions: both legs check with no - axioms, both fixtures refused as named, `[check-recheck] OK`. The CI job on - this change is the receipt. +| Inputs (SHA-256) | + `verification/proofs/rocq/Epistemic.v` `c9dfd029515bb69381c34bbc45b0a1c7c8e5954f4c5945bc5c0864a7cf6baab9`, + `verification/proofs/rocq/Reversibility.v` `0ea2b17813b0f13a93164a1b9a9c3814031823d91bc815095f663fdae7194d36`, + `verification/proofs/rocq/Rollback.v` `662d51bf0b642ac28f816853c7d2c6a851583487a15e9f79c3b8184a53ff28e2`, + `verification/proofs/rocq/SingleActiveLog.v` `abebcca2a94c1cf7d51d53e76ed1000b67afb44dd21cf4926830b4727f3db900`, + `verification/proofs/lean/Epistemic.lean` `9b0d5d88aa7c557b5bf909a78d9acf9391e157ff9e2fbc598dbe5cb70039002f`, + `verification/proofs/lean/Reversibility.lean` `6c13052c4c47f34097ae268ea31f8755ea75dab550892240e508dd176621ccb1`, + `verification/proofs/lean/Rollback.lean` `808c32585ad582fced7497b93607668f92d9140b36ae4bd90b14f6b26bcd36c6`, + `verification/proofs/lean/SingleActiveLog.lean` `f04648e47d7006d213d21ba2d6c08fabc66d9bb3cc14875a38df02579298c9f9`, + `tests/reject-rocq/ForwardRollback.v` `4b2c01d4f70d1b60080babdf64aeaf873ec4db98c4682a6694e1981127160410`, + `tests/reject-rocq/HiddenLoss.v` `e3c4a8546dc96200c07a8ea26eb308eb972a66f1518f132297d92ad56f7a04ee`, + `tests/reject-rocq/OldKeyStillUsable.v` `83ffb85aa91c778ac4aa6a5a1724078738c930dae41de53b910a2510d07c697d`, + `tests/reject-rocq/SettleWithoutSettling.v` `dc9c06e59077e2122cbdb9d49a8a47496c8b422e2a07b58ba047dfff59324210`, + `tests/reject-lean/ForwardRollback.lean` `813cae57494bee9c6457a63553489d83ad47c2ac538c18a0de8e86956cc477ee`, + `tests/reject-lean/HiddenLoss.lean` `f2efff5587ec2be3b321a74ae23a79dc8e0829db0990d8a1d087a8e40a33235d`, + `tests/reject-lean/OldKeyStillUsable.lean` `cb047bacf831d68dac8107b7e0517d156d9f9e30ab9d6a11f1bb997d20dbff1b`, + `tests/reject-lean/SettleWithoutSettling.lean` `09b8c3ba423f34c4da21332c30c4cd99f37cd67197f2293ecdd8c7e6424bfd7d`, + `scripts/check-recheck.sh` `da9a38194ddbb40a5f43b115b83662772fbdd9595a878a8952c0e048224697ac` +| Observed | Locally, with the same two versions: every leg checks with every + report clean, every fixture is refused as named, and every true counterpart + checks; `[check-recheck] OK`. The job on a pull request is branch evidence. + The receipt is a green run on `main`, recorded in the receipt's run ledger + (§The machine-readable receipt). |=== -The pilot answers the question the pilot was for. The transport route is not -available for any of the five theorems, for the reason above. A hand re-proof -in core Rocq and core Lean costs about forty lines per statement. The remaining -four take the same route. G-1 needs the Loss grade algebra restated, since the -targets cannot import `resource-algebra`. T-2 and T-3 are now stated over the abstract -log in `SingleActiveLog.agda`, built from builtins only, so their legs can -restate it directly. - These five are the only rows in this repository with a Proof Witness Grade (PWG). Each rests on a premise it names rather than assumes silently — the per-step cancellation law (`undoes`, TESTED as `execute_then_undo_is_identity`), the @@ -638,11 +723,9 @@ PROOF-POLICY §1 and the ABI belongs in Idris2. and neither receipt is deleted from the history. * `AGDA-PENDING` is the correct correspondence state for a module committed but not yet checked. No row in this repository is in that state today: the five - graded rows are `AGDA-VERIFIED` at the commit above. Except for T-1, whose - legs are re-proved and reconciled, their Rocq and Lean legs have not been - attempted, so each is `OPEN` with no route and no §2.2 record, - and the grade is `PWG-3`. They are not `unavailable`: under §2 that route - means a leg that cannot be built, and a hand re-proof is always available as - the fallback, so the legs are owed, not excused (§8.4.1). + graded rows are `AGDA-VERIFIED` at the commit above, and each of their Rocq + and Lean legs is `re-proved` and `RECONCILED`. No leg is `unavailable`: + under §2 that route means a leg that cannot be built, and a hand re-proof was + available for all ten. * Grade counts appear only as the census at the top of this page: a count per rung, with the denominator and the `ungraded` rung in the same line. diff --git a/scripts/check-recheck.sh b/scripts/check-recheck.sh index a912a37..5623b4b 100755 --- a/scripts/check-recheck.sh +++ b/scripts/check-recheck.sh @@ -3,7 +3,8 @@ # SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell # Recheck legs of the Agda theory theorems (PROOF-POLICY §2): the Rocq files # under verification/proofs/rocq and the Lean files under -# verification/proofs/lean must check with no axioms, and every fixture under +# verification/proofs/lean must check, every `Print Assumptions` and +# `#print axioms` in them must report no axioms, and every fixture under # tests/reject-rocq and tests/reject-lean must be refused with the message its # `expect:` line names. Prover versions are asserted by the caller (CI) and # printed here. ROCQ and LEAN override the binaries. @@ -40,9 +41,19 @@ for f in "${rocq_src[@]}"; do out="$(cd "$work/rocq" && "$rocq" -q -Q . JanusKey "$name" 2>&1)" || { printf '%s\n' "$out"; echo "ERROR: $f does not check" >&2; exit 1; } printf '%s\n' "$out" - grep -q '^Closed under the global context$' <<<"$out" || { - echo "ERROR: $f rests on assumptions (Print Assumptions is not closed)" >&2; exit 1; } - echo "[PASS] rocq leg checks, no assumptions: $f" + # Every `Print Assumptions` in the file must report a closed theorem: a file + # with several theorems must not pass on the strength of one of them. + # Count the commands as Rocq parses them (any run of whitespace between the + # two words), and fail outright on any report that lists an axiom. + want="$(grep -cE '^[[:space:]]*Print[[:space:]]+Assumptions[[:space:]]' "$f" || true)" + got="$(grep -c '^Closed under the global context$' <<<"$out" || true)" + if grep -q '^Axioms:' <<<"$out"; then + echo "ERROR: $f rests on assumptions (a Print Assumptions report lists axioms)" >&2; exit 1 + fi + if [ "$want" -eq 0 ] || [ "$got" -ne "$want" ]; then + echo "ERROR: $f rests on assumptions ($got of $want Print Assumptions closed)" >&2; exit 1 + fi + echo "[PASS] rocq leg checks, no assumptions ($want theorems): $f" done # Lean: compile each leg to an .olean so the fixtures can import it; the @@ -52,9 +63,17 @@ for f in "${lean_src[@]}"; do out="$(LEAN_PATH="$work/lean" "$lean" -o "$work/lean/$mod.olean" "$f" 2>&1)" || { printf '%s\n' "$out"; echo "ERROR: $f does not check" >&2; exit 1; } printf '%s\n' "$out" - grep -q 'does not depend on any axioms' <<<"$out" || { - echo "ERROR: $f depends on axioms (or does not print them)" >&2; exit 1; } - echo "[PASS] lean leg checks, no axioms: $f" + # Every `#print axioms` in the file must report none. Count the commands as + # Lean parses them, and fail outright on any report that lists an axiom. + want="$(grep -cE '^[[:space:]]*#print[[:space:]]+axioms[[:space:]]' "$f" || true)" + got="$(grep -c 'does not depend on any axioms' <<<"$out" || true)" + if grep -q 'depends on axioms' <<<"$out"; then + echo "ERROR: $f depends on axioms (an #print axioms report lists them)" >&2; exit 1 + fi + if [ "$want" -eq 0 ] || [ "$got" -ne "$want" ]; then + echo "ERROR: $f depends on axioms ($got of $want #print axioms report none)" >&2; exit 1 + fi + echo "[PASS] lean leg checks, no axioms ($want theorems): $f" done # Expected rejections: refused, and refused for the stated reason. diff --git a/tests/reject-lean/HiddenLoss.lean b/tests/reject-lean/HiddenLoss.lean new file mode 100644 index 0000000..6b7c15c --- /dev/null +++ b/tests/reject-lean/HiddenLoss.lean @@ -0,0 +1,18 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- Expected rejection, Lean twin of tests/reject-agda/HiddenLoss.agda: a trace +-- with a lossy step cannot be certified lossless. The claim below is false +-- (fin 1 +g fin 0 = fin 1), and the checker must refuse it. The grade is read +-- back as a number (inf as 99) so that `decide` can evaluate the claim. +-- expect: is false +import Reversibility + +open JanusKey.Reversibility + +def lossy : Step Nat := ⟨fun x => x, .fin 1⟩ + +def loss : Grade → Nat + | .fin n => n + | .inf => 99 + +example : loss (traceGrade (.cons lossy .nil)) = 0 := by decide diff --git a/tests/reject-lean/OldKeyStillUsable.lean b/tests/reject-lean/OldKeyStillUsable.lean new file mode 100644 index 0000000..f8093fe --- /dev/null +++ b/tests/reject-lean/OldKeyStillUsable.lean @@ -0,0 +1,14 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- Expected rejection, Lean twin of tests/reject-agda/OldKeyStillUsable.agda, +-- the rotation half of ledger row E-1m. After rotating key 0 -> key 1 (two +-- different keys) in the world x₁, the claim that the owner can still use +-- key 0 is false, and the checker must refuse it. The instance is closed, so +-- the refusal shows the claim evaluates to false, not merely that it does not +-- reduce. +-- expect: is false +import Epistemic + +open JanusKey.Epistemic + +example : (rotate 0 1 x₁).usable .owner 0 = true := by decide diff --git a/tests/reject-lean/SettleWithoutSettling.lean b/tests/reject-lean/SettleWithoutSettling.lean new file mode 100644 index 0000000..86e7cf6 --- /dev/null +++ b/tests/reject-lean/SettleWithoutSettling.lean @@ -0,0 +1,25 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- Expected rejection, Lean twin of tests/reject-agda/SettleWithoutSettling.agda. +-- finish_good needs its settling premise. Here the "finish" transition is the +-- identity, so the record it should settle stays active: the log ends with no +-- pointer but one active record. The claim that countActive matches the +-- pointer (0) is false, and the checker must refuse it. +-- expect: is false +import SingleActiveLog + +open JanusKey.SingleActiveLog + +def natDec (a b : Nat) : PSum (a = b) (a ≠ b) := + if h : a = b then .inl h else .inr h + +/-- Records are bare keys, and every record is active. -/ +def after : Option (Log Nat Nat) := + finish natDec (fun k => k) (fun r => r) ⟨[0], some 0⟩ + +def countAfter : Option Nat := + match after with + | none => none + | some L => some (countActive (fun _ => Phase.active) L.txs) + +example : countAfter = some 0 := by decide diff --git a/tests/reject-rocq/HiddenLoss.v b/tests/reject-rocq/HiddenLoss.v new file mode 100644 index 0000000..4580985 --- /dev/null +++ b/tests/reject-rocq/HiddenLoss.v @@ -0,0 +1,12 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* Expected rejection, Rocq twin of tests/reject-agda/HiddenLoss.agda: a trace + with a lossy step cannot be certified lossless. The claim below is false + (fin 1 +g fin 0 = fin 1), and the checker must refuse it. + expect: Unable to unify "fin 0" with "fin 1" *) +Require Import JanusKey.Reversibility. + +Definition lossy : Step nat := step nat (fun x => x) (fin 1). + +Example hidden : traceGrade nat (tcons nat lossy (tnil nat)) = fin 0. +Proof. vm_compute. reflexivity. Qed. diff --git a/tests/reject-rocq/OldKeyStillUsable.v b/tests/reject-rocq/OldKeyStillUsable.v new file mode 100644 index 0000000..3666993 --- /dev/null +++ b/tests/reject-rocq/OldKeyStillUsable.v @@ -0,0 +1,13 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* Expected rejection, Rocq twin of tests/reject-agda/OldKeyStillUsable.agda, + the rotation half of ledger row E-1m. After rotating key 0 -> key 1 (two + different keys) in the world x1, the claim that the owner can still use + key 0 is false, and the checker must refuse it. The instance is closed, so + the refusal shows the claim evaluates to false, not merely that it does + not reduce. + expect: Unable to unify "true" with "false" *) +Require Import JanusKey.Epistemic. + +Example wrong : usable (rotate 0 1 x1) owner 0 = true. +Proof. vm_compute. reflexivity. Qed. diff --git a/tests/reject-rocq/SettleWithoutSettling.v b/tests/reject-rocq/SettleWithoutSettling.v new file mode 100644 index 0000000..655a02f --- /dev/null +++ b/tests/reject-rocq/SettleWithoutSettling.v @@ -0,0 +1,26 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* Expected rejection, Rocq twin of tests/reject-agda/SettleWithoutSettling.agda. + finish_good needs its settling premise. Here the "finish" transition is the + identity, so the record it should settle stays active: the log ends with no + pointer but one active record. The claim that countActive matches the + pointer (0) is false, and the checker must refuse it. + expect: Unable to unify "Some 0" with "Some 1" *) +Require Import JanusKey.SingleActiveLog. + +Definition nat_dec (m n : nat) : {m = n} + {m <> n}. +Proof. decide equality. Defined. + +(* Records are bare keys, and every record is active. *) +Definition after : option (Log nat nat) := + finish nat nat nat_dec (fun k => k) (fun r => r) + (mkLog nat nat (cons 0 nil) (Some 0)). + +Definition count_after : option nat := + match after with + | None => None + | Some L => Some (countActive nat (fun _ => active) (txs nat nat L)) + end. + +Example no_active_left : count_after = Some 0. +Proof. vm_compute. reflexivity. Qed. diff --git a/verification/proofs/lean/Epistemic.lean b/verification/proofs/lean/Epistemic.lean new file mode 100644 index 0000000..f5bb969 --- /dev/null +++ b/verification/proofs/lean/Epistemic.lean @@ -0,0 +1,133 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- Lean recheck leg of ledger row E-1m (PROOF-POLICY §2, route: re-proved). +-- +-- Source of truth: verification/proofs/agda/Epistemic.agda, theorems +-- knows-observation, different-store-unknown, adversary-ignorant, +-- obliterate-cuts-recovery, obliterate-ignorance, rotate-keeps-new, +-- rotate-forgets-old and rotate-forgets-canUse. This file restates them and +-- proves them again by hand in core Lean 4: no Mathlib, no imports, and no +-- `simp`. Why re-proved and not transported: see Rollback.lean and +-- docs/theory/PROOF-GRADES.adoc, which also records the statement comparison. + +namespace JanusKey.Epistemic + +/-- Agda: `_==_` on Nat. -/ +def eqb : Nat → Nat → Bool + | 0, 0 => true + | 0, _ + 1 => false + | _ + 1, 0 => false + | m + 1, n + 1 => eqb m n + +theorem eqb_refl : ∀ n, eqb n n = true + | 0 => rfl + | n + 1 => eqb_refl n + +/-- Agda: `if_then_else_` on Bool, by matching (not Lean's `if` on `Prop`). -/ +def ite' {A : Type} : Bool → A → A → A + | true, a, _ => a + | false, _, b => b + +abbrev ContentHash := Nat +abbrev Content := Nat +abbrev KeyId := Nat + +inductive Agent : Type where + | owner + | system + | auditor + | adversary + +structure World : Type where + content : ContentHash → Option Content + usable : Agent → KeyId → Bool + see : Agent → List (ContentHash × Content) + +def observe (a : Agent) (x : World) : List (ContentHash × Content) := x.see a + +/-- Knowledge as indiscriminability. -/ +def Knows (a : Agent) (φ : World → Prop) (x : World) : Prop := + ∀ x', observe a x' = observe a x → φ x' + +def CanUse (x : World) (a : Agent) (k : KeyId) : Prop := x.usable a k = true + +/-- Agda: `Σ Content (λ c → content x h ≡ just c)`, a dependent pair in `Set`. -/ +def Recovers (x : World) (h : ContentHash) : Type := + PSigma (fun c : Content => x.content h = some c) + +/-- Theorem 1. An agent knows its own observation. -/ +theorem knows_observation (a : Agent) (x : World) : + Knows a (fun y => observe a y = observe a x) x := fun _ e => e + +/-- Theorem 2. Ignorance is a proposition. -/ +theorem different_store_unknown (a : Agent) (x x' : World) + (e : observe a x' = observe a x) (n : x'.content ≠ x.content) : + ¬ Knows a (fun y => y.content = x.content) x := fun k => n (k x' e) + +def x₁ : World := ⟨fun _ => some 1, fun _ _ => true, fun _ => []⟩ +def x₂ : World := ⟨fun _ => some 2, fun _ _ => true, fun _ => []⟩ + +/-- Theorem 3. Same observation, different content: the adversary does not +know the stored value. -/ +theorem adversary_ignorant : ¬ Knows .adversary (fun y => y.content = x₁.content) x₁ := + fun k => + have h : (some 2 : Option Nat) = some 1 := congrArg (fun f => f 0) (k x₂ rfl) + -- `nomatch h` on two numerals brings in `propext`, so the numerals are + -- told apart by `eqb`, which computes. + have b : true = false := + congrArg (fun o : Option Nat => match o with | some n => eqb n 2 | none => false) h + nomatch b + +def obliterate (h : ContentHash) (x : World) : World := + ⟨fun k => ite' (eqb k h) none (x.content k), x.usable, x.see⟩ + +/-- Theorem 4. Obliteration cuts recovery. -/ +theorem obliterate_cuts_recovery (h : ContentHash) (x : World) : + Recovers (obliterate h x) h → False + | ⟨c, p⟩ => by + have q : ite' (eqb h h) none (x.content h) = some c := p + rw [eqb_refl] at q + exact nomatch q + +/-- Theorem 5. Obliteration does not make the adversary any wiser. -/ +theorem obliterate_ignorance : + ¬ Knows .adversary (fun y => y.content = (obliterate 0 x₁).content) (obliterate 0 x₁) := + fun k => + have h : (some 2 : Option Nat) = none := congrArg (fun f => f 0) (k x₂ rfl) + nomatch h + +def rotate (old new : KeyId) (x : World) : World := + ⟨x.content, + fun a k => ite' (eqb k new) true (ite' (eqb k old) false (x.usable a k)), + x.see⟩ + +theorem rotate_keeps_new (a : Agent) (old new : KeyId) (x : World) : + (rotate old new x).usable a new = true := by + show ite' (eqb new new) true (ite' (eqb new old) false (x.usable a new)) = true + rw [eqb_refl] + rfl + +/-- Theorem 6. Rotation to a different key forgets the old one. -/ +theorem rotate_forgets_old (a : Agent) (old new : KeyId) (x : World) + (n : eqb old new = false) : (rotate old new x).usable a old = false := by + show ite' (eqb old new) true (ite' (eqb old old) false (x.usable a old)) = false + rw [n, eqb_refl] + rfl + +theorem rotate_forgets_canUse (a : Agent) (old new : KeyId) (x : World) + (n : eqb old new = false) : ¬ CanUse (rotate old new x) a old := fun p => by + have q : (rotate old new x).usable a old = true := p + rw [rotate_forgets_old a old new x n] at q + exact nomatch q + +end JanusKey.Epistemic + +#print axioms JanusKey.Epistemic.knows_observation +#print axioms JanusKey.Epistemic.different_store_unknown +#print axioms JanusKey.Epistemic.adversary_ignorant +#print axioms JanusKey.Epistemic.obliterate_cuts_recovery +#print axioms JanusKey.Epistemic.obliterate_ignorance +#print axioms JanusKey.Epistemic.rotate_keeps_new +#print axioms JanusKey.Epistemic.rotate_forgets_old +#print axioms JanusKey.Epistemic.rotate_forgets_canUse diff --git a/verification/proofs/lean/Reversibility.lean b/verification/proofs/lean/Reversibility.lean new file mode 100644 index 0000000..5c86b96 --- /dev/null +++ b/verification/proofs/lean/Reversibility.lean @@ -0,0 +1,149 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- Lean recheck leg of ledger row G-1 (PROOF-POLICY §2, route: re-proved). +-- +-- Source of truth: verification/proofs/agda/Reversibility.agda, module Steps, +-- theorems all-lossless-trace, lossless-trace-all, obliterate-absorbs, +-- obliterated-not-lossless, wrap-unwrap-𝟙 and wrap-unwrap-id. This file +-- restates them and proves them again by hand in core Lean 4: no Mathlib, no +-- imports, and no `simp`. +-- +-- The Agda module takes the Loss grade from the pinned sibling +-- resource-algebra (ResourceAlgebra.Instances.Loss at cf9235c). A recheck leg +-- cannot import that library, so the part G-1 uses is restated below: the +-- carrier, the sequence product `+g`, its left unit and both annihilation +-- laws. Why re-proved and not transported: see Rollback.lean and +-- docs/theory/PROOF-GRADES.adoc, which also records the statement comparison. + +namespace JanusKey.Reversibility + +/-- resource-algebra, Instances/Loss.agda: Grade. -/ +inductive Grade : Type where + | fin : Nat → Grade + | inf : Grade + +open Grade + +/-- resource-algebra, Instances/Loss.agda: _+g_. -/ +def gplus : Grade → Grade → Grade + | fin m, fin n => fin (m + n) + | fin _, inf => inf + | inf, _ => inf + +/-- `+g-unitˡ`. Lean's `Nat.add` recurses on its second argument, so +`0 + a = a` is a lemma here, where Agda and Rocq have it by computation. -/ +theorem gplus_unit_l : ∀ a, gplus (fin 0) a = a + | fin a => congrArg fin (Nat.zero_add a) + | inf => rfl + +theorem gplus_annihil_l (a : Grade) : gplus inf a = inf := rfl + +theorem gplus_annihil_r : ∀ a, gplus a inf = inf + | fin _ => rfl + | inf => rfl + +section Steps + +variable {S : Type} + +/-- A step: what it does to the state, and what it costs in Loss. -/ +structure Step (S : Type) : Type where + run : S → S + grade : Grade + +inductive Trace (S : Type) : Type where + | nil : Trace S + | cons : Step S → Trace S → Trace S + +def traceGrade : Trace S → Grade + | .nil => fin 0 + | .cons s ts => gplus s.grade (traceGrade ts) + +def Lossless (s : Step S) : Prop := s.grade = fin 0 + +inductive AllLossless : Trace S → Prop where + | nil : AllLossless .nil + | cons {s : Step S} {ts : Trace S} : Lossless s → AllLossless ts → AllLossless (.cons s ts) + +/-- Theorem 1. A trace of lossless steps is lossless. -/ +theorem all_lossless_trace : ∀ {ts : Trace S}, AllLossless ts → traceGrade ts = fin 0 + | .nil, .nil => rfl + | .cons s ts, .cons p ps => by + rw [traceGrade] + rw [show s.grade = fin 0 from p, gplus_unit_l, all_lossless_trace ps] + +theorem gplus_zero_left : ∀ a b, gplus a b = fin 0 → a = fin 0 + | fin 0, fin _, _ => rfl + -- Split on n so that m + 1 + n is a successor by computation: no lemma + -- about addition is needed. (`Nat.succ_ne_zero` is not used: in this core + -- library it depends on `propext`.) + | fin (_ + 1), fin 0, h => by + injection h with h + exact Nat.noConfusion h + | fin (_ + 1), fin (_ + 1), h => by + injection h with h + exact Nat.noConfusion h + | fin _, inf, h => nomatch h + | inf, _, h => nomatch h + +theorem gplus_zero_right : ∀ a b, gplus a b = fin 0 → b = fin 0 + | fin _, fin 0, _ => rfl + | fin _, fin (n + 1), h => by + injection h with h + exact Nat.noConfusion h + | fin _, inf, h => nomatch h + | inf, _, h => nomatch h + +/-- Theorem 2. A lossless trace hides no lossy step. -/ +theorem lossless_trace_all : ∀ (ts : Trace S), traceGrade ts = fin 0 → AllLossless ts + | .nil, _ => .nil + | .cons _ ts, p => + .cons (gplus_zero_left _ _ p) (lossless_trace_all ts (gplus_zero_right _ _ p)) + +inductive Contains (s : Step S) : Trace S → Prop where + | here {ts : Trace S} : Contains s (.cons s ts) + | there {t : Step S} {ts : Trace S} : Contains s ts → Contains s (.cons t ts) + +def Obliterating (s : Step S) : Prop := s.grade = inf + +/-- Theorem 3. Obliteration absorbs, whatever comes before or after. -/ +theorem obliterate_absorbs {s : Step S} (o : Obliterating s) : + ∀ {ts : Trace S}, Contains s ts → traceGrade ts = inf + | .cons _ ts, .here => by + rw [traceGrade, show s.grade = inf from o] + exact gplus_annihil_l (traceGrade ts) + | .cons t _, .there c => by + rw [traceGrade, obliterate_absorbs o c] + exact gplus_annihil_r t.grade + +theorem obliterated_not_lossless {s : Step S} {ts : Trace S} + (o : Obliterating s) (c : Contains s ts) (p : traceGrade ts = fin 0) : False := by + rw [obliterate_absorbs o c] at p + exact nomatch p + +/-- The reversible pair. Both steps are ASSIGNED grade 𝟙, as in the Agda. -/ +structure ReversiblePair (S : Type) : Type where + wrap : S → S + unwrap : S → S + cancels : ∀ x, unwrap (wrap x) = x + +def wrapStep (p : ReversiblePair S) : Step S := ⟨p.wrap, fin 0⟩ +def unwrapStep (p : ReversiblePair S) : Step S := ⟨p.unwrap, fin 0⟩ + +theorem wrap_unwrap_one (p : ReversiblePair S) : + traceGrade (.cons (wrapStep p) (.cons (unwrapStep p) .nil)) = fin 0 := rfl + +theorem wrap_unwrap_id (p : ReversiblePair S) (x : S) : + (unwrapStep p).run ((wrapStep p).run x) = x := p.cancels x + +end Steps + +end JanusKey.Reversibility + +#print axioms JanusKey.Reversibility.all_lossless_trace +#print axioms JanusKey.Reversibility.lossless_trace_all +#print axioms JanusKey.Reversibility.obliterate_absorbs +#print axioms JanusKey.Reversibility.obliterated_not_lossless +#print axioms JanusKey.Reversibility.wrap_unwrap_one +#print axioms JanusKey.Reversibility.wrap_unwrap_id diff --git a/verification/proofs/lean/SingleActiveLog.lean b/verification/proofs/lean/SingleActiveLog.lean new file mode 100644 index 0000000..fd2dd16 --- /dev/null +++ b/verification/proofs/lean/SingleActiveLog.lean @@ -0,0 +1,219 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- Lean recheck leg of ledger rows T-2 and T-3 (PROOF-POLICY §2, route: +-- re-proved). +-- +-- Source of truth: verification/proofs/agda/SingleActiveLog.agda, module Log, +-- theorems begin-good, modify-good, finish-good and at-most-one-active, with +-- the refusal lemmas they rest on. This file restates them and proves them +-- again by hand in core Lean 4: no Mathlib, no imports, and no `simp` (whose +-- lemmas can bring in `propext`). Why re-proved and not transported: see +-- Rollback.lean and docs/theory/PROOF-GRADES.adoc, which also records the +-- statement comparison. + +namespace JanusKey.SingleActiveLog + +inductive Phase : Type where + | active + | settled + +open Phase + +/-- Agda: data All. -/ +inductive All {A : Type} (P : A → Prop) : List A → Prop where + | nil : All P [] + | cons {x : A} {xs : List A} : P x → All P xs → All P (x :: xs) + +theorem all_app {A : Type} {P : A → Prop} : + ∀ {xs ys : List A}, All P xs → All P ys → All P (xs ++ ys) + | [], _, _, k => k + | _ :: _, _, .cons p ps, k => .cons p (all_app ps k) + +section Log + +variable {R I : Type} (dec : (a b : I) → PSum (a = b) (a ≠ b)) + (key : R → I) (phase : R → Phase) + +structure Log (R I : Type) : Type where + txs : List R + activeId : Option I + +/-- Rewrite the FIRST record with key `i`; `none` if there is none. -/ +def update (i : I) (f : R → R) : List R → Option (List R) + | [] => none + | t :: ts => + match dec (key t) i with + | .inl _ => some (f t :: ts) + | .inr _ => + match update i f ts with + | none => none + | some us => some (t :: us) + +/-- Open a new record; refused while a record is active. -/ +def begin (r : R) : Log R I → Option (Log R I) + | ⟨_, some _⟩ => none + | ⟨ts, none⟩ => some ⟨ts ++ [r], some (key r)⟩ + +/-- Edit the active record; refused when idle. -/ +def modify (f : R → R) : Log R I → Option (Log R I) + | ⟨_, none⟩ => none + | ⟨ts, some i⟩ => + match update dec key i f ts with + | none => none + | some us => some ⟨us, some i⟩ + +/-- Settle the active record; refused when idle. -/ +def finish (g : R → R) : Log R I → Option (Log R I) + | ⟨_, none⟩ => none + | ⟨ts, some i⟩ => + match update dec key i g ts with + | none => none + | some us => some ⟨us, none⟩ + +inductive Good : Log R I → Prop where + | idle {ts : List R} : All (fun u => phase u = settled) ts → Good ⟨ts, none⟩ + | busy {pre : List R} {t : R} {post : List R} : + All (fun u => key u ≠ key t) pre → + All (fun u => phase u = settled) pre → + phase t = active → + All (fun u => phase u = settled) post → + Good ⟨pre ++ t :: post, some (key t)⟩ + +theorem good_empty : Good key phase (⟨[], none⟩ : Log R I) := .idle .nil + +/-- Only the active record is rewritten. -/ +theorem update_active (f : R → R) (t : R) (post : List R) : + ∀ {pre : List R}, All (fun u => key u ≠ key t) pre → + update dec key (key t) f (pre ++ t :: post) = some (pre ++ f t :: post) + | [], .nil => by + rw [List.nil_append, List.nil_append] + unfold update + cases dec (key t) (key t) with + | inl _ => rfl + | inr n => exact absurd rfl n + | u :: pre, .cons n ns => by + rw [List.cons_append, List.cons_append] + unfold update + cases dec (key u) (key t) with + | inl e => exact absurd e n + | inr _ => + rw [update_active f t post ns] + +/-- A key-preserving edit keeps every earlier record distinct from it. -/ +theorem distinct_after {k k' : I} (e : k' = k) : + ∀ {pre : List R}, All (fun u => key u ≠ k) pre → All (fun u => key u ≠ k') pre + | [], .nil => .nil + | _ :: _, .cons n ns => .cons (fun q => n (q.trans e)) (distinct_after e ns) + +theorem begin_refused_while_active (r : R) (ts : List R) (j : I) : + begin key r ⟨ts, some j⟩ = none := rfl + +theorem begin_good {r : R} {L L' : Log R I} (act : phase r = active) + (G : Good key phase L) (fr : All (fun u => key u ≠ key r) L.txs) + (E : begin key r L = some L') : Good key phase L' := by + cases G with + | @idle ts ss => + cases E + exact @Good.busy R I key phase ts r [] fr ss act .nil + | busy _ _ _ _ => cases E + +theorem modify_refused_when_idle (f : R → R) (ts : List R) : + modify dec key f (⟨ts, none⟩ : Log R I) = none := rfl + +/-- An edit must keep the key and the phase of the record it edits. -/ +theorem modify_good {f : R → R} {L L' : Log R I} + (kf : ∀ r, key (f r) = key r) (pf : ∀ r, phase (f r) = phase r) + (G : Good key phase L) (E : modify dec key f L = some L') : + Good key phase L' := by + cases G with + | idle _ => cases E + | @busy pre t post np sp a sq => + have h : modify dec key f (⟨pre ++ t :: post, some (key t)⟩ : Log R I) + = some ⟨pre ++ f t :: post, some (key t)⟩ := by + dsimp only [modify] + rw [update_active dec key f t post np] + rw [h] at E + cases E + rw [← kf t] + exact Good.busy (distinct_after key (kf t) np) sp ((pf t).trans a) sq + +theorem finish_refused_when_idle (g : R → R) (ts : List R) : + finish dec key g (⟨ts, none⟩ : Log R I) = none := rfl + +/-- A settling transition must land in the settled phase. -/ +theorem finish_good {g : R → R} {L L' : Log R I} + (pg : ∀ r, phase (g r) = settled) + (G : Good key phase L) (E : finish dec key g L = some L') : + Good key phase L' := by + cases G with + | idle _ => cases E + | @busy pre t post np sp a sq => + have h : finish dec key g (⟨pre ++ t :: post, some (key t)⟩ : Log R I) + = some ⟨pre ++ g t :: post, none⟩ := by + dsimp only [finish] + rw [update_active dec key g t post np] + rw [h] at E + cases E + exact Good.idle (all_app sp (.cons (pg t) sq)) + +def countActive : List R → Nat + | [] => 0 + | t :: ts => + match phase t with + | active => countActive ts + 1 + | settled => countActive ts + +def expected : Option I → Nat + | none => 0 + | some _ => 1 + +theorem settled_count : ∀ {ts : List R}, + All (fun u => phase u = settled) ts → countActive phase ts = 0 + | [], .nil => rfl + | t :: ts, .cons s ss => by + show (match phase t with + | active => countActive phase ts + 1 + | settled => countActive phase ts) = 0 + rw [s] + exact settled_count ss + +theorem count_app : ∀ (xs ys : List R), + countActive phase (xs ++ ys) = countActive phase xs + countActive phase ys + | [], ys => (Nat.zero_add _).symm + | x :: xs, ys => by + show (match phase x with + | active => countActive phase (xs ++ ys) + 1 + | settled => countActive phase (xs ++ ys)) + = (match phase x with + | active => countActive phase xs + 1 + | settled => countActive phase xs) + countActive phase ys + cases phase x with + | active => rw [count_app xs ys, Nat.add_right_comm] + | settled => rw [count_app xs ys] + +/-- At most one record is active, and exactly when the pointer is set. -/ +theorem at_most_one_active {L : Log R I} (G : Good key phase L) : + countActive phase L.txs = expected L.activeId := by + cases G with + | idle ss => exact settled_count phase ss + | @busy pre t post _ sp a sq => + show countActive phase (pre ++ t :: post) = 1 + rw [count_app, settled_count phase sp] + show 0 + (match phase t with + | active => countActive phase post + 1 + | settled => countActive phase post) = 1 + rw [a, settled_count phase sq] + rfl + +end Log + +end JanusKey.SingleActiveLog + +#print axioms JanusKey.SingleActiveLog.begin_good +#print axioms JanusKey.SingleActiveLog.modify_good +#print axioms JanusKey.SingleActiveLog.finish_good +#print axioms JanusKey.SingleActiveLog.at_most_one_active +#print axioms JanusKey.SingleActiveLog.begin_refused_while_active +#print axioms JanusKey.SingleActiveLog.modify_refused_when_idle +#print axioms JanusKey.SingleActiveLog.finish_refused_when_idle diff --git a/verification/proofs/rocq/Epistemic.v b/verification/proofs/rocq/Epistemic.v new file mode 100644 index 0000000..c63d18c --- /dev/null +++ b/verification/proofs/rocq/Epistemic.v @@ -0,0 +1,117 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* + Rocq recheck leg of ledger row E-1m (PROOF-POLICY §2, route: re-proved). + + Source of truth: verification/proofs/agda/Epistemic.agda, theorems + knows-observation, different-store-unknown, adversary-ignorant, + obliterate-cuts-recovery, obliterate-ignorance, rotate-keeps-new, + rotate-forgets-old and rotate-forgets-canUse. This file restates them and + proves them again by hand, using only the Rocq prelude. Why re-proved and + not transported: see Rollback.v and docs/theory/PROOF-GRADES.adoc, which + also records the statement comparison. +*) + +(* Agda: _==_ on Nat, and the one fact the proofs need about it. *) +Fixpoint eqb (m n : nat) : bool := + match m, n with + | O, O => true + | O, S _ => false + | S _, O => false + | S m', S n' => eqb m' n' + end. + +Lemma eqb_refl : forall n, eqb n n = true. +Proof. induction n as [| n IH]; [reflexivity | exact IH]. Qed. + +Definition ContentHash := nat. +Definition Content := nat. +Definition KeyId := nat. + +Inductive Agent : Type := owner | system | auditor | adversary. + +Record World : Type := w { + content : ContentHash -> option Content; + usable : Agent -> KeyId -> bool; + see : Agent -> list (ContentHash * Content) +}. + +Definition observe (a : Agent) (x : World) : list (ContentHash * Content) := see x a. + +(* Knowledge as indiscriminability. *) +Definition Knows (a : Agent) (phi : World -> Prop) (x : World) : Prop := + forall x', observe a x' = observe a x -> phi x'. + +Definition CanUse (x : World) (a : Agent) (k : KeyId) : Prop := usable x a k = true. + +(* Agda: Σ Content (λ c → content x h ≡ just c), a dependent pair in Set. *) +Definition Recovers (x : World) (h : ContentHash) : Type := + { c : Content & content x h = Some c }. + +(* Theorem 1. An agent knows its own observation. *) +Theorem knows_observation : forall a x, + Knows a (fun y => observe a y = observe a x) x. +Proof. intros a x y e. exact e. Qed. + +(* Theorem 2. Ignorance is a proposition. *) +Theorem different_store_unknown : forall a x x', + observe a x' = observe a x -> content x' <> content x -> + ~ Knows a (fun y => content y = content x) x. +Proof. intros a x x' e n k. exact (n (k x' e)). Qed. + +Definition x1 : World := w (fun _ => Some 1) (fun _ _ => true) (fun _ => nil). +Definition x2 : World := w (fun _ => Some 2) (fun _ _ => true) (fun _ => nil). + +(* Theorem 3. Same observation, different content: the adversary does not + know the stored value. *) +Theorem adversary_ignorant : ~ Knows adversary (fun y => content y = content x1) x1. +Proof. + intro k. pose proof (f_equal (fun f => f 0) (k x2 eq_refl)) as H. + simpl in H. discriminate H. +Qed. + +Definition obliterate (h : ContentHash) (x : World) : World := + w (fun k => if eqb k h then None else content x k) (usable x) (see x). + +(* Theorem 4. Obliteration cuts recovery. *) +Theorem obliterate_cuts_recovery : forall h x, Recovers (obliterate h x) h -> False. +Proof. + intros h x [c p]. simpl in p. rewrite eqb_refl in p. discriminate p. +Qed. + +(* Theorem 5. Obliteration does not make the adversary any wiser. *) +Theorem obliterate_ignorance : + ~ Knows adversary (fun y => content y = content (obliterate 0 x1)) (obliterate 0 x1). +Proof. + intro k. pose proof (f_equal (fun f => f 0) (k x2 eq_refl)) as H. + simpl in H. discriminate H. +Qed. + +(* Theorem 6. Rotation to a different key forgets the old one. *) +Definition rotate (old new : KeyId) (x : World) : World := + w (content x) + (fun a k => if eqb k new then true else (if eqb k old then false else usable x a k)) + (see x). + +Theorem rotate_keeps_new : forall a old new x, usable (rotate old new x) a new = true. +Proof. intros a old new x. simpl. rewrite eqb_refl. reflexivity. Qed. + +Theorem rotate_forgets_old : forall a old new x, + eqb old new = false -> usable (rotate old new x) a old = false. +Proof. intros a old new x n. simpl. rewrite n, eqb_refl. reflexivity. Qed. + +Theorem rotate_forgets_canUse : forall a old new x, + eqb old new = false -> ~ CanUse (rotate old new x) a old. +Proof. + intros a old new x n p. unfold CanUse in p. + rewrite (rotate_forgets_old a old new x n) in p. discriminate p. +Qed. + +Print Assumptions knows_observation. +Print Assumptions different_store_unknown. +Print Assumptions adversary_ignorant. +Print Assumptions obliterate_cuts_recovery. +Print Assumptions obliterate_ignorance. +Print Assumptions rotate_keeps_new. +Print Assumptions rotate_forgets_old. +Print Assumptions rotate_forgets_canUse. diff --git a/verification/proofs/rocq/Reversibility.v b/verification/proofs/rocq/Reversibility.v new file mode 100644 index 0000000..1c1988c --- /dev/null +++ b/verification/proofs/rocq/Reversibility.v @@ -0,0 +1,136 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* + Rocq recheck leg of ledger row G-1 (PROOF-POLICY §2, route: re-proved). + + Source of truth: verification/proofs/agda/Reversibility.agda, module Steps, + theorems all-lossless-trace, lossless-trace-all, obliterate-absorbs, + obliterated-not-lossless, wrap-unwrap-𝟙 and wrap-unwrap-id. This file + restates them and proves them again by hand, using only the Rocq prelude. + + The Agda module takes the Loss grade from the pinned sibling + resource-algebra (ResourceAlgebra.Instances.Loss at cf9235c). A recheck leg + cannot import that library, so the part G-1 uses is restated below: the + carrier, the sequence product `+g`, its left unit and both annihilation + laws. The alternatives operation and the dioid laws are not used by G-1 + and are not restated. Why re-proved and not transported: see Rollback.v and + docs/theory/PROOF-GRADES.adoc, which also records the statement + comparison. +*) + +(* resource-algebra, Instances/Loss.agda: Grade and _+g_. *) +Inductive Grade : Type := fin : nat -> Grade | inf : Grade. + +Definition gplus (a b : Grade) : Grade := + match a, b with + | fin m, fin n => fin (m + n) + | fin _, inf => inf + | inf, _ => inf + end. + +(* The laws G-1 uses: +g-unitˡ (seq.unitˡ), annihilˡ and annihilʳ. *) +Lemma gplus_unit_l : forall a, gplus (fin 0) a = a. +Proof. intros [a|]; reflexivity. Qed. + +Lemma gplus_annihil_l : forall a, gplus inf a = inf. +Proof. reflexivity. Qed. + +Lemma gplus_annihil_r : forall a, gplus a inf = inf. +Proof. intros [a|]; reflexivity. Qed. + +Section Steps. + +Variable S : Type. + +(* A step: what it does to the state, and what it costs in Loss. *) +Record Step : Type := step { run : S -> S; grade : Grade }. + +Inductive Trace : Type := + | tnil : Trace + | tcons : Step -> Trace -> Trace. + +Fixpoint traceGrade (ts : Trace) : Grade := + match ts with + | tnil => fin 0 + | tcons s ts' => gplus (grade s) (traceGrade ts') + end. + +Definition Lossless (s : Step) : Prop := grade s = fin 0. + +Inductive AllLossless : Trace -> Prop := + | al_nil : AllLossless tnil + | al_cons : forall s ts, Lossless s -> AllLossless ts -> AllLossless (tcons s ts). + +(* Theorem 1. A trace of lossless steps is lossless. *) +Theorem all_lossless_trace : forall ts, AllLossless ts -> traceGrade ts = fin 0. +Proof. + intros ts H. induction H as [| s ts p _ IH]; simpl. + - reflexivity. + - unfold Lossless in p. rewrite p, gplus_unit_l. exact IH. +Qed. + +Lemma gplus_zero_left : forall a b, gplus a b = fin 0 -> a = fin 0. +Proof. + intros [[|m]|] [n|]; simpl; intro H; (reflexivity || discriminate H). +Qed. + +Lemma gplus_zero_right : forall a b, gplus a b = fin 0 -> b = fin 0. +Proof. + intros [[|m]|] [[|n]|]; simpl; intro H; (reflexivity || discriminate H). +Qed. + +(* Theorem 2. A lossless trace hides no lossy step. *) +Theorem lossless_trace_all : forall ts, traceGrade ts = fin 0 -> AllLossless ts. +Proof. + intros ts. induction ts as [| s ts IH]; simpl; intro p. + - exact al_nil. + - exact (al_cons s ts (gplus_zero_left _ _ p) (IH (gplus_zero_right _ _ p))). +Qed. + +Inductive Contains (s : Step) : Trace -> Prop := + | here : forall ts, Contains s (tcons s ts) + | there : forall t ts, Contains s ts -> Contains s (tcons t ts). + +Definition Obliterating (s : Step) : Prop := grade s = inf. + +(* Theorem 3. Obliteration absorbs, whatever comes before or after. *) +Theorem obliterate_absorbs : forall s ts, + Obliterating s -> Contains s ts -> traceGrade ts = inf. +Proof. + intros s ts o c. induction c as [ts | t ts _ IH]; simpl. + - unfold Obliterating in o. rewrite o. apply gplus_annihil_l. + - rewrite IH. apply gplus_annihil_r. +Qed. + +Theorem obliterated_not_lossless : forall s ts, + Obliterating s -> Contains s ts -> traceGrade ts = fin 0 -> False. +Proof. + intros s ts o c p. rewrite (obliterate_absorbs s ts o c) in p. discriminate p. +Qed. + +(* The reversible pair. Both steps are ASSIGNED grade 𝟙, as in the Agda. *) +Record ReversiblePair : Type := mkPair { + wrap : S -> S; + unwrap : S -> S; + cancels : forall x, unwrap (wrap x) = x +}. + +Definition wrapStep (p : ReversiblePair) : Step := step (wrap p) (fin 0). +Definition unwrapStep (p : ReversiblePair) : Step := step (unwrap p) (fin 0). + +Theorem wrap_unwrap_one : forall p, + traceGrade (tcons (wrapStep p) (tcons (unwrapStep p) tnil)) = fin 0. +Proof. reflexivity. Qed. + +Theorem wrap_unwrap_id : forall p x, + run (unwrapStep p) (run (wrapStep p) x) = x. +Proof. intros p x. exact (cancels p x). Qed. + +End Steps. + +Print Assumptions all_lossless_trace. +Print Assumptions lossless_trace_all. +Print Assumptions obliterate_absorbs. +Print Assumptions obliterated_not_lossless. +Print Assumptions wrap_unwrap_one. +Print Assumptions wrap_unwrap_id. diff --git a/verification/proofs/rocq/SingleActiveLog.v b/verification/proofs/rocq/SingleActiveLog.v new file mode 100644 index 0000000..37f4840 --- /dev/null +++ b/verification/proofs/rocq/SingleActiveLog.v @@ -0,0 +1,215 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* + Rocq recheck leg of ledger rows T-2 and T-3 (PROOF-POLICY §2, route: + re-proved). + + Source of truth: verification/proofs/agda/SingleActiveLog.agda, module + Log, theorems begin-good, modify-good, finish-good and at-most-one-active, + with the refusal lemmas they rest on. This file restates them and proves + them again by hand, using only the Rocq prelude. Why re-proved and not + transported: see Rollback.v and docs/theory/PROOF-GRADES.adoc, which also + records the statement comparison. +*) + +Local Open Scope list_scope. + +Inductive Phase : Type := active | settled. + +(* Agda: data All. *) +Inductive All {A : Type} (P : A -> Prop) : list A -> Prop := + | All_nil : All P nil + | All_cons : forall x xs, P x -> All P xs -> All P (cons x xs). + +Lemma all_app : forall (A : Type) (P : A -> Prop) xs ys, + All P xs -> All P ys -> All P (xs ++ ys). +Proof. + intros A P xs ys H K. induction H as [| x xs p _ IH]; simpl. + - exact K. + - exact (All_cons P x (xs ++ ys) p IH). +Qed. + +Section Log. + +Variables R I : Type. +Variable dec : forall a b : I, {a = b} + {a <> b}. +Variable key : R -> I. +Variable phase : R -> Phase. + +Record Log : Type := mkLog { txs : list R; activeId : option I }. + +Definition Settled (r : R) : Prop := phase r = settled. +Definition Fresh (i : I) (ts : list R) : Prop := All (fun u => key u <> i) ts. + +(* Rewrite the FIRST record with key i; None if there is none. *) +Fixpoint update (i : I) (f : R -> R) (ts : list R) : option (list R) := + match ts with + | nil => None + | cons t ts' => + if dec (key t) i then Some (cons (f t) ts') + else match update i f ts' with + | None => None + | Some us => Some (cons t us) + end + end. + +(* Open a new record; refused while a record is active. *) +Definition begin (r : R) (L : Log) : option Log := + match L with + | mkLog _ (Some _) => None + | mkLog ts None => Some (mkLog (ts ++ cons r nil) (Some (key r))) + end. + +(* Edit the active record; refused when idle. *) +Definition modify (f : R -> R) (L : Log) : option Log := + match L with + | mkLog _ None => None + | mkLog ts (Some i) => + match update i f ts with + | None => None + | Some us => Some (mkLog us (Some i)) + end + end. + +(* Settle the active record; refused when idle. *) +Definition finish (g : R -> R) (L : Log) : option Log := + match L with + | mkLog _ None => None + | mkLog ts (Some i) => + match update i g ts with + | None => None + | Some us => Some (mkLog us None) + end + end. + +Inductive Good : Log -> Prop := + | idle : forall ts, All Settled ts -> Good (mkLog ts None) + | busy : forall pre t post, + All (fun u => key u <> key t) pre -> + All Settled pre -> + phase t = active -> + All Settled post -> + Good (mkLog (pre ++ cons t post) (Some (key t))). + +Lemma good_empty : Good (mkLog nil None). +Proof. exact (idle nil (All_nil _)). Qed. + +(* Only the active record is rewritten. *) +Lemma update_active : forall f pre t post, + All (fun u => key u <> key t) pre -> + update (key t) f (pre ++ cons t post) = Some (pre ++ cons (f t) post). +Proof. + intros f pre t post H. induction H as [| u pre' n _ IH]; simpl. + - destruct (dec (key t) (key t)) as [_ | n]. + + reflexivity. + + exfalso. exact (n eq_refl). + - destruct (dec (key u) (key t)) as [e | _]. + + exfalso. exact (n e). + + rewrite IH. reflexivity. +Qed. + +(* A key-preserving edit keeps every earlier record distinct from it. *) +Lemma distinct_after : forall (k k' : I) pre, k' = k -> + All (fun u => key u <> k) pre -> All (fun u => key u <> k') pre. +Proof. + intros k k' pre e H. induction H as [| u pre' n _ IH]. + - exact (All_nil _). + - refine (All_cons _ u pre' _ IH). + intro q. exact (n (eq_trans q e)). +Qed. + +Lemma begin_refused_while_active : forall r ts j, + begin r (mkLog ts (Some j)) = None. +Proof. reflexivity. Qed. + +Theorem begin_good : forall r L L', + phase r = active -> Good L -> Fresh (key r) (txs L) -> + begin r L = Some L' -> Good L'. +Proof. + intros r L L' act G fr E. destruct G as [ts ss | pre t post np sp a sq]. + - simpl in E. injection E as <-. + exact (busy ts r nil fr ss act (All_nil _)). + - discriminate E. +Qed. + +Lemma modify_refused_when_idle : forall f ts, + modify f (mkLog ts None) = None. +Proof. reflexivity. Qed. + +(* An edit must keep the key and the phase of the record it edits. *) +Theorem modify_good : forall f L L', + (forall r, key (f r) = key r) -> (forall r, phase (f r) = phase r) -> + Good L -> modify f L = Some L' -> Good L'. +Proof. + intros f L L' kf pf G E. destruct G as [ts ss | pre t post np sp a sq]. + - discriminate E. + - simpl in E. rewrite (update_active f pre t post np) in E. + injection E as <-. rewrite <- (kf t). + exact (busy pre (f t) post + (distinct_after (key t) (key (f t)) pre (kf t) np) + sp (eq_trans (pf t) a) sq). +Qed. + +Lemma finish_refused_when_idle : forall g ts, + finish g (mkLog ts None) = None. +Proof. reflexivity. Qed. + +(* A settling transition must land in the settled phase. *) +Theorem finish_good : forall g L L', + (forall r, phase (g r) = settled) -> + Good L -> finish g L = Some L' -> Good L'. +Proof. + intros g L L' pg G E. destruct G as [ts ss | pre t post np sp a sq]. + - discriminate E. + - simpl in E. rewrite (update_active g pre t post np) in E. + injection E as <-. + exact (idle _ (all_app _ _ pre _ sp (All_cons _ (g t) post (pg t) sq))). +Qed. + +Fixpoint countActive (ts : list R) : nat := + match ts with + | nil => 0 + | cons t ts' => + match phase t with + | active => S (countActive ts') + | settled => countActive ts' + end + end. + +Definition expected (o : option I) : nat := + match o with None => 0 | Some _ => 1 end. + +Lemma settled_count : forall ts, All Settled ts -> countActive ts = 0. +Proof. + intros ts H. induction H as [| t ts' s _ IH]; simpl. + - reflexivity. + - unfold Settled in s. rewrite s. exact IH. +Qed. + +Lemma count_app : forall xs ys, + countActive (xs ++ ys) = countActive xs + countActive ys. +Proof. + intros xs ys. induction xs as [| x xs IH]; simpl. + - reflexivity. + - destruct (phase x); simpl; rewrite IH; reflexivity. +Qed. + +(* At most one record is active, and exactly when the pointer is set. *) +Theorem at_most_one_active : forall L, + Good L -> countActive (txs L) = expected (activeId L). +Proof. + intros L G. destruct G as [ts ss | pre t post np sp a sq]; simpl. + - exact (settled_count ts ss). + - rewrite count_app. simpl. rewrite a. + rewrite (settled_count pre sp), (settled_count post sq). reflexivity. +Qed. + +End Log. + +Print Assumptions begin_good. +Print Assumptions modify_good. +Print Assumptions finish_good. +Print Assumptions at_most_one_active. +Print Assumptions begin_refused_while_active. +Print Assumptions modify_refused_when_idle. +Print Assumptions finish_refused_when_idle.