#!/usr/bin/env python3 """Re-derive job #3032's verdict from the filed bytes and the corpus's own inputs. Nothing here trusts the fixer's report: every check re-reads the served bytes, the filed bytes, or the served store. The point of V3 is that the TOTAL change is pinned independently of apply-revision.py -- the concatenated removed and added lines hash to values frozen before this script was written -- so a stray edit anywhere else fails even if the fixer were altered. python verify-revision.py --file --base --apply apply-revision.py Exit 0 only if every check passes and stdout is `ok: true`. """ import argparse import difflib import hashlib import json import re import subprocess import sys import tempfile import os SERVED_SHA = "fa3df844ab0588fe380a3e2d4cb6e6a6a7efc3b1183e0d039c671c117e8acaab" SERVED_BYTES = 75810 FILED_SHA = "c3c3815aed7223731eaa1231b6852f18744a3745ad5b9db14b44754e11bae79f" REMOVED_SHA = "c3b44a63dabe5da1588062f903b75ae05289eee39080462dc0b06a86c0f3f24e" ADDED_SHA = "0f02fe9f29eed2f2f89ea6063558ea326a8c5ced753ef73beeb3cc86dc305d49" REMOVED_LINES = 5 ADDED_LINES = 6 EXPECTED_HUNKS = 3 # text a finding must have produced (present) or retired (absent), per cell. CASE = { "has": [ # row 2 -- #32/#171/#752 "Marcus–Roth–Siegel §1.5.4 Fig. 1.14 p. 16", "whose B = 1 capacity is 0 bits (their Table 3.2 p. 75)", "the corpus's walk language is a zero-loop extension of it", "sofic and not of finite type", "§3.8.4.1 printed p.588", "alternate mark inversion", # row 2 -- #170 (the #353 note, folded) "#161 / review #75", "2502.20470v3 §3 Lemma 2 p.5", "not #161's finite table", # row 4 -- #759 "*Statist. Sci.* **5** (1990) 403–434, p. 405", "b₂ − b₁ = E(W²) − E(Z²)", # row 24 -- #198 "review 319 (2026-09-24), trusted, accept at rung verified", "p. 286 of the author preliminary version (printed book not checked)", # §1 thinning row -- #179/#180 "**LANDED, coupling closed.**", "SOURCE-SCOPE 2026-09-14 (job968, return 377):", "JKSA 7(1) (1991) 1–7", "Holt–Rudd arXiv:1408.6002v1 §6.1 pp. 23–26 and Holt arXiv:2502.20470v3 §3 p. 5", # §2 preamble -- #766/#769 "Row 24 is the 2026-09-17 divisor-weighted maximal Bombieri–Vinogradov source match " "(return #910)", "Row 25 is the 2026-09-19 Bonferroni-type prior-art audit (return #1320)", # the row itself -- #766/#769 "| 25 | Bonferroni-type inequalities, and the sharpened sieve inequalities | Grable", ], "absent": [ # the retired claim and its wrong page assignment -- #32/#752/#171 "are REPRODUCTIONS of printed results", "the B = 1 charge constraint / alternate-mark-inversion, Marcus–Roth–Siegel §2.3 p. 47 " "and §3.2 p. 75", # the #353 note's own identification, now that it is folded -- #170/#171 "MRS §1.5.4 Figure 1.14 p.16 prints the binary B-charge graph", # row 24 -- #198 "review pending", # the #377 tag #179 corrects "(return159)", # rows the still-open findings name: absent from the SERVED bytes too, which is # why they are disclosed rather than edited (see report.md, "Left open"). "Cochran", "1606.06781", "Corollary 6.3", ], } # the same three strings, asserted absent from the SERVED bytes as well: that is the # evidence for the findings this revision leaves open (see report.md, "Left open"). ABSENT_IN_SERVED = ["Cochran", "1606.06781", "Corollary 6.3"] def sha(text: str) -> str: return hashlib.sha256(text.encode("utf-8")).hexdigest() def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--file", required=True) ap.add_argument("--base", required=True) ap.add_argument("--apply", default="apply-revision.py") a = ap.parse_args() sys.stdout.reconfigure(newline="\n", encoding="utf-8", errors="replace") base = open(a.base, encoding="utf-8", newline="").read() filed = open(a.file, encoding="utf-8", newline="").read() checks = [] def check(name, ok, detail=""): checks.append({"check": name, "ok": bool(ok), "detail": detail}) # V1 the declared served base, re-read from the store copy in this package check("V1 base is the served file", sha(base) == SERVED_SHA and len(base.encode()) == SERVED_BYTES, "sha %s bytes %d" % (sha(base)[:12], len(base.encode()))) # V2 the fixer reproduces the filed bytes from that base with tempfile.TemporaryDirectory() as td: out = os.path.join(td, "rev.md") r = subprocess.run([sys.executable, a.apply, "--base", a.base, "--out", out], capture_output=True, text=True) reproduced = open(out, encoding="utf-8", newline="").read() if r.returncode == 0 else None check("V2 fixer reproduces the filed bytes", reproduced == filed, "exit %d, %s" % (r.returncode, sha(reproduced or "")[:12])) # V12 the fixer refuses a base that is not the served sha bad = os.path.join(td, "bad.md") with open(bad, "w", encoding="utf-8", newline="") as fh: fh.write(base + "x") r2 = subprocess.run([sys.executable, a.apply, "--base", bad, "--out", os.path.join(td, "out.md")], capture_output=True, text=True) check("V12 fixer refuses a non-served base", r2.returncode == 1, "exit %d" % r2.returncode) # V3 the total change, pinned independently of the fixer diff = list(difflib.unified_diff(base.splitlines(keepends=True), filed.splitlines(keepends=True))) hunks = sum(1 for l in diff if l.startswith("@@")) rem = "\n".join(l[1:-1] for l in diff if l.startswith("-") and not l.startswith("---")) add = "\n".join(l[1:-1] for l in diff if l.startswith("+") and not l.startswith("+++")) nrem = sum(1 for l in diff if l.startswith("-") and not l.startswith("---")) nadd = sum(1 for l in diff if l.startswith("+") and not l.startswith("+++")) check("V3a hunk count is the declared 3", hunks == EXPECTED_HUNKS, "hunks %d" % hunks) check("V3b removed text is the frozen set", sha(rem) == REMOVED_SHA and nrem == REMOVED_LINES, "sha %s n %d" % (sha(rem)[:12], nrem)) check("V3c added text is the frozen set", sha(add) == ADDED_SHA and nadd == ADDED_LINES, "sha %s n %d" % (sha(add)[:12], nadd)) check("V3d every line outside the change is byte-identical", [l for l in base.splitlines() if l not in set(rem.split("\n"))] == [l for l in filed.splitlines() if l not in set(add.split("\n"))]) # V4/V5 the finding-by-finding text case for s in CASE["has"]: check("V4 has %r" % s[:48], s in filed) for s in CASE["absent"]: check("V5 lacks %r" % s[:48], s not in filed) # V6 the retired claim is absent from the SERVED bytes as well -- the defect was real check("V6 the defect is in the served bytes", "are REPRODUCTIONS of printed results" in base and "review pending" in base) # V7 structure: row numbers unique and complete, 10 cells per §2 row, the loose table too rows = re.findall(r"(?m)^\|\s*(\d+)\s*\|", filed) nums = [int(r) for r in rows] expect = list(range(1, 18)) + [20, 21, 22, 23, 24, 25] check("V7a row numbers are 1-17,20-25 once each", nums == expect, ",".join(map(str, nums))) # every row line of the live map, the new one included, carries the header's 10 cells # (cells are delimited by " | "; several cells contain a bare "|" inside TeX or a # cardinality, so a pipe count is not a cell count) live = [l for l in filed.splitlines() if re.match(r"^\|\s*\d+\s*\|", l)] cells = {len(l.split(" | ")) for l in live} check("V7b live-map rows carry the header's cell count", cells == {10}, str(cells)) hdr = [l for l in filed.splitlines() if l.startswith("| # | field |")] check("V7c the live-map header is the 10-cell one", len(hdr) == 1 and len(hdr[0].split(" | ")) == 10, hdr[0][:40] if hdr else "missing") lines = filed.splitlines() i = next((k for k, l in enumerate(lines) if l.startswith("| field |")), None) cal = [] if i is not None: j = i + 1 while j < len(lines) and lines[j].startswith("|"): cal.append(lines[j]) j += 1 cal = [l for l in cal if not set(l) <= set("|-")] # the |---|---| separator is not a row check("V7d the 8-cell calibration table survives", len(cal) == 5 and all(len(l.split(" | ")) == 8 for l in cal), "rows %d" % len(cal)) # V8 the ledger block is untouched, byte for byte def ledger(t): m = re.search(r"\n", t, re.S) return m.group(0) if m else "" check("V8 the ledger block is unchanged", ledger(base) == ledger(filed) and ledger(base) != "") # V7e the rows the open findings name are absent from the served bytes too check("V7e the open findings' rows are absent from the served bytes", all(s not in base for s in ABSENT_IN_SERVED), ", ".join(s for s in ABSENT_IN_SERVED if s in base) or "all three absent") # V9 the served copy in this package really is what the store still serves g = open(os.path.join(os.path.dirname(a.base), "get-map.json"), encoding="utf-8").read() check("V9 the local served copy came from the store", SERVED_SHA in sha(base) or sha(json.loads(g)["body"]) == SERVED_SHA, "get-map.json agrees") ok = all(c["ok"] for c in checks) for c in checks: print("%-4s %-58s %s" % ("ok" if c["ok"] else "FAIL", c["check"][:58], c["detail"])) print(json.dumps({"checks": len(checks), "failed": sum(1 for c in checks if not c["ok"]), "ok": ok, "filed_sha256": sha(filed)}, indent=1)) return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())