Compare commits

..

No commits in common. "9972ab4198c10fe489caf86abdb3e2d35c86d762" and "8d67e9519c3604fcbfb229d0652ca3faaa5b0fd2" have entirely different histories.

27 changed files with 34 additions and 2356 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
*.olean
.lake/

View file

@ -1,79 +0,0 @@
# Known gaps and scope boundaries (honest ledger)
Deliberate, documented, and none silent. Reviewers should verify this
list is COMPLETE, not merely that the items are acceptable.
1. **SHA-256 is opaque** — the single boundary axiom (`LTLAcc.sha256`),
by design identical to the paper's posture: soundness theorems
construct collisions, never assume collision resistance.
2. **No consistency-completeness theorem** (honest ConsRec acceptance).
Matches the paper (its Theorem 1 is inclusion-only); honest
consistency behavior is covered by the fidelity harness's honest
cases (within the 230,016-case consistency agreement with the
deployed verifier).
3. **Lemma 2 is mechanized as specializations, not as one general
theorem.** The paper's Lemma 2 is a single statement quantified over
an abstract hash-fold `F` and a connected subtree `S`. The corpus has
no hash-fold datatype/predicate; it proves the needed instances
directly — whole-tree (`extractMTH_correct`), ConsRec
(`consRecBinding`), inclusion (`extractIncl_correct`), and the width
fact (`hnode_preimage_inj`). These suffice for Theorems 2–3. Two
consequences: (a) the abstract lemma itself is not a mechanized
object; (b) the path-instance receipt-uniqueness for `Root` (removed
with the vacuous `root_binding`) is not restored — optional, unused.
Any paper claim that "Lemma 2 is mechanized" must read "its
specializations sufficient for Theorems 2–3 are mechanized."
4. **Signature layer abstract** — Ed25519 EUF-CMA, the poison/evidence
retention state, and transferability of fork evidence (paper Prop
1(2)) are not modeled; `fork_distinct` is the Merkle-layer share only.
5. **Transliteration bridge** — `fidelity/lean_defs.py` mirrors the Lean
definitions by quoted-source inspection (the Lean defs are
noncomputable over the opaque hash, so the bridge cannot be #eval'd
closed). Same inspection bridge the paper's own harness uses.
6. **Proposition 2 (verdict integrity) out of scope** — per paper §10's
mechanization list (i–v). It is a property of the consumer tooling's
construction, enforced and regression-tested in the pacta repo.
7. **Multi-step pin monotonicity** — mechanized per-step
(`pinAccept_monotone`); the paper's multi-step chain is its
reflexive-transitive iterate, not separately mechanized.
8. **Process history** (candor): three cone pins were guessed (not read)
during S5.3–S6 and the audit's failure went unnoticed until S7
because green was claimed from tailed output rather than the exit
code. No theorem was affected (kernel-checked throughout); pins were
corrected, the audit surface defined, and the standing rule is now:
exit code + ALL GREEN, cones read from #print axioms only.
9. **Asymptotic cost not mechanized.** Paper Theorems 2 and 3 assert the
extractors run in `O(n)` / `O(n₁)` hash evaluations. The mechanization
proves functional correctness of the named extractors only — no cost
semantics, recurrence, or computability-after-hash-instantiation. (The
extractors are `noncomputable` over the opaque `sha256`.)
10. **Pin-store initialization from the empty pin not modeled**, and
`pin_prefix_correct` assumes `0 < n`. Trust-on-first-use / the size-0
initial state is a separate operation; the theorems cover transitions
from a positive-size pin. (Related to gap 7's per-step scoping.)
11. **acceptIncl now named (was review F1).** The consumer's inclusion
acceptance `m < n ∧ Root … = some r` is now the Lean object
`acceptIncl`, with `acceptIncl_complete`/`acceptIncl_sound` routing
completeness/soundness through it, and the fidelity harness exercises
the out-of-range families (`m ≥ n`). `Root` alone still accepts
out-of-range `m`; that is by design (it is the reconstruction, not the
accept predicate).
12. **Audit-gate lineage** (candor; was round-2 GPT H1 / Claude NEW-1,
both round-1 "fail-closed" claims were overclaims). The round-2
coverage gate enumerated declarations with a source regex and was
evadable (attributes, indentation, private/protected, `instance`,
nested-namespace basename collisions). Round 3 replaced it with an
environment-derived inventory (`Proofs/Inventory.lean` +
`inventory-allowlist.txt`, fully-qualified names, no filtering) and
`selftest_audit.sh`, which runs the published evasion table plus a
namespace collision, an axiom smuggle, a stale-entry case, and two
unmanifested-module cases against the exact production gate.
Residual honesty: the inventory sees what the compiled environment
contains; it cannot see source that is never compiled (which the
dead-file checks cover) or defeat a hostile Lean toolchain.
13. **Review-kit fidelity target was not self-contained in round 2**
(GPT H2: missing load-time imports made `run_fidelity.py` unrunnable
from the kit). Round 3 ships the complete stdlib-only import closure
of `pacta.transparency`, content-addressed against pacta commit
`3d81d53`, plus the clean-extraction transcript with exit code.

View file

@ -5,31 +5,16 @@ Lean 4 mechanization of the security analysis (§6) of the paper
accumulator's own correctness and soundness theorems, kernel-checked, in
the same discipline as the four `*-ed25519-verified` subject corpora.
## Status: **FROZEN for external review** (corpus complete)
All paper-§10 mechanization targets are kernel-checked; the audit surface
is defined and green (`verification/check.sh`, exit 0). See
[STATEMENT-MAP.md](STATEMENT-MAP.md) for the paper↔Lean review surface and
[KNOWN-GAPS.md](KNOWN-GAPS.md) for the honest scope ledger.
Revised after review round 1 (GPT-5.6 + second Claude) and round 2:
the audit surface is now an environment-derived inventory
(`Proofs/Inventory.lean` + pinned allowlist, self-tested by
`selftest_audit.sh`), the review kit's fidelity target is
self-contained, `acceptIncl` routes Theorems 1–2, fidelity families
extended (230,271 / 230,016). No changes until the external review
completes. The finished certificates' attestation into the LTL is a
separate, explicitly-authorized operator decision.
## Status: layer scaffold (work in progress — honest ledger below)
| layer | content | status |
|---|---|---|
| L1 | bytes, hleaf/hnode, domain separation (Lemma 1) | **done** (domsep: axiom-free) |
| L2 | MTH, Root, ConsRec definitions + termination | **done** (cones: propext, LTLAcc.sha256, Quot.sound) |
| L3 | inclusion completeness (Theorem 1) + named acceptance `acceptIncl` | **done** (incl_complete: propext, Classical.choice, LTLAcc.sha256, Quot.sound) |
| L4 | frontier binding content (Lemma 2) | **done as specializations** — inlined in the extractor walk (`extractIncl`), whole-tree (`extractMTH`), ConsRec (`consRecBinding`); the standalone `Root` receipt-uniqueness instance was deleted with the vacuous `root_binding` in S3.5 and deliberately NOT restored (optional, unused — KNOWN-GAPS gap 3) |
| L5 | inclusion soundness = EXPLICIT extractor `extractIncl` (Theorem 2) | **done, non-vacuous** |
| L6a | descent extractor `extractMTH` (Theorem 3 step 3 = Lemma 2, whole-tree instance) | **done, non-vacuous** |
| L6b | Theorem 3 (consistency soundness): `consRecBinding` (steps 1–2) + `extractCons`/`extractCons_correct` (+ `_paper` at the paper's exact quantifiers) | **done, non-vacuous** |
| L6c | pin-store state machine safety (Proposition 1): `pinAccept_monotone`, `pin_prefix_correct`, `fork_distinct` | **done, non-vacuous** (per-step; multi-step chain = gap 7) |
| L3 | inclusion completeness (Theorem 1) | pending |
| L4 | frontier hash-fold + root binding (Lemma 2) | pending |
| L5 | inclusion/consistency soundness as collision extractors (Theorems 2, 3) | pending |
| L6 | pin-store state machine safety (Proposition 1) | pending |
## Discipline (identical to the subject corpora)

View file

@ -1,136 +0,0 @@
# Response to reviewers — round 3
Corpus: `ltl-accumulator-verified`. Round-2 reviews received against the
round-2 freeze `260ad64` (GPT-5.6 second adversarial review; second
Claude round-2 findings). Every finding was independently re-verified
against the corpus before any change; all confirmed findings are fixed
in this freeze. No theorem statement changed except the one interface
tightening both reviewers requested (L1/NEW-2).
## Disposition of round-2 findings
### GPT H1 / Claude NEW-1 — coverage gate evadable (CONFIRMED, fixed structurally)
Both reviewers were right, and GPT's namespace-collision attack
(`LTLAcc.Hidden.MTH` classified against `CONES[LTLAcc.MTH]`) showed that
regex hardening (Claude's proposed fix) would not have closed the class.
We adopted GPT's required correction in full — the inventory is now
derived from the Lean environment, not from source:
- **`Proofs/Inventory.lean`** imports every corpus module and emits
EVERY constant whose originating module is a corpus module: fully
qualified name, declaration kind, and axiom cone. There is **no
filtering** — compiler-generated auxiliaries and `_private.*` mangles
are emitted and pinned too, so there is no name shape that can hide.
A corpus module missing from the import list is an elaboration error.
- The axiom cone is computed by our own walker AND cross-checked
in-process against core `collectAxioms` (the machinery `#print axioms`
uses) for every constant — divergence is a hard error. (This caught a
real toolchain subtlety during development: `ConstantInfo.value?`
returns `none` for theorems on 4.30.0-rc2, which would have silently
truncated cones; the direct constructor match avoids it, and the
cross-check would have refused to ship it.)
- **`verification/inventory-allowlist.txt`** pins all 218 constants;
**`inventory_gate.sh`** diffs environment vs allowlist fail-closed in
BOTH directions (UNCLASSIFIED / STALE), requires the INV-COUNT
trailer (a truncated Lean run cannot pass as an empty diff), and
asserts the whole corpus contains exactly one axiom-kind constant:
`LTLAcc.sha256`.
- check.sh Phase 3b additionally verifies: the inventory's module list
== the compile manifest (both directions), every CONES entry appears
in the allowlist **with an identical cone** (two independent cone
computations must agree), and every CONES entry is queried by
AxiomCheck.
- **GPT release condition 2 (adversarial tests) is met by
`verification/selftest_audit.sh`**, which attacks the exact production
gate: attributed, indented, private, and instance declarations, the
nested-namespace basename collision, a smuggled axiom, a deleted
declaration (STALE direction), and unmanifested `Proofs/` and `gen/`
modules through the full check.sh — plus a positive control so the
self-test cannot pass vacuously. Transcript in the kit
(`selftest-transcript.txt`).
### GPT H2 — fidelity target could not run (CONFIRMED, fixed)
Reproduced exactly (`ModuleNotFoundError: pacta.postquantum`). The
round-3 `pacta-fidelity-target` ships the complete **load-time import
closure** of `pacta.transparency` (`__init__`, `transparency`,
`postquantum`, `signing`, `yamlio`) — all stdlib-only, so a bare
Python 3 runs it with no pip installs — content-addressed in
`MANIFEST.sha256` against pacta commit `3d81d538…` with verification
instructions (`TARGET-PROVENANCE.md`). The kit includes the complete
terminal transcript AND exit code of `run_fidelity.py` executed from a
clean extraction: exit 0, `230,271 + 230,016`, zero mismatches
(`fidelity-clean-run-transcript.txt`), plus the full green `check.sh`
transcript ending in `ATTESTATION GREEN` with fidelity not skipped
(`check-transcript.txt`) — GPT release conditions 3 and 5.
### GPT M1 — audit narrower outside Proofs/ (CONFIRMED, fixed)
- Orphan-olean guard is now recursive over the whole tree (it caught a
stray development artifact on its first run).
- gen/ has the same unmanifested-source ("dead file") check as Proofs/.
- The axiom surface is pinned corpus-wide twice: textually (exactly one
`axiom` line under gen/, none under Proofs/) and semantically (the
inventory admits exactly one axiom-kind constant anywhere).
- Declaration discovery under gen/ now goes through the environment
inventory like everything else.
### GPT M2 — stale fidelity counts in STATEMENT-MAP (CONFIRMED, fixed)
The row now reads 230,271 + 230,016 with the expanded families named.
Process note: the round-2 Claude review certified this row as already
fixed; it was not. Consistent with this project's experience, "verified"
claims by reviewers are themselves re-verified now.
### GPT M3 — "not choice-dischargeable" overclaims (CONFIRMED, fixed)
STATEMENT-MAP now uses (essentially) GPT's safer wording: the guards
show each named extractor returns a non-collision on at least one
canonical honest input, ruling out the globally-inhabited-existential
degeneration; they do NOT establish logical dependence on every
hypothesis, nor exclude other classical arguments on restricted domains.
### GPT L1 / Claude NEW-2 — redundant `hm` in `acceptIncl_sound` (CONFIRMED, fixed)
The hypothesis is gone; the range fact is derived from `hacc.1`, so the
theorem is stated purely in terms of acceptance + wrong-leaf premise.
Cone unchanged (`propext, Classical.choice, LTLAcc.sha256, Quot.sound`),
re-verified by `#print axioms` and the inventory.
### GPT ledger additions (adopted, as history)
KNOWN-GAPS gains gap 12 (audit-gate lineage: the round-2 gate was
evadable, what replaced it, and the residual limits of an
environment-derived inventory — it cannot see never-compiled source,
which the dead-file checks cover, nor defeat a hostile toolchain) and
gap 13 (the round-2 kit's fidelity target was not self-contained).
## Found in round-3 self-review (neither reviewer caught)
- **README layer table was still stale at `260ad64`**: L4 carried
"queued for S4 restoration" and the pin-store row said "pending",
despite round-1 F2 being certified as fixed by the round-2 Claude
review. The table now matches the frozen state (all layers done,
L4 explicitly "done as specializations" per gap 3).
- KNOWN-GAPS gap 2 still cited the old 164,224 count; updated.
## Round-2 Claude review, remaining notes
NEW-1 was correct in direction; we implemented the stronger
environment-based fix rather than the proposed regex broadening, since
the namespace collision defeats any basename-keyed source scan. The
round-2 Claude claim that the fidelity harness was "confirmed green
against the real pacta code" was obtained by hand-stubbing the missing
modules — with the round-3 self-contained target, that result is now
reproducible by anyone from the kit alone.
## What did NOT change
All theorem statements and proofs except the `acceptIncl_sound`
signature tightening; the axiom boundary (single opaque `sha256`); the
pinned CONES table (59 entries, all cones byte-identical to round 2);
the fidelity counts. The live transparency log remains frozen at
12 leaves (root `bcd15f9d…`) and is untouched by this round;
attestation remains blocked pending the ePrint decision, author
review, and an explicit operator order.

View file

@ -1,61 +0,0 @@
# Statement map: paper §6 ↔ Lean corpus
The kernel guarantees every proof below; what a reviewer must vet is the
**statements** — that each Lean theorem says what the paper's item says.
This map is the review surface. Paper = "The Lean Transparency Log"
(https://ltl.zkdefi.org/paper), §6 and §10 (which scopes the
mechanization to items i–v).
| paper item | Lean name | file | cone |
|---|---|---|---|
| §5.3 split point k (RFC 9162) | `kbelow` + `kbelow_pos/lt`, `le_two_kbelow`, `kbelow_pow2` (2^j = k < n ≤ 2^{j+1} pins k uniquely) | Basic | no hash axiom |
| §5.3 MTH | `MTH` | Basic | sha256 |
| §5.3 Path | `Path` | Completeness | sha256 |
| §5.3 Root (App. B) | `Root` (Option = rejection) | Basic | sha256 |
| §5.3 inclusion accept | `acceptIncl` (= `m < n ∧ Root … = some r`); `acceptIncl_complete`, `acceptIncl_sound` route Thm 1/2 through it | Basic, Completeness, Extract | sha256 (+choice) |
| Lemma 2 (general abstract form) | **not mechanized as one theorem** — proved as specializations (see KNOWN-GAPS gap 3); the row below and the Lemma-2 rows are those instances | — | — |
| §5.3 ConsRec | `ConsRec` (+ machine-checked base-refactor equivalences `consRec_base_true_eq/false_eq`) | Basic, Refactor | sha256 |
| Lemma 1 (domain separation) | `domsep` | Basic | **axiom-free** |
| Theorem 1 (inclusion completeness) | `incl_complete` | Completeness | sha256 (+choice) |
| Lemma 2, width fact ("65-byte preimages") | `Hash` = length-32 subtype; `hnode_preimage_inj` | gen, Basic | propext |
| Lemma 2, whole-tree instance | `extractMTH` + `extractMTH_correct` | Descent | sha256 (+choice) |
| Lemma 2, ConsRec instance (Thm 3 steps 1–2) | `consRecBinding` | Binding3 | sha256 (+choice) |
| Theorem 2 (inclusion soundness, explicit 𝓔) | `extractIncl` + `extractIncl_correct` | Extract | sha256 (+choice) |
| Theorem 3 (consistency soundness, explicit 𝓔′) | `extractCons` + `extractCons_correct`; `extractCons_correct_paper` at the paper's exact quantifiers (n₀=0 discharged) | Theorem3 | sha256 (+choice) |
| Prop 1(1) (pin monotonicity + prefix) | `pinAccept`, `pinAccept_monotone`, `pin_prefix_correct` | PinStore | sha256 (+choice) |
| Prop 1(2), Merkle share | `fork_distinct` (different roots ⇒ different content); transferability = signature layer, out of scope | PinStore | sha256 |
| non-vacuity guards (anti-pigeonhole) | `extractIncl_nonvacuous`, `extractMTH_nonvacuous`, `extractCons_nonvacuous`, `pin_prefix_nonvacuous` | Extract/Descent/Theorem3/PinStore | sha256 |
| definition fidelity vs deployed verifier | `fidelity/` harness: MTH==merkle_root, Path==inclusion_proof, verifier agreement 230,271 inclusion + 230,016 consistency (paper's case set + out-of-range families m≥n, n₀>n₁, n₀=0; round-2 M2 fixed the stale pre-expansion counts here) | fidelity | (testing) |
Note on "assumption-free" (paper §10(i)): `incl_complete`'s cone lists
`LTLAcc.sha256`, but the theorem assumes **no property** of it — it
merely *mentions* the opaque constant. Constant-dependence is not
property-assumption; the soundness theorems likewise carry `sha256`
without assuming collision resistance.
Design invariant of every soundness statement: the collision is the output
of a **named extractor function** and correctness is a claim about that
output. A bare `∃ x y, x ≠ y ∧ sha256 x = sha256 y` is provable by
pigeonhole alone (sha256 maps an infinite domain into the finite 32-byte
type), so it carries no cryptographic content. What the guards certify
(precisely — round-2 M3): each named extractor does **not** return a
collision on at least one canonical honest input, which rules out the
degeneration where the conclusion is a globally inhabited bare collision
existential. They do NOT establish logical dependence on every listed
hypothesis, nor that no other classical argument could reach the
conclusion on some restricted domain.
Audit surface (enforced by `verification/check.sh`, exit 0 = green):
the FULL compiled environment of the corpus modules — 218 constants,
read from the Lean environment by `Proofs/Inventory.lean` (fully
qualified names, kinds, axiom cones) and pinned in
`verification/inventory-allowlist.txt`, diffed fail-closed both
directions on every run (round-3 replacement for the round-2 source-regex
gate, which GPT H1 showed was evadable). The 59 human-reviewed statement
cones above are additionally checked via `#print axioms` and
cross-checked against the inventory's independently computed cones.
`verification/selftest_audit.sh` attacks the gate with nine injection
cases (attributed/indented/private/instance declarations, a nested
namespace reusing an audited basename, a smuggled axiom, a deleted
declaration, and unmanifested Proofs/ and gen/ modules) — each must
fail the exact production gate.

View file

@ -1,70 +1,9 @@
/- Axiom-cone observation for the audit (Phase 3 of check.sh). -/
import Proofs.Basic
import Proofs.Completeness
import Proofs.Extract
import Proofs.Descent
import Proofs.Consistency
import Proofs.Binding3
import Proofs.Refactor
import Proofs.Theorem3
import Proofs.PinStore
#print axioms LTLAcc.domsep
#print axioms LTLAcc.kbelow_pos
#print axioms LTLAcc.kbelow_lt
#print axioms LTLAcc.le_two_kbelow
#print axioms LTLAcc.kbelow_pow2
#print axioms LTLAcc.MTH
#print axioms LTLAcc.Root
#print axioms LTLAcc.ConsRec
#print axioms LTLAcc.Path
#print axioms LTLAcc.incl_complete
#print axioms LTLAcc.hnode_preimage_inj
#print axioms LTLAcc.IsCollision
#print axioms LTLAcc.extractIncl
#print axioms LTLAcc.extractIncl_correct
#print axioms LTLAcc.extractIncl_nonvacuous
#print axioms LTLAcc.extractMTH
#print axioms LTLAcc.extractMTH_correct
#print axioms LTLAcc.extractMTH_nonvacuous
#print axioms LTLAcc.kbelow_prefix_eq
#print axioms LTLAcc.take_take_le
#print axioms LTLAcc.take_drop_prefix
#print axioms LTLAcc.extractConsNode
#print axioms LTLAcc.take_all
#print axioms LTLAcc.consRecBinding
#print axioms LTLAcc.consRec_base_false_eq
#print axioms LTLAcc.consRec_base_true_eq
#print axioms LTLAcc.extractCons
#print axioms LTLAcc.extractCons_correct
#print axioms LTLAcc.extractCons_nonvacuous
#print axioms LTLAcc.pinAccept_monotone
#print axioms LTLAcc.pin_prefix_correct
#print axioms LTLAcc.fork_distinct
#print axioms LTLAcc.pin_prefix_nonvacuous
#print axioms LTLAcc.MTH_single
#print axioms LTLAcc.MTH_split
#print axioms LTLAcc.Root_left
#print axioms LTLAcc.Root_one
#print axioms LTLAcc.Root_one_cons
#print axioms LTLAcc.Root_right
#print axioms LTLAcc.acceptCons
#print axioms LTLAcc.eq_dropLast_append_of_getLast?
#print axioms LTLAcc.exists_singleton_of_length_one
#print axioms LTLAcc.getD_drop
#print axioms LTLAcc.getD_take
#print axioms LTLAcc.hleaf
#print axioms LTLAcc.hnode
#print axioms LTLAcc.kbelow
#print axioms LTLAcc.kbelow_eq_of_pow2_between
#print axioms LTLAcc.pinAccept
#print axioms LTLAcc.pinExtract
#print axioms LTLAcc.pow2_exp_unique
#print axioms LTLAcc.take_append_drop
#print axioms LTLAcc.instInhabitedHash
#print axioms LTLAcc.instDecidableEqHash
#print axioms LTLAcc.acceptIncl
#print axioms LTLAcc.acceptIncl_complete
#print axioms LTLAcc.acceptIncl_sound
#print axioms LTLAcc.extractCons_correct_paper
#print axioms LTLAcc.Hash

Binary file not shown.

View file

@ -11,22 +11,10 @@ namespace LTLAcc
abbrev Bytes := List UInt8
/-- Leaf hash: `H(0x00 ‖ d)` (paper §5.3). -/
noncomputable def hleaf (d : Bytes) : Hash := sha256 (0x00 :: d)
noncomputable def hleaf (d : Bytes) : Bytes := sha256 (0x00 :: d)
/-- Node hash: `H(0x01 ‖ x ‖ y)` (paper §5.3). Arguments are 32-byte
hash values, so the preimage determines the argument pair — the
load-bearing width fact of the paper's Lemma 2. -/
noncomputable def hnode (x y : Hash) : Hash := sha256 (0x01 :: (x.val ++ y.val))
/-- Preimage-level pair injectivity: equal `hnode` PREIMAGES force equal
argument pairs, because both components are exactly 32 bytes. -/
theorem hnode_preimage_inj {x y X Y : Hash}
(h : (0x01 : UInt8) :: (x.val ++ y.val) = 0x01 :: (X.val ++ Y.val)) :
x = X ∧ y = Y := by
injection h with _ happ
have hlen : x.val.length = X.val.length := by rw [x.property, X.property]
have := List.append_inj happ hlen
exact ⟨Subtype.ext this.1, Subtype.ext this.2⟩
/-- Node hash: `H(0x01 ‖ x ‖ y)` (paper §5.3). -/
noncomputable def hnode (x y : Bytes) : Bytes := sha256 (0x01 :: (x ++ y))
/-- **Lemma 1 (Domain separation), preimage form**: no leaf preimage
equals a node preimage as a byte string — the first byte differs. -/
@ -69,24 +57,10 @@ theorem le_two_kbelow (n : Nat) (h : 2 ≤ n) : n ≤ 2 * kbelow n := by
have := ih h2
omega
/-- `kbelow` is a genuine power of two. Together with `kbelow_lt` and
`le_two_kbelow` (`2^j = k < n ≤ 2k = 2^(j+1)`) this pins `kbelow n`
as THE largest power of two strictly below `n` — the RFC 9162 split
point, uniquely determined. -/
theorem kbelow_pow2 (n : Nat) : ∃ j, kbelow n = 2 ^ j := by
induction n using kbelow.induct with
| case1 n hle => exact ⟨0, by rw [kbelow]; simp only [if_pos hle]⟩
| case2 n hgt ih =>
obtain ⟨j, hj⟩ := ih
refine ⟨j + 1, ?_⟩
rw [kbelow]
simp only [if_neg hgt]
rw [hj, Nat.pow_succ, Nat.mul_comm]
/-- `MTH` (paper §5.3): the RFC 9162 tree head over a leaf-data list.
`MTH [] = H(ε)`, `MTH [d] = hleaf d`, and for `n ≥ 2` the split at
`k = kbelow n`. -/
noncomputable def MTH (D : List Bytes) : Hash :=
noncomputable def MTH (D : List Bytes) : Bytes :=
if _h0 : D.length = 0 then sha256 []
else if _h1 : D.length = 1 then hleaf (D.headD [])
else
@ -107,9 +81,11 @@ decreasing_by
/-- `Root` (paper §5.3 / Appendix B): the consumer's root reconstruction.
`none` = rejection on any length mismatch, exactly as deployed. -/
noncomputable def Root (v : Hash) (m n : Nat) (P : List Hash) : Option Hash :=
noncomputable def Root (v : Bytes) (m n : Nat) (P : List Bytes) : Option Bytes :=
if n = 1 then
(if P = [] then some v else none)
match P with
| [] => some v
| _ => none
else if n = 0 then none
else
match P.getLast? with
@ -135,13 +111,17 @@ decreasing_by
the reconstructed pair (old root, new root); `none` = shape
mismatch. The flag `b` records whether the size-`n₀` subtree root is
carried implicitly (the pinned root `r`) or explicitly in `C`. -/
noncomputable def ConsRec (n₀ n : Nat) (C : List Hash) (b : Bool) (r : Hash) :
Option (Hash × Hash) :=
noncomputable def ConsRec (n₀ n : Nat) (C : List Bytes) (b : Bool) (r : Bytes) :
Option (Bytes × Bytes) :=
if n₀ = n then
if b then
(if C = [] then some (r, r) else none)
match C with
| [] => some (r, r)
| _ => none
else
(if C.length = 1 then some (C.getLastD default, C.getLastD default) else none)
match C with
| [s] => some (s, s)
| _ => none
else if n₀ > n ∨ n₀ = 0 ∨ n ≤ 1 then none
else
match C.getLast? with
@ -165,14 +145,7 @@ decreasing_by
/-- The consumer's acceptance predicate for a consistency proof between
pinned head `(n₀, r₀)` and offered head `(n₁, r₁)` (paper §5.3). -/
def acceptCons (n₀ n₁ : Nat) (r₀ r₁ : Hash) (C : List Hash) : Prop :=
def acceptCons (n₀ n₁ : Nat) (r₀ r₁ : Bytes) (C : List Bytes) : Prop :=
n₀ = 0 ∨ ConsRec n₀ n₁ C true r₀ = some (r₀, r₁)
/-- The consumer's INCLUSION acceptance predicate (paper §5.3 / Appendix B):
the `m < n` range guard is part of accept, not just a theorem hypothesis
(review F1). `Root` alone would accept out-of-range `m` at `n = 1`; this
is the object the fidelity harness's `accept_incl` mirrors. -/
def acceptIncl (d : Bytes) (m n : Nat) (P : List Hash) (r : Hash) : Prop :=
m < n ∧ Root (hleaf d) m n P = some r
end LTLAcc

Binary file not shown.

View file

@ -1,153 +0,0 @@
/- S5.3 — consRecBinding: the paper's Theorem 3 steps 1-2, as a statement
about the extractor's output. Under the maintained value-equality
invariant `y = MTH D₁`, an accepting ConsRec fold either makes
`extractConsNode` output a genuine collision, or its first component is
the honest prefix root `MTH (D₁.take n₀)`. -/
import Proofs.Consistency
namespace LTLAcc
theorem take_all (l : List Bytes) (n : Nat) (h : l.length = n) : l.take n = l := by
subst h; exact List.take_length
theorem consRecBinding (r : Hash) :
∀ (n₀ n : Nat) (C : List Hash) (b : Bool) (D₁ : List Bytes) (x y : Hash),
D₁.length = n → 0 < n₀ → n₀ ≤ n →
ConsRec n₀ n C b r = some (x, y) → y = MTH D₁ →
(match extractConsNode n₀ n C b r D₁ with
| some c => IsCollision c.1 c.2
| none => x = MTH (D₁.take n₀)) := by
intro n₀ n C b
induction n₀, n, C, b using ConsRec.induct r with
| case1 n =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons; simp at hcons
obtain ⟨hx, hyr⟩ := hcons
have hext : extractConsNode n n [] true r D₁ = none := by rw [extractConsNode]; simp
simp only [hext]
rw [← hx, hyr, hy, take_all D₁ n hlen]
| case2 n C hCne =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons; simp [hCne] at hcons
| case3 n C b hb hC1 =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons; simp [hb, hC1] at hcons
obtain ⟨hx, hyr⟩ := hcons
have hext : extractConsNode n n C b r D₁ = none := by rw [extractConsNode]; simp
simp only [hext]
rw [← hx, hyr, hy, take_all D₁ n hlen]
| case4 n C b hb hC1 =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons; simp [hb, hC1] at hcons
| case5 n₀ n C b hne hrej =>
intro D₁ x y hlen hn0 hle hcons hy
exfalso; omega
| case6 n₀ n C b hne hrej hgl =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons
simp only [if_neg hne, if_neg hrej, hgl] at hcons
exact absurd hcons (by simp)
| case7 n₀ n C b hne hrej s hgl k hle2 hsubnone _ih =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons
have hk : kbelow n = k := rfl
simp only [if_neg hne, if_neg hrej, hgl, hk, if_pos hle2, hsubnone] at hcons
exact absurd hcons (by simp)
| case8 n₀ n C b hne hrej s hgl k hle2 xx yy hsub ih =>
intro D₁ x y hlen hn0 hle hcons hy
have h2 : 2 ≤ n := by omega
have hk : kbelow n = k := rfl
have hkl : k < n := by rw [← hk]; exact kbelow_lt n h2
rw [ConsRec] at hcons
simp only [if_neg hne, if_neg hrej, hgl, hk, if_pos hle2, hsub,
Option.some.injEq, Prod.mk.injEq] at hcons
obtain ⟨hx, hyv⟩ := hcons
have hsplit : MTH D₁ = hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := by
have := MTH_split D₁ (by omega); rw [hlen, hk] at this; exact this
have hnodeeq : hnode yy s = hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := by
rw [hyv, hy, hsplit]
have htklen : (D₁.take k).length = k := by rw [List.length_take, hlen]; omega
rw [extractConsNode]
simp only [if_neg hne, if_neg hrej, hgl, hk, if_pos hle2]
have hy' : (Option.map Prod.snd (ConsRec n₀ k C.dropLast b r)).getD default = yy := by
rw [hsub]; rfl
rw [hy']
by_cases hpair : yy = MTH (D₁.take k) ∧ s = MTH (D₁.drop k)
· simp only [if_pos hpair]
have hih := ih (D₁.take k) xx yy htklen hn0 hle2 hsub hpair.1
cases hrec : extractConsNode n₀ k C.dropLast b r (D₁.take k) with
| some c => rw [hrec] at hih; exact hih
| none =>
rw [hrec] at hih
have htt : (D₁.take k).take n₀ = D₁.take n₀ := by
rw [List.take_take]; congr 1; omega
rw [← hx, hih, htt]
· simp only [if_neg hpair]
refine ⟨?_, ?_⟩
· intro hc
injection hc with _ happ
have hln : yy.val.length = (MTH (D₁.take k)).val.length := by
rw [yy.property, (MTH (D₁.take k)).property]
obtain ⟨e1, e2⟩ := List.append_inj happ hln
exact hpair ⟨Subtype.ext e1, Subtype.ext e2⟩
· show sha256 _ = sha256 _
have el : sha256 (0x01 :: (yy.val ++ s.val)) = hnode yy s := rfl
have er : sha256 (0x01 :: ((MTH (D₁.take k)).val ++ (MTH (D₁.drop k)).val))
= hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := rfl
rw [el, er, hnodeeq]
| case9 n₀ n C b hne hrej s hgl k hle2 hsubnone _ih =>
intro D₁ x y hlen hn0 hle hcons hy
rw [ConsRec] at hcons
have hk : kbelow n = k := rfl
simp only [if_neg hne, if_neg hrej, hgl, hk, if_neg hle2, hsubnone] at hcons
exact absurd hcons (by simp)
| case10 n₀ n C b hne hrej s hgl k hle2 xx yy hsub ih =>
intro D₁ x y hlen hn0 hle hcons hy
have h2 : 2 ≤ n := by omega
have hk : kbelow n = k := rfl
have hkl : k < n := by rw [← hk]; exact kbelow_lt n h2
have hkp : 0 < k := by rw [← hk]; exact kbelow_pos n
rw [ConsRec] at hcons
simp only [if_neg hne, if_neg hrej, hgl, hk, if_neg hle2, hsub,
Option.some.injEq, Prod.mk.injEq] at hcons
obtain ⟨hx, hyv⟩ := hcons
have hsplit : MTH D₁ = hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := by
have := MTH_split D₁ (by omega); rw [hlen, hk] at this; exact this
have hnodeeq : hnode s yy = hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := by
rw [hyv, hy, hsplit]
have hdklen : (D₁.drop k).length = n - k := by rw [List.length_drop, hlen]
rw [extractConsNode]
simp only [if_neg hne, if_neg hrej, hgl, hk, if_neg hle2]
have hy' : (Option.map Prod.snd (ConsRec (n₀ - k) (n - k) C.dropLast false r)).getD default = yy := by
rw [hsub]; rfl
rw [hy']
by_cases hpair : s = MTH (D₁.take k) ∧ yy = MTH (D₁.drop k)
· simp only [if_pos hpair]
have hih := ih (D₁.drop k) xx yy hdklen (by omega) (by omega) hsub hpair.2
cases hrec : extractConsNode (n₀ - k) (n - k) C.dropLast false r (D₁.drop k) with
| some c => rw [hrec] at hih; exact hih
| none =>
rw [hrec] at hih
have hn2 : 2 ≤ n₀ := by omega
have hkbn0 : kbelow n₀ = k := kbelow_prefix_eq h2 hk.symm (by omega) hle
have htn0len : (D₁.take n₀).length = n₀ := by rw [List.length_take, hlen]; omega
have hspn0 : MTH (D₁.take n₀)
= hnode (MTH ((D₁.take n₀).take k)) (MTH ((D₁.take n₀).drop k)) := by
have := MTH_split (D₁.take n₀) (by omega); rw [htn0len, hkbn0] at this; exact this
rw [take_take_le D₁ k n₀ (by omega), take_drop_prefix D₁ k n₀] at hspn0
rw [← hx, hspn0, hpair.1, hih]
· simp only [if_neg hpair]
refine ⟨?_, ?_⟩
· intro hc
injection hc with _ happ
have hln : s.val.length = (MTH (D₁.take k)).val.length := by
rw [s.property, (MTH (D₁.take k)).property]
obtain ⟨e1, e2⟩ := List.append_inj happ hln
exact hpair ⟨Subtype.ext e1, Subtype.ext e2⟩
· show sha256 _ = sha256 _
have el : sha256 (0x01 :: (s.val ++ yy.val)) = hnode s yy := rfl
have er : sha256 (0x01 :: ((MTH (D₁.take k)).val ++ (MTH (D₁.drop k)).val))
= hnode (MTH (D₁.take k)) (MTH (D₁.drop k)) := rfl
rw [el, er, hnodeeq]
end LTLAcc

View file

@ -1,190 +0,0 @@
/- L3 of the accumulator pyramid: the prover-side Path function and
**Theorem 1 (inclusion completeness)** — honest receipts always verify:
Root (hleaf D[m]) m |D| (Path m D) = some (MTH D)
No hash property is used anywhere (the theorem is about shapes). -/
import Proofs.Basic
namespace LTLAcc
/-- `Path` (paper §5.3): the operator's inclusion path for index `m`.
Sibling subtree heads, leaf-to-root order (the paper's `‖ [s]`). -/
noncomputable def Path (m : Nat) (D : List Bytes) : List Hash :=
if D.length ≤ 1 then []
else
let k := kbelow D.length
if m < k then Path m (D.take k) ++ [MTH (D.drop k)]
else Path (m - k) (D.drop k) ++ [MTH (D.take k)]
termination_by D.length
decreasing_by
· simp only [List.length_take]
have h2 : 2 ≤ D.length := by omega
have hk := kbelow_lt D.length h2
omega
· simp only [List.length_drop]
have hp := kbelow_pos D.length
omega
/-! ### List helper lemmas (self-contained; no stdlib-name dependence) -/
theorem getD_take (l : List Bytes) (k m : Nat) (h : m < k) :
(l.take k).getD m [] = l.getD m [] := by
induction l generalizing k m with
| nil => simp
| cons a t ih =>
cases k with
| zero => omega
| succ k' =>
cases m with
| zero => simp
| succ m' =>
simp only [List.take_succ_cons, List.getD_cons_succ]
exact ih k' m' (by omega)
theorem getD_drop (l : List Bytes) (k i : Nat) :
(l.drop k).getD i [] = l.getD (k + i) [] := by
induction l generalizing k with
| nil => simp
| cons a t ih =>
cases k with
| zero => simp
| succ k' =>
have hidx : k' + 1 + i = (k' + i) + 1 := by omega
simp only [List.drop_succ_cons, hidx, List.getD_cons_succ]
exact ih k'
theorem exists_singleton_of_length_one (l : List Bytes)
(h : l.length = 1) : ∃ d, l = [d] := by
cases l with
| nil => simp at h
| cons a t =>
cases t with
| nil => exact ⟨a, rfl⟩
| cons b u => simp at h
/-! ### Equation lemmas -/
theorem MTH_single (d : Bytes) : MTH [d] = hleaf d := by
rw [MTH]; rfl
theorem MTH_split (D : List Bytes) (h : 2 ≤ D.length) :
MTH D = hnode (MTH (D.take (kbelow D.length)))
(MTH (D.drop (kbelow D.length))) := by
rw [MTH]
have h0 : ¬ D.length = 0 := by omega
have h1 : ¬ D.length = 1 := by omega
simp only [h0, h1, dite_false]
theorem Root_one (v : Hash) (m : Nat) : Root v m 1 [] = some v := by
rw [Root]; simp
theorem Root_one_cons (v : Hash) (m : Nat) (p : Hash) (q : List Hash) :
Root v m 1 (p :: q) = none := by
rw [Root]; simp
/-- `Root` at a composite size, left branch (`m < k`). -/
theorem Root_left (v : Hash) (m n : Nat) (P : List Hash) (s : Hash)
(hn : 2 ≤ n) (hm : m < kbelow n) :
Root v m n (P ++ [s]) = (Root v m (kbelow n) P).map (hnode · s) := by
have h1 : ¬ n = 1 := by omega
have h0 : ¬ n = 0 := by omega
cases hR : Root v m (kbelow n) P with
| none =>
rw [Root]; simp [h0, h1, hm, hR]
| some x =>
rw [Root]; simp [h0, h1, hm, hR]
/-- `Root` at a composite size, right branch (`m ≥ k`). -/
theorem Root_right (v : Hash) (m n : Nat) (P : List Hash) (s : Hash)
(hn : 2 ≤ n) (hm : ¬ m < kbelow n) :
Root v m n (P ++ [s]) =
(Root v (m - kbelow n) (n - kbelow n) P).map (hnode s ·) := by
have h1 : ¬ n = 1 := by omega
have h0 : ¬ n = 0 := by omega
cases hR : Root v (m - kbelow n) (n - kbelow n) P with
| none =>
rw [Root]; simp [h0, h1, hm, hR]
| some x =>
rw [Root]; simp [h0, h1, hm, hR]
/-! ### Theorem 1 -/
/-- **Theorem 1 (Inclusion completeness)**, paper §6: for every non-empty
leaf list `D` and every `m < |D|`, the honestly produced receipt
verifies to the honest root. -/
theorem incl_complete (m : Nat) (D : List Bytes) (hm : m < D.length) :
Root (hleaf (D.getD m [])) m D.length (Path m D) = some (MTH D) := by
induction m, D using Path.induct with
| case1 m D hle =>
-- |D| ≤ 1 and m < |D| force D = [d], m = 0
have h1 : D.length = 1 := by omega
obtain ⟨d, rfl⟩ := exists_singleton_of_length_one D h1
have hm0 : m = 0 := by simpa using hm
subst hm0
rw [Path]
simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
rw [MTH_single]
simpa using Root_one (hleaf d) 0
| case2 m D hgt k hmk ih =>
have h2 : 2 ≤ D.length := by omega
have hkeq : k = kbelow D.length := rfl
have hkl : k < D.length := by rw [hkeq]; exact kbelow_lt D.length h2
have hmk' : m < kbelow D.length := by rw [← hkeq]; exact hmk
rw [Path]
simp only [if_neg hgt, ← hkeq, if_pos hmk]
rw [Root_left _ _ _ _ _ h2 hmk', ← hkeq]
have htklen : (D.take k).length = k := by
simp [List.length_take]; omega
have ihm : m < (D.take k).length := by omega
have hrec := ih ihm
rw [getD_take D k m hmk, htklen] at hrec
rw [hrec, MTH_split D h2, ← hkeq]
rfl
| case3 m D hgt k hmk ih =>
have h2 : 2 ≤ D.length := by omega
have hkeq : k = kbelow D.length := rfl
have hkl : k < D.length := by rw [hkeq]; exact kbelow_lt D.length h2
have hkp : 0 < k := by rw [hkeq]; exact kbelow_pos D.length
have hmk' : ¬ m < kbelow D.length := by rw [← hkeq]; exact hmk
rw [Path]
simp only [if_neg hgt, ← hkeq, if_neg hmk]
rw [Root_right _ _ _ _ _ h2 hmk', ← hkeq]
have hidx : k + (m - k) = m := by omega
have hget : (D.drop k).getD (m - k) [] = D.getD m [] := by
rw [getD_drop, hidx]
have hdplen : (D.drop k).length = D.length - k := by
simp [List.length_drop]
have ihm : m - k < (D.drop k).length := by omega
have hrec := ih ihm
rw [hget, hdplen] at hrec
rw [hrec, MTH_split D h2, ← hkeq]
rfl
/-- A non-empty list is its `dropLast` plus its last element
(self-contained; no stdlib-name dependence). -/
theorem eq_dropLast_append_of_getLast? (l : List Hash) (s : Hash)
(h : l.getLast? = some s) : l = l.dropLast ++ [s] := by
induction l with
| nil => simp at h
| cons a t ih =>
cases t with
| nil =>
simp at h
subst h
rfl
| cons b u =>
have hh : (b :: u).getLast? = some s := by
simpa using h
have := ih hh
calc a :: b :: u = a :: (b :: u) := rfl
_ = a :: ((b :: u).dropLast ++ [s]) := by rw [← this]
_ = (a :: b :: u).dropLast ++ [s] := by simp
/-- Completeness through the named acceptance predicate (review F1): the
honest receipt satisfies `acceptIncl`. -/
theorem acceptIncl_complete (m : Nat) (D : List Bytes) (hm : m < D.length) :
acceptIncl (D.getD m []) m D.length (Path m D) (MTH D) :=
⟨hm, incl_complete m D hm⟩
end LTLAcc

View file

@ -1,106 +0,0 @@
/- S5 (stage 1) — infrastructure for consistency soundness (paper Theorem 3,
steps 1-2). The binding argument needs one non-obvious arithmetic fact and
two list-surgery facts, isolated and proven here before the main proof.
Arithmetic: when the pinned prefix of size n₀ spills past the left subtree
(k < n₀ ≤ n, k = kbelow n), the honest tree of `D₁.take n₀` splits at the
SAME point k. That is `kbelow n₀ = k`, and it holds because k is a power of
two with k < n₀ ≤ 2k, which pins kbelow uniquely. -/
import Proofs.Descent
namespace LTLAcc
/-- Two powers of two both lying in `(m/2, m]` (i.e. `2^a < m ≤ 2^(a+1)`)
have the same exponent. -/
theorem pow2_exp_unique {a j m : Nat}
(ha : 2^a < m) (ha2 : m ≤ 2^(a+1)) (hj : 2^j < m) (hj2 : m ≤ 2^(j+1)) :
a = j := by
rcases Nat.lt_trichotomy a j with h | h | h
· -- a < j ⇒ a+1 ≤ j ⇒ 2^(a+1) ≤ 2^j < m, contradicting m ≤ 2^(a+1)
have : a + 1 ≤ j := h
have hle : 2^(a+1) ≤ 2^j := Nat.pow_le_pow_right (by omega) this
omega
· exact h
· have : j + 1 ≤ a := h
have hle : 2^(j+1) ≤ 2^a := Nat.pow_le_pow_right (by omega) this
omega
/-- `kbelow` is pinned by its defining inequalities: a power of two `p`
with `p < m ≤ 2p` IS `kbelow m`. -/
theorem kbelow_eq_of_pow2_between {p m : Nat} (j : Nat) (hp : p = 2^j)
(h1 : p < m) (h2 : m ≤ 2 * p) : kbelow m = p := by
have hm2 : 2 ≤ m := by
have : 1 ≤ p := by rw [hp]; exact Nat.one_le_two_pow
omega
obtain ⟨a, ha⟩ := kbelow_pow2 m
have hlt := kbelow_lt m hm2
have hle := le_two_kbelow m hm2
-- kbelow m = 2^a with 2^a < m ≤ 2^(a+1); p = 2^j with 2^j < m ≤ 2^(j+1)
rw [ha] at hlt hle
have hj2 : m ≤ 2^(j+1) := by rw [Nat.pow_succ]; omega
have ha2 : m ≤ 2^(a+1) := by rw [Nat.pow_succ]; omega
have hja : 2^j < m := by omega
have : a = j := pow2_exp_unique hlt ha2 hja hj2
rw [ha, this, ← hp]
/-- The specialization used in the binding: with `k = kbelow n`, `2 ≤ n`,
and `k < n₀ ≤ n`, the prefix tree splits at the same `k`. -/
theorem kbelow_prefix_eq {n n₀ : Nat} (hn : 2 ≤ n)
(hk : k = kbelow n) (hlo : k < n₀) (hhi : n₀ ≤ n) :
kbelow n₀ = k := by
obtain ⟨j, hj⟩ := kbelow_pow2 n
rw [← hk] at hj
have hle := le_two_kbelow n hn
rw [← hk] at hle
exact kbelow_eq_of_pow2_between j hj hlo (by omega)
/-! ### list surgery -/
theorem take_take_le (l : List Bytes) (k n₀ : Nat) (h : k ≤ n₀) :
(l.take n₀).take k = l.take k := by
rw [List.take_take]; congr 1; omega
theorem take_drop_prefix (l : List Bytes) (k n₀ : Nat) :
(l.take n₀).drop k = (l.drop k).take (n₀ - k) := by
rw [List.drop_take]
/-! ### the consistency collision extractor (paper Theorem 3, steps 1-2) -/
/-- Walk the `ConsRec` fold in parallel with the honest size-`n` tree of
`D₁`. At each level the new-root component builds `hnode` of a left and
a right value; compare that argument pair against the honest node
`hnode (MTH (D₁.take k)) (MTH (D₁.drop k))`. Return `some` concrete
colliding preimage pair at the first mismatch (steps 1-2 of Theorem 3),
or `none` if the fold is genuine all the way down — in which case the
binding `x = MTH (D₁.take n₀)` holds (proven in stage 3). -/
noncomputable def extractConsNode (n₀ n : Nat) (C : List Hash) (b : Bool)
(r : Hash) (D₁ : List Bytes) : Option (List UInt8 × List UInt8) :=
if n₀ = n then none
else if n₀ > n ∨ n₀ = 0 ∨ n ≤ 1 then none
else
match C.getLast? with
| none => none
| some s =>
let k := kbelow n
if n₀ ≤ k then
let y' := ((ConsRec n₀ k C.dropLast b r).map Prod.snd).getD default
if y' = MTH (D₁.take k) ∧ s = MTH (D₁.drop k) then
extractConsNode n₀ k C.dropLast b r (D₁.take k)
else
some (0x01 :: (y'.val ++ s.val),
0x01 :: ((MTH (D₁.take k)).val ++ (MTH (D₁.drop k)).val))
else
let y' := ((ConsRec (n₀ - k) (n - k) C.dropLast false r).map Prod.snd).getD default
if s = MTH (D₁.take k) ∧ y' = MTH (D₁.drop k) then
extractConsNode (n₀ - k) (n - k) C.dropLast false r (D₁.drop k)
else
some (0x01 :: (s.val ++ y'.val),
0x01 :: ((MTH (D₁.take k)).val ++ (MTH (D₁.drop k)).val))
termination_by n
decreasing_by
· have h2 : 2 ≤ n := by omega
exact kbelow_lt n h2
· have := kbelow_pos n
omega
end LTLAcc

View file

@ -1,126 +0,0 @@
/- S4 — the DESCENT extractor: two equal-length leaf lists with the same
Merkle root yield an explicit SHA-256 collision.
This is step 3 of the paper's Theorem 3 ("descend"), and it also
restores — in explicit, non-vacuous form — the receipt-uniqueness
content that the S3.5 cleanup deleted with `root_binding` (re-audit
F2): the honest fold is injective up to a collision. Built as a named
function `extractMTH` with a correctness statement about ITS OUTPUT,
so pigeonhole/choice cannot discharge it (guarded by
`extractMTH_nonvacuous`). -/
import Proofs.Extract
namespace LTLAcc
/-- The descent extractor. Given two leaf lists of equal length with
equal Merkle roots but differing data, walk the (shared-shape) tree
to the first divergence and return the concrete colliding preimage
pair — a node preimage pair, or a leaf preimage pair at the bottom. -/
noncomputable def extractMTH (D D' : List Bytes) : List UInt8 × List UInt8 :=
if D.length ≤ 1 then
(0x00 :: D.headD [], 0x00 :: D'.headD [])
else
let k := kbelow D.length
if MTH (D.take k) = MTH (D'.take k) ∧ MTH (D.drop k) = MTH (D'.drop k) then
if D.take k ≠ D'.take k then extractMTH (D.take k) (D'.take k)
else extractMTH (D.drop k) (D'.drop k)
else
(0x01 :: ((MTH (D.take k)).val ++ (MTH (D.drop k)).val),
0x01 :: ((MTH (D'.take k)).val ++ (MTH (D'.drop k)).val))
termination_by D.length
decreasing_by
· simp only [List.length_take]
have h2 : 2 ≤ D.length := by omega
have hk := kbelow_lt D.length h2
omega
· simp only [List.length_drop]
have hp := kbelow_pos D.length
omega
/-- Take/drop reconstruct the whole list (self-contained). -/
theorem take_append_drop (l : List Bytes) (k : Nat) :
l.take k ++ l.drop k = l := List.take_append_drop k l
/-- **Descent correctness** (paper Theorem 3, step 3; and the restored
receipt-uniqueness content of Lemma 2 in explicit form): for equal-
length lists with equal roots but differing data, `extractMTH`
outputs a genuine SHA-256 collision. -/
theorem extractMTH_correct (D D' : List Bytes) :
D.length = D'.length → D ≠ D' → MTH D = MTH D' →
IsCollision (extractMTH D D').1 (extractMTH D D').2 := by
induction D, D' using extractMTH.induct with
| case1 D D' hle =>
intro hlen hne hroot
rw [extractMTH]; simp only [hle, if_pos]
have hd1 : D.length = 1 := by
rcases Nat.eq_zero_or_pos D.length with h0 | hp
· exfalso; apply hne
have hD : D = [] := List.length_eq_zero_iff.mp h0
have hD' : D' = [] := List.length_eq_zero_iff.mp (by omega)
rw [hD, hD']
· omega
obtain ⟨a, rfl⟩ := exists_singleton_of_length_one D hd1
obtain ⟨b, rfl⟩ := exists_singleton_of_length_one D' (by omega)
have hab : a ≠ b := by intro h; exact hne (by rw [h])
rw [MTH_single, MTH_single] at hroot
refine ⟨?_, ?_⟩
· intro hc; injection hc with _ ht; exact hab ht
· simpa using hroot
| case2 D D' hgt k hhalves htake ih =>
intro hlen hne hroot
have hk : kbelow D.length = k := rfl
rw [extractMTH, if_neg hgt, hk, if_pos hhalves, if_pos htake]
apply ih
· simp only [List.length_take]; omega
· exact htake
· exact hhalves.1
| case3 D D' hgt k hhalves htake ih =>
intro hlen hne hroot
have hk : kbelow D.length = k := rfl
rw [extractMTH, if_neg hgt, hk, if_pos hhalves, if_neg htake]
apply ih
· simp only [List.length_drop]; omega
· intro hdrop
apply hne
have ht : D.take k = D'.take k := Decidable.of_not_not htake
calc D = D.take k ++ D.drop k := (take_append_drop D k).symm
_ = D'.take k ++ D'.drop k := by rw [ht, hdrop]
_ = D' := take_append_drop D' k
· exact hhalves.2
| case4 D D' hgt k hhalves =>
intro hlen hne hroot
have h2 : 2 ≤ D.length := by omega
have h2' : 2 ≤ D'.length := by omega
have hkeq : kbelow D'.length = k := by rw [← hlen]
have hk : kbelow D.length = k := rfl
rw [extractMTH, if_neg hgt, hk, if_neg hhalves]
have hsD : MTH D = hnode (MTH (D.take k)) (MTH (D.drop k)) := MTH_split D h2
have hsD' : MTH D' = hnode (MTH (D'.take k)) (MTH (D'.drop k)) := by
have := MTH_split D' h2'; rw [hkeq] at this; exact this
refine ⟨?_, ?_⟩
· intro hc
injection hc with _ happ
have hln : (MTH (D.take k)).val.length = (MTH (D'.take k)).val.length := by
rw [(MTH (D.take k)).property, (MTH (D'.take k)).property]
obtain ⟨e1, e2⟩ := List.append_inj happ hln
exact hhalves ⟨Subtype.ext e1, Subtype.ext e2⟩
· show sha256 _ = sha256 _
have e1 : sha256 (0x01 :: ((MTH (D.take k)).val ++ (MTH (D.drop k)).val)) = MTH D :=
hsD.symm
have e2 : sha256 (0x01 :: ((MTH (D'.take k)).val ++ (MTH (D'.drop k)).val)) = MTH D' :=
hsD'.symm
rw [e1, e2]; exact hroot
/-- Permanent non-vacuity witness (re-audit discipline): on EQUAL lists
the extractor's output is not a collision (both sides identical), so
`extractMTH_correct`'s conclusion is false for some inputs and cannot
be discharged by pigeonhole/choice. -/
theorem extractMTH_nonvacuous :
¬ IsCollision (extractMTH [([7] : List UInt8)] [([7] : List UInt8)]).1
(extractMTH [([7] : List UInt8)] [([7] : List UInt8)]).2 := by
rw [extractMTH]
simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
intro hcol
exact hcol.1 rfl
end LTLAcc

View file

@ -1,223 +0,0 @@
/- S3.5 — the EXPLICIT collision extractor for inclusion soundness.
Why a function and not `∃`: `Hash` is a finite type (32-byte lists),
`sha256` has an infinite domain, so `∃ x y, x ≠ y ∧ sha256 x = sha256 y`
is provable by pigeonhole ALONE — a bare-existential soundness theorem
is vacuous, and even a data-carrying `{p // IsCollision p}` disjunct is
inhabited by `Classical.choice`. The paper's Theorem 2 is an *explicit
algorithm* 𝓔; faithfulness demands a named function `extractIncl` and a
correctness statement ABOUT ITS OUTPUT — a claim pigeonhole cannot
discharge, because it pins down *which* pair. -/
import Proofs.Completeness
namespace LTLAcc
/-- A specific colliding pair (predicate on concrete byte strings). -/
def IsCollision (x y : List UInt8) : Prop :=
x ≠ y ∧ sha256 x = sha256 y
/-- The extractor 𝓔 for inclusion (paper Theorem 2). Given the honest
leaf list `D`, a claimed index `m`, a claimed leaf `d`, and a path
`P`, it walks the honest tree and returns the concrete preimage pair
at the first level where the offered reconstruction diverges from the
honest tree — a node preimage pair high up, or the leaf preimage pair
at the bottom. Total (junk defaults on the branches the soundness
hypothesis excludes). -/
noncomputable def extractIncl (m : Nat) (D : List Bytes) (d : Bytes)
(P : List Hash) : List UInt8 × List UInt8 :=
if D.length ≤ 1 then
-- leaf level: the offered leaf `d` vs the honest leaf `D[m]`
(0x00 :: d, 0x00 :: D.getD m [])
else
let k := kbelow D.length
match P.getLast? with
| none => ([], []) -- excluded: composite size needs a sibling
| some s =>
if m < k then
let child := (Root (hleaf d) m k P.dropLast).getD default
if child = MTH (D.take k) ∧ s = MTH (D.drop k) then
extractIncl m (D.take k) d P.dropLast
else
(0x01 :: (child.val ++ s.val),
0x01 :: ((MTH (D.take k)).val ++ (MTH (D.drop k)).val))
else
let child := (Root (hleaf d) (m - k) (D.length - k) P.dropLast).getD default
if s = MTH (D.take k) ∧ child = MTH (D.drop k) then
extractIncl (m - k) (D.drop k) d P.dropLast
else
(0x01 :: (s.val ++ child.val),
0x01 :: ((MTH (D.take k)).val ++ (MTH (D.drop k)).val))
termination_by D.length
decreasing_by
· simp only [List.length_take]
have h2 : 2 ≤ D.length := by omega
have hk := kbelow_lt D.length h2
omega
· simp only [List.length_drop]
have hp := kbelow_pos D.length
omega
/-- **Theorem 2 (Inclusion soundness), explicit form** — the faithful
replacement for the vacuous bare-existential version. If an accepting
receipt opens position `m` to a leaf `d` different from the honest
`D[m]`, then `extractIncl` OUTPUTS a genuine SHA-256 collision. The
statement is about the fixed function's output, so pigeonhole cannot
prove it: it must exhibit that THIS pair collides. -/
theorem extractIncl_correct (m : Nat) (D : List Bytes) :
∀ (d : Bytes) (P : List Hash), m < D.length → d ≠ D.getD m [] →
Root (hleaf d) m D.length P = some (MTH D) →
IsCollision (extractIncl m D d P).1 (extractIncl m D d P).2 := by
induction m, D using Path.induct with
| case1 m D hle =>
intro d P hm hd h
have h1 : D.length = 1 := by omega
obtain ⟨e, rfl⟩ := exists_singleton_of_length_one D h1
have hm0 : m = 0 := by simpa using hm
subst hm0
rw [extractIncl]
simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
have hlen : ([e] : List Bytes).length = 1 := rfl
rw [hlen] at h
cases P with
| nil =>
rw [Root_one, MTH_single] at h
simp only [Option.some.injEq] at h
have hde : d ≠ e := by simpa using hd
refine ⟨?_, ?_⟩
· intro hc; injection hc with _ ht; exact hde ht
· have hg : ([e] : List Bytes).getD 0 [] = e := rfl
rw [hg]; exact h
| cons p q =>
rw [Root_one_cons] at h
exact absurd h (by simp)
| case2 m D hgt k hmk ih =>
intro d P hm hd h
have h2 : 2 ≤ D.length := by omega
have hkeq : k = kbelow D.length := rfl
have hkl : k < D.length := by rw [hkeq]; exact kbelow_lt D.length h2
have hmk' : m < kbelow D.length := by rw [← hkeq]; exact hmk
have htklen : (D.take k).length = k := by simp [List.length_take]; omega
cases hP : P.getLast? with
| none =>
have hPnil : P = [] := by
cases P with
| nil => rfl
| cons a t => simp at hP
subst hPnil
rw [Root] at h
have hn1 : ¬ D.length = 1 := by omega
have hn0 : ¬ D.length = 0 := by omega
simp [hn1, hn0] at h
| some s =>
obtain hsplit := eq_dropLast_append_of_getLast? P s hP
have hh := h
rw [hsplit, Root_left _ _ _ _ _ h2 hmk', ← hkeq] at hh
cases hR : Root (hleaf d) m k P.dropLast with
| none => rw [hR] at hh; simp at hh
| some x =>
rw [hR] at hh
simp only [Option.map_some, Option.some.injEq] at hh
rw [MTH_split D h2, ← hkeq] at hh
rw [extractIncl]
simp only [if_neg hgt, hP, ← hkeq, if_pos hmk]
have hchild : (Root (hleaf d) m k P.dropLast).getD default = x := by
rw [hR]; rfl
rw [hchild]
by_cases hpair : x = MTH (D.take k) ∧ s = MTH (D.drop k)
· simp only [if_pos hpair]
have ihm : m < (D.take k).length := by omega
have hgetd : (D.take k).getD m [] = D.getD m [] := getD_take D k m hmk
have hd' : d ≠ (D.take k).getD m [] := by rw [hgetd]; exact hd
have hrec : Root (hleaf d) m (D.take k).length P.dropLast
= some (MTH (D.take k)) := by rw [htklen, hR, hpair.1]
exact ih d P.dropLast ihm hd' hrec
· simp only [if_neg hpair]
refine ⟨?_, ?_⟩
· intro hc
injection hc with _ happ
have hlen : x.val.length = (MTH (D.take k)).val.length := by
rw [x.property, (MTH (D.take k)).property]
obtain ⟨hx, hs⟩ := List.append_inj happ hlen
exact hpair ⟨Subtype.ext hx, Subtype.ext hs⟩
· exact hh
| case3 m D hgt k hmk ih =>
intro d P hm hd h
have h2 : 2 ≤ D.length := by omega
have hkeq : k = kbelow D.length := rfl
have hkl : k < D.length := by rw [hkeq]; exact kbelow_lt D.length h2
have hkp : 0 < k := by rw [hkeq]; exact kbelow_pos D.length
have hmk' : ¬ m < kbelow D.length := by rw [← hkeq]; exact hmk
have hdplen : (D.drop k).length = D.length - k := by simp [List.length_drop]
cases hP : P.getLast? with
| none =>
have hPnil : P = [] := by
cases P with
| nil => rfl
| cons a t => simp at hP
subst hPnil
rw [Root] at h
have hn1 : ¬ D.length = 1 := by omega
have hn0 : ¬ D.length = 0 := by omega
simp [hn1, hn0] at h
| some s =>
obtain hsplit := eq_dropLast_append_of_getLast? P s hP
have hh := h
rw [hsplit, Root_right _ _ _ _ _ h2 hmk', ← hkeq] at hh
cases hR : Root (hleaf d) (m - k) (D.length - k) P.dropLast with
| none => rw [hR] at hh; simp at hh
| some x =>
rw [hR] at hh
simp only [Option.map_some, Option.some.injEq] at hh
rw [MTH_split D h2, ← hkeq] at hh
rw [extractIncl]
simp only [if_neg hgt, hP, ← hkeq, if_neg hmk]
have hchild : (Root (hleaf d) (m - k) (D.length - k) P.dropLast).getD default = x := by
rw [hR]; rfl
rw [hchild]
by_cases hpair : s = MTH (D.take k) ∧ x = MTH (D.drop k)
· simp only [if_pos hpair]
have ihm : m - k < (D.drop k).length := by omega
have hidx : k + (m - k) = m := by omega
have hgetd : (D.drop k).getD (m - k) [] = D.getD m [] := by
rw [getD_drop, hidx]
have hd' : d ≠ (D.drop k).getD (m - k) [] := by rw [hgetd]; exact hd
have hrec : Root (hleaf d) (m - k) (D.drop k).length P.dropLast
= some (MTH (D.drop k)) := by rw [hdplen, hR, hpair.2]
exact ih d P.dropLast ihm hd' hrec
· simp only [if_neg hpair]
refine ⟨?_, ?_⟩
· intro hc
injection hc with _ happ
have hlen : s.val.length = (MTH (D.take k)).val.length := by
rw [s.property, (MTH (D.take k)).property]
obtain ⟨hs, hx⟩ := List.append_inj happ hlen
exact hpair ⟨Subtype.ext hs, Subtype.ext hx⟩
· exact hh
/-- **Permanent non-vacuity witness** (re-audit F1): on a NON-forgery
input (the offered leaf IS the honest leaf), the extractor's output
is provably NOT a collision. Hence `extractIncl_correct`'s conclusion
is false for some inputs — it cannot be discharged by pigeonhole or
choice, and only the forgery hypotheses make it hold. This theorem
guards the corpus against any future drift back into vacuity. -/
theorem extractIncl_nonvacuous :
¬ IsCollision (extractIncl 0 [([7] : List UInt8)] [7] []).1
(extractIncl 0 [([7] : List UInt8)] [7] []).2 := by
rw [extractIncl]
simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
intro hcol
exact hcol.1 rfl
/-- Inclusion soundness through the named acceptance predicate (review F1):
if `acceptIncl` holds for a wrong leaf, `extractIncl` outputs a
collision. Ties the object the harness tests to the security theorem.
The range fact `m < |D|` is `hacc.1` — acceptance carries it, so the
caller owes nothing beyond acceptance and the wrong-leaf premise
(review round 2, L1/NEW-2). -/
theorem acceptIncl_sound (m : Nat) (D : List Bytes)
(d : Bytes) (P : List Hash) (hd : d ≠ D.getD m [])
(hacc : acceptIncl d m D.length P (MTH D)) :
IsCollision (extractIncl m D d P).1 (extractIncl m D d P).2 :=
extractIncl_correct m D d P hacc.1 hd hacc.2
end LTLAcc

View file

@ -1,123 +0,0 @@
/- Environment-derived declaration inventory (Phase 3b of check.sh).
Review round 2 (GPT H1) proved the previous source-regex enumerator
evadable: attributed / private / indented / `instance` declarations
were invisible, and a nested `namespace Hidden theorem MTH` collided
with the basename of an audited declaration. This module replaces
source scanning entirely: the inventory is read from the compiled
Lean ENVIRONMENT, so it sees exactly what the kernel saw.
Design (fail-closed by construction):
· The corpus module list below must match check.sh's compile
manifest (check.sh verifies this textually, both directions).
A listed module that is not actually imported is an elaboration
ERROR here, not a silent skip.
· EVERY constant whose originating module is a corpus module is
emitted — fully qualified, NO filtering. Compiler-generated
auxiliaries (equation lemmas, match/eq/induct helpers, private
mangles) are emitted too and pinned in the allowlist; anything
new, renamed, or removed shows up as a diff. There is no name
shape that can hide.
· Each constant carries its declaration KIND and its full axiom
cone, computed by the independent walker below (not by
#print axioms — Phase 3 still runs #print axioms separately, so
the two cone computations cross-check each other in check.sh).
· Output lines are prefixed `INV|` and sorted, so check.sh can
extract them robustly from compiler chatter.
This file is audit INFRASTRUCTURE, not corpus: it is excluded from
the compile manifest (like AxiomCheck.lean) and its own constants
are not inventoried (they live in the current module, which has no
module index). It proves nothing and is imported by nothing. -/
import Lean
import LTLAcc.HashExternal
import Proofs.Basic
import Proofs.Completeness
import Proofs.Extract
import Proofs.Descent
import Proofs.Consistency
import Proofs.Binding3
import Proofs.Refactor
import Proofs.Theorem3
import Proofs.PinStore
open Lean
namespace LTLAccAudit
/-- Exactly check.sh's GEN_MODULES ++ PROOFS, as module names. -/
def corpusModules : Array Name :=
#[`LTLAcc.HashExternal,
`Proofs.Basic, `Proofs.Completeness, `Proofs.Extract, `Proofs.Descent,
`Proofs.Consistency, `Proofs.Binding3, `Proofs.Refactor,
`Proofs.Theorem3, `Proofs.PinStore]
def kindOf : ConstantInfo → String
| .axiomInfo _ => "axiom"
| .defnInfo _ => "def"
| .thmInfo _ => "theorem"
| .opaqueInfo _ => "opaque"
| .quotInfo _ => "quot"
| .inductInfo _ => "inductive"
| .ctorInfo _ => "ctor"
| .recInfo _ => "recursor"
/-- Proof/definition body of a constant. NOTE: `ConstantInfo.value?`
returns `none` for theorems on this toolchain (observed on
4.30.0-rc2), which would silently truncate every cone at the first
theorem — so we match constructors directly. The cross-check against
core `collectAxioms` below would catch any such truncation. -/
def valueOf : ConstantInfo → Option Expr
| .defnInfo v => some v.value
| .thmInfo v => some v.value
| .opaqueInfo v => some v.value
| _ => none
/-- Full axiom cone of `root`: transitive closure over types AND values.
Written independently of core's `CollectAxioms`; the `#eval` below
insists both agree on every constant, and Phase 3 of check.sh
additionally cross-checks the audited names against `#print axioms`
output. -/
def axiomCone (env : Environment) (root : Name) : Array Name := Id.run do
let mut visited : NameSet := {}
let mut axioms : Array Name := #[]
let mut stack : Array Name := #[root]
while h : stack.size > 0 do
let n := stack[stack.size - 1]'(by omega)
stack := stack.pop
unless visited.contains n do
visited := visited.insert n
if let some ci := env.find? n then
if ci matches .axiomInfo _ then
axioms := axioms.push n
stack := stack ++ ci.type.getUsedConstants
if let some v := valueOf ci then
stack := stack ++ v.getUsedConstants
return (axioms.qsort (fun a b => a.toString < b.toString))
#eval show CoreM Unit from do
let env ← getEnv
-- Resolve every corpus module to its index; a miss is a hard error.
let mut idxs : Array Nat := #[]
for m in corpusModules do
match env.getModuleIdx? m with
| some i => idxs := idxs.push i
| none => throwError "INVENTORY ERROR: corpus module {m} is not imported"
let mut lines : Array String := #[]
for (n, ci) in env.constants.toList do
if let some i := env.getModuleIdxFor? n then
if idxs.contains i then
let cone := axiomCone env n
-- Cross-check against core's collector (the same machinery
-- `#print axioms` uses): any divergence is a hard error.
let coreCone := (← collectAxioms n).qsort (fun a b => a.toString < b.toString)
unless cone == coreCone do
throwError "INVENTORY ERROR: cone divergence on {n}: walker={cone} core={coreCone}"
let coneStr := ",".intercalate (cone.toList.map (·.toString))
lines := lines.push s!"INV|{n}|{kindOf ci}|{coneStr}"
let sorted := lines.qsort (· < ·)
for l in sorted do
IO.println l
IO.println s!"INV-COUNT|{sorted.size}"
end LTLAccAudit

View file

@ -1,93 +0,0 @@
/- S6 — **Proposition 1 (Pin-store safety)**, the Merkle-layer contribution.
The consumer pin store (§5.4) as a transition predicate; monotonicity is
definitional, and prefix-ordering — the substantive part — reduces to
Theorem 3 (grow) and the whole-tree Lemma 2 (same-size), stated as an
explicit named-extractor collision (non-vacuous), never a bare ∃.
SCOPE: Ed25519 EUF-CMA is NOT in this corpus (signatures are abstract).
Part (2) of the paper's Prop 1 — that two conflicting signed heads are
*transferable* evidence — is a signature-layer fact; the Merkle layer
contributes only that different roots at equal size commit to different
content (fork_distinct). This boundary is documented, not smuggled. -/
import Proofs.Theorem3
namespace LTLAcc
/-- The pin-store accept predicate (§5.4): same size ⇒ root must match;
smaller ⇒ reject (rollback); larger ⇒ a consistency proof from the
pinned head must verify. Mirrors sthstore.py. -/
def pinAccept (n : Nat) (r : Hash) (n' : Nat) (r' : Hash) (C : List Hash) : Prop :=
if n' = n then r' = r
else if n' < n then False
else ConsRec n n' C true r = some (r, r')
/-- **Monotonicity (size)**: an accepted step never shrinks the pin. -/
theorem pinAccept_monotone (n : Nat) (r : Hash) (n' : Nat) (r' : Hash)
(C : List Hash) (h : pinAccept n r n' r' C) : n ≤ n' := by
unfold pinAccept at h
by_cases he : n' = n
· omega
· by_cases hl : n' < n
· simp [he, hl] at h
· omega
/-- The pin-store collision extractor: whole-tree descent at equal size,
else the consistency extractor. -/
noncomputable def pinExtract (n n' : Nat) (C : List Hash)
(D D' : List Bytes) : List UInt8 × List UInt8 :=
if n' = n then extractMTH D D' else extractCons n C D D'
/-- **Prefix-ordering (monotonicity, content)**: if the pin advances from an
honest head of `D` to an honest head of `D'` but `D` is NOT the prefix
of `D'` of its length, then `pinExtract` outputs a genuine collision.
(Explicit form ⇒ non-vacuous; this is the paper's Prop 1(1).) -/
theorem pin_prefix_correct (n n' : Nat) (r r' : Hash) (C : List Hash)
(D D' : List Bytes)
(hstep : pinAccept n r n' r' C)
(hDlen : D.length = n) (hDr : MTH D = r)
(hD'len : D'.length = n') (hD'r : MTH D' = r')
(hn0 : 0 < n) (hne : D ≠ D'.take n) :
IsCollision (pinExtract n n' C D D').1 (pinExtract n n' C D D').2 := by
unfold pinAccept at hstep
by_cases he : n' = n
· -- same size: r' = r ⇒ MTH D' = MTH D; D ≠ D'.take n = D' (len n)
simp only [if_pos he] at hstep
rw [pinExtract]; simp only [if_pos he]
have hlen : D.length = D'.length := by rw [hDlen, hD'len, he]
have hroot : MTH D = MTH D' := by rw [hDr, hD'r, hstep]
have hne' : D ≠ D' := by
intro h; apply hne; rw [h]
have hta : D'.take n = D' := by apply take_all; rw [hD'len]; exact he
rw [hta]
exact extractMTH_correct D D' hlen hne' hroot
· by_cases hl : n' < n
· simp [he, hl] at hstep
· -- grow: ConsRec n n' C true r = some (r, r')
have hgrow : ConsRec n n' C true r = some (r, r') := by
simp only [he, hl, if_false] at hstep; exact hstep
rw [pinExtract]; simp only [if_neg he]
have hle : n ≤ D'.length := by omega
have hacc : ConsRec n D'.length C true (MTH D) = some (MTH D, MTH D') := by
rw [hDr, hD'r, hD'len]; exact hgrow
exact extractCons_correct n C D D' hDlen hn0 hle hne hacc
/-- **Fork observation (Merkle-layer share of Prop 1(2))**: two honest
heads of equal size with different roots commit to different content.
(Transferable-evidence via EUF-CMA is signature-layer, out of scope.) -/
theorem fork_distinct (n : Nat) (r r' : Hash) (D D' : List Bytes)
(hDlen : D.length = n) (hD'len : D'.length = n)
(hDr : MTH D = r) (hD'r : MTH D' = r') (hrne : r ≠ r') : D ≠ D' := by
intro h; apply hrne; rw [← hDr, ← hD'r, h]
/-- Permanent non-vacuity witness for pin_prefix_correct: on an honest
non-fork step (D IS the prefix), the extractor output is not a
collision. Uses the same-size identity D = D' = [[7]]. -/
theorem pin_prefix_nonvacuous :
¬ IsCollision (pinExtract 1 1 [] [([7] : List UInt8)] [([7] : List UInt8)]).1
(pinExtract 1 1 [] [([7] : List UInt8)] [([7] : List UInt8)]).2 := by
rw [pinExtract]; simp only [if_pos rfl]
rw [extractMTH]; simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
intro hcol; exact hcol.1 rfl
end LTLAcc

View file

@ -1,33 +0,0 @@
/- S5.3 Fable re-audit artifact (permanent, not a throwaway probe): the
S5.3 change of ConsRec's base from list-match to decidable `if` must be
SEMANTICS-PRESERVING — Opus's only evidence was "the chain recompiled".
These two theorems machine-check the equivalence against the exact
list-match forms that were replaced, so the refactor's faithfulness is
a permanent, cone-audited guarantee.
PROVENANCE (verified against git history, not memory): the RHS forms
below are verbatim the base of `ConsRec` at commit cfde9b2 (pre-
refactor), and `git diff cfde9b2 8795e82 -- Proofs/Basic.lean` shows
the refactor touched ONLY those eight base lines. Unchanged remainder
(git) + equal base (kernel) = the whole function is unchanged. -/
import Proofs.Basic
namespace LTLAcc
/-- b=false base: decidable-if form = the original `[s]` list-match. -/
theorem consRec_base_false_eq (C : List Hash) :
(if C.length = 1 then some ((C.getLastD default, C.getLastD default) : Hash × Hash) else none)
= (match C with | [s] => some (s, s) | _ => none) := by
cases C with
| nil => rfl
| cons a t => cases t with | nil => rfl | cons b u => simp
/-- b=true base: decidable-if form = the original `[]` list-match. -/
theorem consRec_base_true_eq (C : List Hash) (r : Hash) :
(if C = [] then some ((r, r) : Hash × Hash) else none)
= (match C with | [] => some (r, r) | _ => none) := by
cases C with
| nil => rfl
| cons a t => rfl
end LTLAcc

View file

@ -1,81 +0,0 @@
/- S5.4 — **Theorem 3 (Consistency soundness)**, assembled: the explicit
extractor 𝓔′ for history rewrites. Joins consRecBinding (steps 1-2,
S5.3) to extractMTH (step 3, S4).
Statement design per the corpus discipline: a NAMED function whose
correctness is about ITS OUTPUT (pigeonhole/choice cannot discharge
it), guarded by a permanent non-vacuity witness. -/
import Proofs.Binding3
namespace LTLAcc
/-- The consistency extractor 𝓔′ (paper Theorem 3). On a claimed rewrite
— an accepted consistency proof `C` between the pinned root of `D₀`
and the head of `D₁`, where `D₀` is NOT the real prefix — return the
node collision found while walking the fold, or descend into the two
same-root prefix trees. -/
noncomputable def extractCons (n₀ : Nat) (C : List Hash)
(D₀ D₁ : List Bytes) : List UInt8 × List UInt8 :=
match extractConsNode n₀ D₁.length C true (MTH D₀) D₁ with
| some c => c
| none => extractMTH D₀ (D₁.take n₀)
/-- **Theorem 3 (Consistency soundness), explicit form**: if the
consumer's verifier accepts `C` between the pinned head `MTH D₀`
(size `n₀`) and the offered head `MTH D₁`, but `D₀` is not the real
prefix of `D₁`, then `extractCons` outputs a genuine SHA-256
collision. -/
theorem extractCons_correct (n₀ : Nat) (C : List Hash) (D₀ D₁ : List Bytes)
(hlen0 : D₀.length = n₀) (hn0 : 0 < n₀) (hle : n₀ ≤ D₁.length)
(hne : D₀ ≠ D₁.take n₀)
(hacc : ConsRec n₀ D₁.length C true (MTH D₀) = some (MTH D₀, MTH D₁)) :
IsCollision (extractCons n₀ C D₀ D₁).1 (extractCons n₀ C D₀ D₁).2 := by
have hbind := consRecBinding (MTH D₀) n₀ D₁.length C true D₁
(MTH D₀) (MTH D₁) rfl hn0 hle hacc rfl
rw [extractCons]
cases hrec : extractConsNode n₀ D₁.length C true (MTH D₀) D₁ with
| some c =>
rw [hrec] at hbind
exact hbind
| none =>
rw [hrec] at hbind
-- hbind : MTH D₀ = MTH (D₁.take n₀); descend
have htklen : (D₁.take n₀).length = n₀ := by
rw [List.length_take]; omega
exact extractMTH_correct D₀ (D₁.take n₀) (by omega) hne hbind
/-- Permanent non-vacuity witness: on a NON-rewrite input (the pinned
list IS the real prefix), the extractor's output is provably NOT a
collision — so the correctness conclusion is false for some inputs
and cannot be discharged by pigeonhole or choice. Uses the honest
n₀ = n base: D₀ = D₁ = [[7]], C = [], where ConsRec accepts and
extractConsNode returns none, so extractCons = extractMTH D₀ D₀ =
the equal leaf pair. -/
theorem extractCons_nonvacuous :
¬ IsCollision (extractCons 1 [] [([7] : List UInt8)] [([7] : List UInt8)]).1
(extractCons 1 [] [([7] : List UInt8)] [([7] : List UInt8)]).2 := by
rw [extractCons]
have hrec : extractConsNode 1 ([([7] : List UInt8)]).length [] true
(MTH [([7] : List UInt8)]) [([7] : List UInt8)] = none := by
rw [extractConsNode]; simp
rw [hrec]
rw [extractMTH]
simp only [List.length_singleton, if_pos (by omega : (1:Nat) ≤ 1)]
intro hcol
exact hcol.1 rfl
/-- Theorem 3 at the paper's exact quantifiers (review M4): `n₀ ≤ n₁`
without a separate `0 < n₀`. The `n₀ = 0` case is discharged: `D₀`
has length 0 so `D₀ = [] = D₁.take 0`, contradicting `hne`. -/
theorem extractCons_correct_paper (n₀ : Nat) (C : List Hash) (D₀ D₁ : List Bytes)
(hlen0 : D₀.length = n₀) (hle : n₀ ≤ D₁.length)
(hne : D₀ ≠ D₁.take n₀)
(hacc : ConsRec n₀ D₁.length C true (MTH D₀) = some (MTH D₀, MTH D₁)) :
IsCollision (extractCons n₀ C D₀ D₁).1 (extractCons n₀ C D₀ D₁).2 := by
rcases Nat.eq_zero_or_pos n₀ with h0 | hpos
· exfalso; apply hne
have hD0 : D₀ = [] := List.length_eq_zero_iff.mp (by omega)
rw [hD0, h0]; simp
· exact extractCons_correct n₀ C D₀ D₁ hlen0 hpos hle hne hacc
end LTLAcc

View file

@ -17,81 +17,20 @@ export LEAN_MEM_MB="${LEAN_MEM_MB:-4096}"
CORES="${LEAN_MAX_CORES:-0-3}"
GEN_MODULES=( LTLAcc/HashExternal )
PROOFS=( Basic Completeness Extract Descent Consistency Binding3 Refactor Theorem3 PinStore )
PROOFS=( Basic )
# Certificates and their exact expected cones (observed via #print axioms,
# never guessed; any drift in EITHER direction is a failure).
# AUDIT SURFACE: Phase 3b pins the FULL environment of the corpus modules
# (inventory-allowlist.txt, 218 constants incl. compiler-generated
# auxiliaries); the 59 entries below are the human-reviewed statement
# surface, additionally queried through #print axioms in Phase 3 and
# cross-checked against the inventory's independently computed cones.
# Certificates and their exact expected cones (observed at first green
# compile, 2026-07-10; any drift in EITHER direction is a failure).
declare -A CONES=(
[LTLAcc.domsep]=""
[LTLAcc.kbelow_pos]="propext, Quot.sound"
[LTLAcc.kbelow_lt]="propext, Quot.sound"
[LTLAcc.le_two_kbelow]="propext, Quot.sound"
[LTLAcc.kbelow_pow2]="propext, Quot.sound"
[LTLAcc.MTH]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Root]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.ConsRec]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Path]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.incl_complete]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.hnode_preimage_inj]="propext"
[LTLAcc.IsCollision]="LTLAcc.sha256"
[LTLAcc.extractIncl]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractIncl_correct]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractIncl_nonvacuous]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractMTH]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractMTH_correct]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractMTH_nonvacuous]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.kbelow_prefix_eq]="propext, Quot.sound"
[LTLAcc.take_take_le]="propext, Quot.sound"
[LTLAcc.take_drop_prefix]="propext, Classical.choice, Quot.sound"
[LTLAcc.extractConsNode]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.take_all]="propext"
[LTLAcc.consRecBinding]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.consRec_base_false_eq]="propext, Classical.choice, Quot.sound"
[LTLAcc.consRec_base_true_eq]="propext"
[LTLAcc.extractCons]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractCons_correct]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractCons_nonvacuous]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.pinAccept_monotone]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.pin_prefix_correct]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.fork_distinct]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.pin_prefix_nonvacuous]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.MTH_single]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.MTH_split]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Root_left]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Root_one]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Root_one_cons]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.Root_right]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.acceptCons]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.exists_singleton_of_length_one]="propext, Classical.choice, Quot.sound"
[LTLAcc.getD_drop]="propext, Quot.sound"
[LTLAcc.getD_take]="propext, Quot.sound"
[LTLAcc.hleaf]="LTLAcc.sha256"
[LTLAcc.hnode]="LTLAcc.sha256"
[LTLAcc.kbelow]="propext, Quot.sound"
[LTLAcc.kbelow_eq_of_pow2_between]="propext, Quot.sound"
[LTLAcc.pinAccept]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.pinExtract]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.pow2_exp_unique]="propext, Quot.sound"
[LTLAcc.take_append_drop]=""
[LTLAcc.eq_dropLast_append_of_getLast?]="propext"
[LTLAcc.instInhabitedHash]="propext"
[LTLAcc.instDecidableEqHash]=""
[LTLAcc.Hash]=""
[LTLAcc.acceptIncl]="propext, LTLAcc.sha256, Quot.sound"
[LTLAcc.acceptIncl_complete]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.acceptIncl_sound]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
[LTLAcc.extractCons_correct_paper]="propext, Classical.choice, LTLAcc.sha256, Quot.sound"
)
# (The former EXCLUDE table is gone: since Phase 3b reads the environment,
# sha256 and Bytes are ordinary allowlist entries — the axiom is pinned as
# the SINGLE axiom-kind constant, the abbrev carries its empty cone.)
free -m | awk '/Mem:/{if($7<2048){print "FATAL: <2GB RAM available — refusing to compile"; exit 1}}'
echo "=== Phase 0: source integrity ==="
for f in "$HERE"/gen/LTLAcc/*.lean "$HERE"/Proofs/*.lean; do
@ -101,11 +40,6 @@ for f in "$HERE"/gen/LTLAcc/*.lean "$HERE"/Proofs/*.lean; do
fi
done
echo " all sources valid"
# Recursive: no compiled artifact anywhere in the tree may lack its source
# (review round 2, GPT M1 — previously scanned Proofs/*.olean only).
while IFS= read -r -d '' o; do
[ -f "${o%.olean}.lean" ] || { echo "ORPHAN OLEAN: $o has no sibling .lean (stale artifact)"; exit 1; }
done < <(find "$HERE" -name '*.olean' -print0)
echo "=== Phase 1: stub + axiom-smuggling audit ==="
if grep -rn 'by trivial' "$HERE"/Proofs/*.lean 2>/dev/null; then
@ -115,11 +49,6 @@ if grep -rn ' : True :=' "$HERE"/Proofs/*.lean 2>/dev/null; then
if grep -rnE '^(private |protected |noncomputable )*axiom ' "$HERE"/Proofs/*.lean 2>/dev/null; then
echo "AXIOM SMUGGLING DETECTED: axiom under Proofs/ — gen/ is the only sanctioned site."; exit 1
fi
# gen/ is the sanctioned site for exactly ONE axiom (review round 2, GPT M1).
# This textual pin is the fast belt; the semantic guarantee is Phase 3b's
# environment inventory (exactly one axiom-kind constant, LTLAcc.sha256).
AXCOUNT=$(grep -hcE '^(private |protected |noncomputable )*axiom ' "$HERE"/gen/LTLAcc/*.lean | paste -sd+ - | bc)
[ "$AXCOUNT" = 1 ] || { echo "AXIOM COUNT DRIFT: gen/ declares $AXCOUNT axioms, sanctioned: 1 (sha256)"; exit 1; }
echo " clean"
echo "=== Phase 2: compile ==="
@ -140,15 +69,9 @@ lake env bash -c "
done
for f in Proofs/*.lean; do
b=\$(basename \"\$f\" .lean)
[ \"\$b\" = AxiomCheck ] && continue # audit infrastructure, compiled in Phase 3
[ \"\$b\" = Inventory ] && continue # audit infrastructure, compiled in Phase 3b
[ \"\$b\" = AxiomCheck ] && continue
case \" ${PROOFS[*]} \" in (*\" \$b \"*) ;; (*) echo \"DEAD FILE: \$f\"; exit 1;; esac
done
# gen/ gets the same unmanifested-source check (review round 2, GPT M1)
for f in gen/LTLAcc/*.lean; do
b=\"LTLAcc/\$(basename \"\$f\" .lean)\"
case \" ${GEN_MODULES[*]} \" in (*\" \$b \"*) ;; (*) echo \"DEAD FILE (gen): \$f\"; exit 1;; esac
done
"
if grep -q "uses 'sorry'" "$LOG"; then echo "STUB: sorry detected"; exit 1; fi
rm -f "$LOG"
@ -178,86 +101,5 @@ for cert in "${!CONES[@]}"; do
fi
done
rm -f "$AUD"
# -- Phase 3b: ENVIRONMENT-derived audit-surface coverage (fail-closed) ------
# Review round 2 (GPT H1 / Claude NEW-1): the previous source-regex
# enumerator was evadable (attributes, indentation, private/protected,
# instance, and namespace-nested basename collisions). Replaced entirely:
# Proofs/Inventory.lean reads the compiled Lean ENVIRONMENT and emits every
# constant of every corpus module — fully qualified, unfiltered, each with
# kind and axiom cone (its own walker, cross-checked in-process against
# core collectAxioms). inventory_gate.sh diffs that against the pinned
# allowlist, fail-closed BOTH directions. No name shape can hide: what the
# kernel saw is what gets audited.
echo "=== Phase 3b: environment-derived audit-surface coverage ==="
COVFAIL=0
INVLOG=$(mktemp /tmp/acc-inv-XXXX.log)
cd "$AENEAS_LEAN"
lake env bash -c "
cd '$HERE' && export LEAN_PATH=\"\$LEAN_PATH:$HERE/gen:$HERE\"
LEAN_TIMEOUT=600 LEAN_MAX_CORES=$CORES '$HERE/lean-guard' Proofs/Inventory.lean
" > "$INVLOG" 2>&1 || { cat "$INVLOG"; echo "INVENTORY COMPILE FAILED"; exit 1; }
"$HERE/inventory_gate.sh" "$INVLOG" "$HERE/inventory-allowlist.txt" || COVFAIL=1
# The inventory's corpus-module list must BE the compile manifest — both
# directions, so neither can drift from the other silently.
for m in "${GEN_MODULES[@]}" "${PROOFS[@]}"; do
mod=$(echo "$m" | sed 's|^LTLAcc/|LTLAcc.|; s|^\([A-Z]\)|Proofs.\1|; s|^Proofs\.LTLAcc\.|LTLAcc.|')
grep -qF "\`$mod" "$HERE/Proofs/Inventory.lean" || {
echo " MANIFEST DRIFT: $mod compiled by check.sh but not inventoried"; COVFAIL=1; }
done
NMANIFEST=$(( ${#GEN_MODULES[@]} + ${#PROOFS[@]} ))
NINV=$(grep -oE '`(LTLAcc|Proofs)\.[A-Za-z0-9_.]+' "$HERE/Proofs/Inventory.lean" | wc -l)
[ "$NMANIFEST" = "$NINV" ] || {
echo " MANIFEST DRIFT: check.sh compiles $NMANIFEST modules, Inventory lists $NINV"; COVFAIL=1; }
# CONES ⊆ allowlist with IDENTICAL cones: the #print-axioms-pinned table
# and the environment inventory are two independent computations of the
# same facts — any disagreement is a failure of one of them.
# (cones are compared as SETS: CONES keeps #print-axioms order, the
# inventory emits byte-sorted order — canonicalize both before comparing)
canon() { tr -d ' ' <<<"$1" | tr ',' '\n' | LC_ALL=C sort | paste -sd, -; }
while IFS='|' read -r _ name _ cone; do
if [ -n "${CONES[$name]+x}" ]; then
want=$(canon "${CONES[$name]}")
got=$(canon "$cone")
[ "$want" = "$got" ] || {
echo " CONE CROSS-CHECK FAILED: $name CONES=[$want] inventory=[$got]"; COVFAIL=1; }
fi
done < <(grep '^INV|' "$HERE/inventory-allowlist.txt")
for cert in "${!CONES[@]}"; do
grep -q "^INV|$cert|" "$HERE/inventory-allowlist.txt" || {
echo " PINNED BUT NOT INVENTORIED: $cert (in CONES, not in allowlist)"; COVFAIL=1; }
done
rm -f "$INVLOG"
# every pinned cert must actually be queried by AxiomCheck (no pin-but-never-check)
for cert in "${!CONES[@]}"; do
grep -qF "#print axioms $cert" "$HERE/Proofs/AxiomCheck.lean" || {
echo " PINNED BUT NOT QUERIED: $cert (in CONES, absent from AxiomCheck.lean)"; COVFAIL=1; }
done
[ "$COVFAIL" = 0 ] && echo " coverage complete: environment == allowlist, CONES cross-checked"
[ "$COVFAIL" = 0 ] || { echo "COVERAGE FAILED"; FAIL=1; }
[ "$FAIL" = 0 ] || exit 1
# -- Phase 4: definition fidelity (Lean defs vs deployed pacta verifiers) --
echo "=== Phase 4: definition fidelity ==="
PACTA_SRC="${PACTA_SRC:-$HERE/../../proof-aware-crypto-tooling-agent/src}"
FIDELITY_RAN=0
if [ "${SKIP_FIDELITY:-0}" = "1" ]; then
echo " skipped (SKIP_FIDELITY=1)"
elif [ -d "$PACTA_SRC/pacta" ]; then
PACTA_SRC="$PACTA_SRC" python3 "$HERE/fidelity/run_fidelity.py" || { echo "FIDELITY FAILED"; exit 1; }
FIDELITY_RAN=1
else
echo " SKIPPED: pacta repo not found at $PACTA_SRC (set PACTA_SRC to run)"
fi
# Fail-closed markers (review H2): the Lean corpus is green either way, but
# only the strong marker — required by the attestation gate — is emitted
# when fidelity actually ran. Never conflate the two.
echo "=== LEAN GREEN ==="
if [ "$FIDELITY_RAN" = 1 ]; then
echo "=== ATTESTATION GREEN (Lean + fidelity) ==="
else
echo "=== FIDELITY NOT RUN — NOT attestation-ready (run with pacta present) ==="
fi
echo "=== ALL GREEN ==="

View file

@ -1,106 +0,0 @@
"""Line-faithful Python transliteration of the LEAN definitions in
Proofs/Basic.lean and Proofs/Completeness.lean (commit-current forms,
including the decidable-if ConsRec base and the recursive kbelow).
Each function quotes its Lean source. The fidelity harness
(run_fidelity.py) differential-tests these against the DEPLOYED pacta
verifiers; any transliteration drift is caught by the exhaustive run,
any Lean-vs-deployed drift is the finding the harness exists for.
"""
import hashlib
def sha256(b: bytes) -> bytes:
return hashlib.sha256(b).digest()
def hleaf(d: bytes) -> bytes:
# Lean: hleaf d = sha256 (0x00 :: d)
return sha256(b"\x00" + d)
def hnode(x: bytes, y: bytes) -> bytes:
# Lean: hnode x y = sha256 (0x01 :: (x.val ++ y.val))
return sha256(b"\x01" + x + y)
def kbelow(n: int) -> int:
# Lean: if n ≤ 2 then 1 else 2 * kbelow ((n + 1) / 2)
if n <= 2:
return 1
return 2 * kbelow((n + 1) // 2)
def MTH(D: list) -> bytes:
# Lean: if length = 0 then sha256 [] ; if length = 1 then hleaf (headD [])
# else hnode (MTH (take k)) (MTH (drop k)), k = kbelow length
if len(D) == 0:
return sha256(b"")
if len(D) == 1:
return hleaf(D[0])
k = kbelow(len(D))
return hnode(MTH(D[:k]), MTH(D[k:]))
def Path(m: int, D: list) -> list:
# Lean: if length ≤ 1 then [] else (m<k: Path m take ++ [MTH drop]
# | else: Path (m-k) drop ++ [MTH take])
if len(D) <= 1:
return []
k = kbelow(len(D))
if m < k:
return Path(m, D[:k]) + [MTH(D[k:])]
return Path(m - k, D[k:]) + [MTH(D[:k])]
def Root(v: bytes, m: int, n: int, P: list):
# Lean: n=1: (if P = [] then some v else none); n=0: none;
# P.getLast? none: none; m<k: (Root v m k P').map (hnode · s)
# else (Root v (m-k) (n-k) P').map (hnode s ·)
if n == 1:
return v if P == [] else None
if n == 0:
return None
if P == []:
return None
s = P[-1]
k = kbelow(n)
if m < k:
x = Root(v, m, k, P[:-1])
return None if x is None else hnode(x, s)
x = Root(v, m - k, n - k, P[:-1])
return None if x is None else hnode(s, x)
def ConsRec(n0: int, n: int, C: list, b: bool, r: bytes):
# Lean (post-refactor, machine-verified equivalent to the original):
# n0=n: b: (if C = [] then some (r,r) else none)
# ¬b: (if C.length = 1 then some (getLastD, getLastD) else none)
# n0>n ∨ n0=0 ∨ n≤1: none ; getLast? none: none
# n0≤k: sub.map (fun (x,y) => (x, hnode y s))
# else: sub(false).map (fun (x,y) => (hnode s x, hnode s y))
if n0 == n:
if b:
return (r, r) if C == [] else None
return (C[-1], C[-1]) if len(C) == 1 else None
if n0 > n or n0 == 0 or n <= 1:
return None
if C == []:
return None
s = C[-1]
k = kbelow(n)
if n0 <= k:
sub = ConsRec(n0, k, C[:-1], b, r)
return None if sub is None else (sub[0], hnode(sub[1], s))
sub = ConsRec(n0 - k, n - k, C[:-1], False, r)
return None if sub is None else (hnode(s, sub[0]), hnode(s, sub[1]))
def accept_incl(d: bytes, m: int, n: int, P: list, root: bytes) -> bool:
# Lean acceptance: m < n ∧ Root (hleaf d) m n P = some root
return m < n and Root(hleaf(d), m, n, P) == root
def accept_cons(n0: int, n1: int, r0: bytes, r1: bytes, C: list) -> bool:
# Lean acceptCons: n0 = 0 ∨ ConsRec n0 n1 C true r0 = some (r0, r1)
return n0 == 0 or ConsRec(n0, n1, C, True, r0) == (r0, r1)

View file

@ -1,117 +0,0 @@
#!/usr/bin/env python3
"""S7 definition-fidelity harness for ltl-accumulator-verified.
Differential-tests the LEAN definitions (transliterated in lean_defs.py:
MTH / Path / Root / ConsRec, post-refactor decidable-if base) against the
DEPLOYED pacta verifiers, over the EXACT case generation of the paper's
tests/test_paper_verifiers.py — this run establishes agreement between the mechanized objects and the
deployed RFC 9162 code EXHAUSTIVELY OVER all size/index (and old/new
size) pairs through 256 FOR the two fixed generated datasets and the
listed mutation classes (honest, wrong-leaf, wrong-index, wrong-root,
truncated/padded proof, and out-of-range m≥n / n0>n1 / n0=0). It is not
a proof of extensional equality over all inputs; the Lean-to-Python
bridge remains trusted quoted-source inspection (see KNOWN-GAPS).
Requires the pacta repo on PYTHONPATH (its src/). Bound NMAX matches the
paper.
"""
import hashlib
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
PACTA_SRC = os.environ.get("PACTA_SRC",
os.path.join(HERE, "..", "..", "..", "proof-aware-crypto-tooling-agent", "src"))
sys.path.insert(0, PACTA_SRC)
sys.path.insert(0, HERE)
# deployed (pacta) side
from pacta.transparency import ( # noqa: E402
consistency_proof, inclusion_proof, merkle_root,
verify_consistency, verify_inclusion,
)
# lean (mechanized) side
import lean_defs as L # noqa: E402
NMAX = int(os.environ.get("FIDELITY_NMAX", "256"))
def _h(b):
return hashlib.sha256(b).digest()
def inclusion():
total = 0
root_checks = 0
path_checks = 0
for n in range(1, NMAX + 1):
data = [bytes([i % 251]) + bytes([(i * 5) % 256]) * (i % 3) for i in range(n)]
root = merkle_root(data)
# root fidelity: Lean MTH == deployed merkle_root
assert L.MTH(data) == root, ("MTH drift", n)
root_checks += 1
for m in range(n):
P = inclusion_proof(data, m)
# path fidelity: Lean Path == deployed inclusion_proof
assert L.Path(m, data) == P, ("Path drift", n, m)
path_checks += 1
cases = [
(data[m], m, n, P, root),
(data[m] + b"!", m, n, P, root),
(data[m], (m + 1) % n, n, P, root),
(data[m], m, n, P, _h(b"q")),
(data[m], n, n, P, root), # out-of-range m = n (review F1)
(data[m], n + 3, n, P, root), # out-of-range m > n (review F1)
]
if P:
cases.append((data[m], m, n, P[:-1], root))
for d2, m2, n2, P2, r2 in cases:
total += 1
dep = verify_inclusion(d2, m2, n2, P2, r2)
lean = L.accept_incl(d2, m2, n2, P2, r2)
assert dep == lean, ("INCL VERIFIER DRIFT", n, m, dep, lean)
return total, root_checks, path_checks
def consistency():
total = 0
for n in range(1, NMAX + 1):
data = [bytes([i % 251]) + bytes([(i * 7) % 256]) * (i % 4) for i in range(n)]
r1 = merkle_root(data)
assert L.MTH(data) == r1, ("MTH drift (cons)", n)
for m in range(1, n + 1):
P = consistency_proof(data, m)
r0 = merkle_root(data[:m])
cases = [
(m, n, r0, r1, P), # honest consistency
(m, n, _h(b"x"), r1, P),
(m, n, r0, _h(b"y"), P),
(m, n, r0, r1, P + [_h(b"z")]),
(n + 1, n, r1, r0, P), # n0 > n1 (review F1)
(0, n, r0, r1, P), # n0 = 0 escape (review F1)
]
if P:
cases.append((m, n, r0, r1, P[:-1]))
for mm, nn, a, bb, pp in cases:
total += 1
dep = verify_consistency(mm, nn, a, bb, pp)
lean = L.accept_cons(mm, nn, a, bb, pp)
assert dep == lean, ("CONS VERIFIER DRIFT", n, m, dep, lean)
return total
def main():
print(f"S7 fidelity: Lean defs vs deployed pacta, NMAX={NMAX}")
ti, rc, pc = inclusion()
print(f" inclusion: {ti} verifier cases, {rc} MTH==merkle_root, {pc} Path==inclusion_proof — all agree")
tc = consistency()
print(f" consistency: {tc} verifier cases (incl. honest), MTH checks — all agree")
# pinned counts (identical generation to the paper's harness)
assert ti == 230_271, ti # re-pinned after adding out-of-range families (F1)
assert tc == 230_016, tc
print(f" PINNED: inclusion={ti} (230,271) consistency={tc} (230,016)")
print("=== FIDELITY GREEN: mechanized defs agree with deployed verifier ===")
if __name__ == "__main__":
main()

View file

@ -1,22 +1,12 @@
/- The single sanctioned axiom site of this corpus (mirrors the role of
gen/ in the *-ed25519-verified repos): SHA-256 as an opaque function
into 32-byte outputs. No properties are assumed of it — in particular
NOT collision resistance; the soundness theorems downstream are
constructive, they EXHIBIT two distinct preimages with equal image.
The fixed output WIDTH is part of the function's type, not an
assumption about its behavior: it is what makes hnode argument pairs
recoverable from preimages (the paper's "65-byte preimages"
parenthetical, made explicit). -/
gen/ in the *-ed25519-verified repos): SHA-256 as an opaque function.
No properties are assumed of it — in particular NOT collision
resistance. The soundness theorems downstream are constructive: they
EXHIBIT two distinct preimages with equal image. Believing such a
pair cannot be found is the reader's interpretation step, exactly as
documented in the paper (§6, Remark 1). -/
namespace LTLAcc
/-- A 32-byte hash value. -/
def Hash : Type := { l : List UInt8 // l.length = 32 }
instance : Inhabited Hash := ⟨⟨List.replicate 32 0, by simp⟩⟩
instance : DecidableEq Hash := fun a b =>
decidable_of_iff (a.val = b.val) Subtype.ext_iff.symm
axiom sha256 : List UInt8 → Hash
axiom sha256 : List UInt8 → List UInt8
end LTLAcc

Binary file not shown.

View file

@ -1,235 +0,0 @@
# inventory-allowlist.txt — the pinned audit surface (Phase 3b).
#
# One line per constant in the compiled environment of the corpus
# modules (GEN_MODULES + PROOFS in check.sh), emitted by
# Proofs/Inventory.lean: INV|<fully-qualified name>|<kind>|<axiom cone>
#
# EVERYTHING the kernel saw is here — including compiler-generated
# auxiliaries (match_*/eq_*/induct/_proof_*/_unary and _private.*
# mangles). There is no filtering, so there is no name shape that can
# escape: a new, renamed, re-namespaced, private, attributed, indented,
# or instance declaration changes the environment and fails the diff.
# Regenerate ONLY by reviewing `lean-guard Proofs/Inventory.lean` output
# line by line; every addition must be justified in STATEMENT-MAP.md or
# be a compiler-generated auxiliary of a justified declaration.
#
# Invariant checked by check.sh on top of the diff:
# exactly ONE axiom line in this file, and it is LTLAcc.sha256.
INV|LTLAcc.acceptCons|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.acceptIncl|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.acceptIncl_complete|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.acceptIncl_sound|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Bytes|def|
INV|LTLAcc.ConsRec|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.consRec_base_false_eq|theorem|Classical.choice,Quot.sound,propext
INV|LTLAcc.consRec_base_false_eq.match_1|def|propext
INV|LTLAcc.consRec_base_false_eq._sparseCasesOn_1|def|propext
INV|LTLAcc.consRec_base_false_eq._sparseCasesOn_2|def|propext
INV|LTLAcc.consRec_base_true_eq|theorem|propext
INV|LTLAcc.consRec_base_true_eq.match_1|def|propext
INV|LTLAcc.consRecBinding|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.consRecBinding.match_1|def|
INV|LTLAcc.consRecBinding._proof_1_10|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_11|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_12|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_13|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_14|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_15|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_16|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_17|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_5|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_6|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_7|theorem|Quot.sound,propext
INV|LTLAcc.consRecBinding._proof_1_8|theorem|Quot.sound,propext
INV|LTLAcc.ConsRec.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec.induct|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec.match_1|def|
INV|LTLAcc.ConsRec._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec._unary.induct|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.ConsRec._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.ConsRec._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.domsep|theorem|
INV|LTLAcc.eq_dropLast_append_of_getLast?|theorem|propext
INV|LTLAcc.exists_singleton_of_length_one|theorem|Classical.choice,Quot.sound,propext
INV|LTLAcc.extractCons|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractCons_correct|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractCons_correct_paper|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractCons_correct_paper._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.extractCons_correct._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.extractCons_correct._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.extractCons.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractCons.match_1|def|
INV|LTLAcc.extractConsNode|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractConsNode.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractConsNode.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractConsNode.match_1|def|
INV|LTLAcc.extractConsNode._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractConsNode._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractConsNode._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.extractConsNode._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.extractCons_nonvacuous|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractCons_nonvacuous._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl_correct|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_4|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_5|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_6|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_7|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_8|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl_correct._proof_1_9|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl.match_1|def|
INV|LTLAcc.extractIncl_nonvacuous|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl_nonvacuous._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractIncl._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.extractIncl._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH_correct|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_10|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_4|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_5|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_6|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_7|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_8|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH_correct._proof_1_9|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH.induct|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH_nonvacuous|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH_nonvacuous._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH._unary.induct|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.extractMTH._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.extractMTH._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.fork_distinct|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.getD_drop|theorem|Quot.sound,propext
INV|LTLAcc.getD_drop._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.getD_take|theorem|Quot.sound,propext
INV|LTLAcc.getD_take._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.getD_take._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.Hash|def|
INV|LTLAcc.hleaf|def|LTLAcc.sha256
INV|LTLAcc.hnode|def|LTLAcc.sha256
INV|LTLAcc.hnode_preimage_inj|theorem|propext
INV|LTLAcc.incl_complete|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_5|theorem|Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_6|theorem|Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_7|theorem|Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_8|theorem|Quot.sound,propext
INV|LTLAcc.incl_complete._proof_1_9|theorem|Quot.sound,propext
INV|LTLAcc.instDecidableEqHash|def|
INV|LTLAcc.instDecidableEqHash._proof_1|theorem|
INV|LTLAcc.instInhabitedHash|def|propext
INV|LTLAcc.instInhabitedHash._proof_1|theorem|propext
INV|LTLAcc.IsCollision|def|LTLAcc.sha256
INV|LTLAcc.kbelow|def|Quot.sound,propext
INV|LTLAcc.kbelow.eq_1|theorem|Quot.sound,propext
INV|LTLAcc.kbelow.eq_def|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_eq_of_pow2_between|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_eq_of_pow2_between._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_eq_of_pow2_between._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_eq_of_pow2_between._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_eq_of_pow2_between._proof_1_4|theorem|Quot.sound,propext
INV|LTLAcc.kbelow.induct|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_lt|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_lt._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_lt._proof_1_4|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_lt._proof_1_5|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_pos|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_pow2|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_prefix_eq|theorem|Quot.sound,propext
INV|LTLAcc.kbelow_prefix_eq._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.kbelow._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.kbelow._unsafe_rec|def|
INV|LTLAcc.le_two_kbelow|theorem|Quot.sound,propext
INV|LTLAcc.le_two_kbelow._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.le_two_kbelow._proof_1_4|theorem|Quot.sound,propext
INV|LTLAcc.MTH|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.MTH.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.MTH.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.MTH._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.MTH._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.MTH_single|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.MTH_split|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.MTH_split._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.MTH_split._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.Path|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Path.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Path.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Path.induct|theorem|Quot.sound,propext
INV|LTLAcc.Path._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Path._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Path._unary.induct|theorem|Quot.sound,propext
INV|LTLAcc.Path._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.Path._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.pinAccept|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pinAccept_monotone|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pinAccept_monotone._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.pinAccept_monotone._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.pinExtract|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pinExtract.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pin_prefix_correct|theorem|Classical.choice,LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pin_prefix_correct._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.pin_prefix_nonvacuous|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.pin_prefix_nonvacuous._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.pow2_exp_unique|theorem|Quot.sound,propext
INV|LTLAcc.pow2_exp_unique._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.pow2_exp_unique._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.pow2_exp_unique._proof_1_3|theorem|Quot.sound,propext
INV|LTLAcc.Root|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root.eq_1|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root_left|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root_left._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.Root_left._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.Root.match_1|def|
INV|LTLAcc.Root_one|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root_one_cons|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root_right|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root_right._proof_1_1|theorem|Quot.sound,propext
INV|LTLAcc.Root_right._proof_1_2|theorem|Quot.sound,propext
INV|LTLAcc.Root._unary|def|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root._unary.eq_def|theorem|LTLAcc.sha256,Quot.sound,propext
INV|LTLAcc.Root._unary._proof_1|theorem|Quot.sound,propext
INV|LTLAcc.Root._unary._proof_2|theorem|Quot.sound,propext
INV|LTLAcc.sha256|axiom|LTLAcc.sha256
INV|LTLAcc.take_all|theorem|propext
INV|LTLAcc.take_append_drop|theorem|
INV|LTLAcc.take_drop_prefix|theorem|Classical.choice,Quot.sound,propext
INV|LTLAcc.take_take_le|theorem|Quot.sound,propext
INV|LTLAcc.take_take_le._proof_1_1|theorem|Quot.sound,propext
INV|_private.Proofs.Basic.0.LTLAcc.ConsRec.match_1.eq_1|theorem|
INV|_private.Proofs.Basic.0.LTLAcc.ConsRec.match_1.eq_2|theorem|
INV|_private.Proofs.Basic.0.LTLAcc.ConsRec.match_1.splitter|def|
INV|_private.Proofs.Basic.0.LTLAcc.Root.match_1.eq_1|theorem|
INV|_private.Proofs.Basic.0.LTLAcc.Root.match_1.eq_2|theorem|
INV|_private.Proofs.Basic.0.LTLAcc.Root.match_1.splitter|def|
INV|_private.Proofs.Basic.0.PSigma.casesOn._arg_pusher|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.consRecBinding.match_1.eq_1|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.consRecBinding.match_1.eq_2|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.consRecBinding.match_1.splitter|def|
INV|_private.Proofs.Binding3.0.LTLAcc.ConsRec.match_1.eq_1|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.ConsRec.match_1.eq_2|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.ConsRec.match_1.splitter|def|
INV|_private.Proofs.Binding3.0.LTLAcc.Root.match_1.eq_1|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.Root.match_1.eq_2|theorem|
INV|_private.Proofs.Binding3.0.LTLAcc.Root.match_1.splitter|def|
INV|_private.Proofs.Completeness.0.PSigma.casesOn._arg_pusher|theorem|
INV|_private.Proofs.Consistency.0.LTLAcc.extractConsNode.match_1.eq_1|theorem|
INV|_private.Proofs.Consistency.0.LTLAcc.extractConsNode.match_1.eq_2|theorem|
INV|_private.Proofs.Consistency.0.LTLAcc.extractConsNode.match_1.splitter|def|
INV|_private.Proofs.Consistency.0.PSigma.casesOn._arg_pusher|theorem|
INV|_private.Proofs.Descent.0.PSigma.casesOn._arg_pusher|theorem|
INV|_private.Proofs.Extract.0.LTLAcc.extractIncl.match_1.eq_1|theorem|
INV|_private.Proofs.Extract.0.LTLAcc.extractIncl.match_1.eq_2|theorem|
INV|_private.Proofs.Extract.0.LTLAcc.extractIncl.match_1.splitter|def|
INV|_private.Proofs.Extract.0.PSigma.casesOn._arg_pusher|theorem|

