mirror of
https://github.com/saymrwulf/ltl-accumulator-verified.git
synced 2026-09-04 20:03:44 +00:00
No theorem was wrong; every fix is spec-surface, audit-mechanism, docs, or harness coverage. Changes: LEAN (Claude F1, GPT M4): - acceptIncl: the consumer's inclusion accept (m<n ∧ Root=some r) is now a named object, not just a theorem hypothesis. Root alone accepts out-of-range m; acceptIncl pins the guard. - acceptIncl_complete / acceptIncl_sound: route Thm 1/2 through it. - extractCons_correct_paper: Thm 3 at the paper's exact quantifiers (n₀≤n₁, no separate 0<n₀; n₀=0 discharged since D₀=[]=take 0). SCRIPT (GPT H1/H2, Claude F3): - Phase 3b: fail-closed audit-surface COVERAGE — every named decl under Proofs/ and gen/ must be in CONES or a documented EXCLUDE (sha256, Bytes); anonymous gen instances count-pinned; every CONES key must be queried by AxiomCheck (no pin-but-never-check). Tested: an unclassified theorem now makes the button exit 1. - H2: distinct markers — LEAN GREEN always, ATTESTATION GREEN only when fidelity actually ran; SKIP/absent-pacta no longer emit the strong marker. Attestation gate keys on ATTESTATION GREEN. - Phase 0: orphan-olean guard (every Proofs/*.olean needs a sibling .lean); deleted 6 orphans; untracked all *.olean/.lake from git and gitignored them (root cause of the F3 tarball leak). HARNESS (Claude F1, GPT M3): - added out-of-range families (m≥n, m>n, n₀>n₁, n₀=0); re-pinned counts 230,271 / 230,016 (match the reviewer's independent RFC difftest exactly); narrowed 'exhaustive' wording to the tested domain. DOCS: README stale rows fixed (freeze banner no longer contradicts table); KNOWN-GAPS gap 3 reworded (general Lemma 2 = specializations), +gaps 9 (cost), 10 (pin init), 11 (acceptIncl resolved); STATEMENT-MAP +acceptIncl rows, +Lemma-2-general note, +constant-vs-property clarification for §10(i). Button: EXIT 0, coverage complete, ATTESTATION GREEN, 230,271/230,016. 56 pinned cones over an ENFORCED surface. LTL untouched (12, bcd15f9d). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
117 lines
4.6 KiB
Python
117 lines
4.6 KiB
Python
#!/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()
|