View file

@ -1,52 +0,0 @@
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# inventory_gate.sh — diff an observed environment inventory against the
# pinned allowlist. This is THE production coverage gate: check.sh Phase 3b
# calls it, and selftest_audit.sh exercises this exact script against
# injected evader declarations — the tested logic IS the shipping logic.
#
# Usage: inventory_gate.sh <observed-lean-output> <allowlist-file>
#
# Fail-closed in BOTH directions:
# UNCLASSIFIED — constant in the environment, absent from the allowlist
# (new/renamed decl, changed kind, or changed axiom cone)
# STALE — allowlist entry absent from the environment
# plus an output-integrity check: the INV-COUNT trailer emitted by
# Proofs/Inventory.lean must equal the number of INV lines actually seen,
# so a truncated or crashed run can never pass as an empty diff.
# ─────────────────────────────────────────────────────────────────────────────
set -uo pipefail
export LC_ALL=C # byte-order collation: sort/comm must agree with Lean's String order
obs_file="$1"; allow_file="$2"
OBS=$(grep '^INV|' "$obs_file" | sort -u)
N_OBS=$(printf '%s' "$OBS" | grep -c '^INV|' || true)
TRAILER=$(grep '^INV-COUNT|' "$obs_file" | tail -1 | cut -d'|' -f2)
if [ -z "$TRAILER" ] || [ "$TRAILER" != "$N_OBS" ]; then
echo " INVENTORY TRUNCATED: trailer=${TRAILER:-absent}, observed $N_OBS lines"
exit 1
fi
ALLOW=$(grep '^INV|' "$allow_file" | sort -u)
FAILGATE=0
UNCLASS=$(comm -23 <(printf '%s\n' "$OBS") <(printf '%s\n' "$ALLOW"))
STALE=$(comm -13 <(printf '%s\n' "$OBS") <(printf '%s\n' "$ALLOW"))
if [ -n "$UNCLASS" ]; then
printf '%s\n' "$UNCLASS" | sed 's/^/ UNCLASSIFIED (in environment, not allowlisted): /'
FAILGATE=1
fi
if [ -n "$STALE" ]; then
printf '%s\n' "$STALE" | sed 's/^/ STALE (allowlisted, not in environment): /'
FAILGATE=1
fi
# The corpus admits exactly one axiom, and it is the sanctioned boundary.
AXLINES=$(printf '%s\n' "$OBS" | grep '|axiom|' || true)
if [ "$AXLINES" != "INV|LTLAcc.sha256|axiom|LTLAcc.sha256" ]; then
echo " AXIOM SURFACE DRIFT: expected exactly LTLAcc.sha256, observed:"
printf '%s\n' "${AXLINES:- (none)}" | sed 's/^/ /'
FAILGATE=1
fi
[ "$FAILGATE" = 0 ] && echo " inventory gate: $N_OBS constants, environment == allowlist, single sanctioned axiom"
exit "$FAILGATE"

View file

@ -1,135 +0,0 @@
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# selftest_audit.sh — adversarial self-test of the audit gate.
#
# Review round 2 (GPT H1 / Claude NEW-1) demonstrated that the old
# source-regex coverage gate was evadable. This script proves the
# replacement is not, by ATTACKING THE SHIPPING LOGIC: every case copies
# the corpus to a scratch tree, injects a declaration the old gate could
# not see, recompiles through lean-guard, and asserts that the exact
# inventory_gate.sh used by check.sh Phase 3b FAILS with the expected
# diagnosis. The two unmanifested-module cases run the full check.sh.
#
# Cases (release condition 2 of the round-2 GPT review, plus two):
# 0 positive control: pristine tree must PASS (guards against a gate
# that fails everything — a vacuous self-test)
# 1 attributed theorem @[simp] theorem …
# 2 indented theorem (leading whitespace)
# 3 private theorem private theorem …
# 4 instance declaration instance … : Nonempty Nat
# 5 nested namespace collision LTLAcc.Hidden.MTH vs audited LTLAcc.MTH
# 6 smuggled axiom axiom rogue : True
# 7 deleted declaration STALE direction of the diff
# 8 unmanifested Proofs/ module full check.sh must die: DEAD FILE
# 9 unmanifested gen/ module full check.sh must die: DEAD FILE (gen)
#
# Run AFTER a green check.sh (needs compiled .oleans in the tree).
# All Lean work goes through lean-guard (memory-capped, single-flight).
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
source ~/aeneas-toolchain/env.sh
SRC="$(cd "$(dirname "$0")" && pwd)"
AENEAS_LEAN="$AENEAS_HOME/backends/lean"
CORES="${LEAN_MAX_CORES:-0-3}"
WORK=$(mktemp -d /tmp/acc-selftest-XXXX)
trap 'echo "(scratch tree kept for inspection: $WORK)"' ERR
echo "=== audit-gate self-test (scratch: $WORK) ==="
cp -a "$SRC" "$WORK/verification"
T="$WORK/verification"
cp "$T/Proofs/PinStore.lean" "$T/PinStore.pristine"
# Recompile the injected leaf module + the inventory, then run the gate.
# Returns the gate's exit code; gate output goes to $T/gate.out.
run_gate() {
cd "$AENEAS_LEAN"
lake env bash -c "
set -euo pipefail
cd '$T' && export LEAN_PATH=\"\$LEAN_PATH:$T/gen:$T\"
LEAN_TIMEOUT=600 LEAN_MAX_CORES=$CORES '$T/lean-guard' Proofs/PinStore.lean >/dev/null 2>&1
LEAN_TIMEOUT=600 LEAN_MAX_CORES=$CORES '$T/lean-guard' Proofs/Inventory.lean
" > "$T/inv.out" 2>&1 || { echo " (inventory compile failed — see $T/inv.out)"; return 99; }
"$T/inventory_gate.sh" "$T/inv.out" "$T/inventory-allowlist.txt" > "$T/gate.out" 2>&1
}
expect_fail() { # $1=case label $2=grep pattern expected in gate output
local rc=0; run_gate || rc=$?
if [ "$rc" = 0 ]; then
echo " ✗ $1: gate PASSED but must fail"; echo "SELF-TEST FAILED"; exit 1
elif [ "$rc" = 99 ]; then
echo " ✗ $1: injected code did not compile (case is vacuous)"; exit 1
elif ! grep -q "$2" "$T/gate.out"; then
echo " ✗ $1: gate failed but without expected diagnosis '$2':"
sed 's/^/ /' "$T/gate.out"; exit 1
fi
echo " ✓ $1: gate fails with $(grep -c "$2" "$T/gate.out") '$2' line(s)"
}
restore() { cp "$T/PinStore.pristine" "$T/Proofs/PinStore.lean"; }
# 0 — positive control
if run_gate; then echo " ✓ case 0 control: pristine tree passes the gate"; else
echo " ✗ case 0 control: pristine tree FAILED the gate:"; sed 's/^/ /' "$T/gate.out"; exit 1; fi
# 1 — attributed
restore; printf '\n@[simp] theorem smuggled_attr : 1 = 1 := rfl\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 1 attributed theorem" "UNCLASSIFIED.*smuggled_attr"
# 2 — indented
restore; printf '\n theorem smuggled_indent : 3 = 3 := rfl\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 2 indented theorem" "UNCLASSIFIED.*smuggled_indent"
# 3 — private
restore; printf '\nprivate theorem smuggled_private : 2 = 2 := rfl\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 3 private theorem" "UNCLASSIFIED.*_private.*smuggled_private"
# 4 — instance
restore; printf '\ninstance smuggledInst : Nonempty Nat := ⟨0⟩\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 4 instance" "UNCLASSIFIED.*smuggledInst"
# 5 — nested namespace reusing an audited basename
restore; printf '\nnamespace LTLAcc.Hidden\ntheorem MTH : 1 = 1 := rfl\nend LTLAcc.Hidden\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 5 namespace collision (LTLAcc.Hidden.MTH)" "UNCLASSIFIED.*LTLAcc\.Hidden\.MTH"
# 6 — smuggled axiom
restore; printf '\naxiom rogue : True\n' >> "$T/Proofs/PinStore.lean"
expect_fail "case 6 smuggled axiom" "AXIOM SURFACE DRIFT"
# 7 — deleted declaration (STALE direction)
restore
python3 - "$T/Proofs/PinStore.lean" <<'EOF'
import sys
p = sys.argv[1]; s = open(p).read()
# drop the trailing nonvacuity guard (a leaf theorem nothing imports),
# including its doc comment — an orphaned /-- ... -/ would not compile
i = s.rindex("/-- Permanent non-vacuity witness for pin_prefix_correct")
j = s.index("end LTLAcc", i)
open(p, "w").write(s[:i] + s[j:])
EOF
expect_fail "case 7 deleted declaration" "STALE.*pin_prefix_nonvacuous"
restore
rm -f "$T/PinStore.pristine"
# 8 — unmanifested Proofs/ module (full check.sh; dies in Phase 2)
printf '/- rogue -/\ntheorem rogue_thm : 1 = 1 := rfl\n' > "$T/Proofs/Rogue.lean"
if SKIP_FIDELITY=1 "$T/check.sh" > "$T/check8.out" 2>&1; then
echo " ✗ case 8: check.sh PASSED with unmanifested Proofs/Rogue.lean"; exit 1
fi
grep -q "DEAD FILE: Proofs/Rogue.lean" "$T/check8.out" || {
echo " ✗ case 8: check.sh failed without DEAD FILE diagnosis"; tail -5 "$T/check8.out"; exit 1; }
echo " ✓ case 8 unmanifested Proofs module: check.sh dies with DEAD FILE"
rm -f "$T/Proofs/Rogue.lean"
# 9 — unmanifested gen/ module (full check.sh; dies in Phase 2)
printf '/- rogue -/\ntheorem rogue_gen : 1 = 1 := rfl\n' > "$T/gen/LTLAcc/Rogue.lean"
if SKIP_FIDELITY=1 "$T/check.sh" > "$T/check9.out" 2>&1; then
echo " ✗ case 9: check.sh PASSED with unmanifested gen/LTLAcc/Rogue.lean"; exit 1
fi
grep -q "DEAD FILE (gen): gen/LTLAcc/Rogue.lean" "$T/check9.out" || {
echo " ✗ case 9: check.sh failed without DEAD FILE (gen) diagnosis"; tail -5 "$T/check9.out"; exit 1; }
echo " ✓ case 9 unmanifested gen module: check.sh dies with DEAD FILE (gen)"
rm -rf "$WORK"
trap - ERR
echo "=== SELF-TEST GREEN: 9 attack cases defeated + positive control ==="