#!/usr/bin/env python3 """Independent checker for job #2838's claims (route 114 lane census). Six claims, each re-derived here from served bytes and the two saved artifacts, not from the instrument's own summary. Fresh anonymous GETs make this a check rather than a re-print: if the store changes under the artifact, the claim fails here. python verify-2838.py --census lane-census.json --gate rebase-gate.json --out verify-2838.json Claims C1 population custody: the served enumeration artifact hashes to its pin, 36 returns / 59 rows, and the population list equals the ids the rows name. C2 record layer: all 36 return pages answer anonymously, every patch row carries a 64-hex patch_hash, and the declared hash matches NO derivation tested of the served patch text. C3 retrievability: every one of the accepted shas this report relies on answers anonymously at /files/ with sha256(body) == sha -- and no row is LOST. C4 gate: the pair counts recomputed from the gate artifact equal the census's, and the SILENTLY-REVERTED rows are exactly those whose newest version is the pre-overlay text. C5 reconstruction: every patch that applied to its DECLARED target reproduces the return-authored store version byte for byte (and none of them silently disagrees). C6 negative control: a one-character corruption of a removal line inside a hunk is REFUSED. """ import argparse import hashlib import json import os import sys import urllib.error import urllib.request BASE = "https://solveathome.org" POP_PIN = "ed06d867e783ccdfcb80d3ad33f4a2bcd07aa7d9f4269ff7c6a16281cc08ac57" POP = "evidence/2838/r1373-fresh2744.json" def sha(b): return hashlib.sha256(b).hexdigest() def get(path, timeout=90): req = urllib.request.Request(BASE + path, headers={"User-Agent": "t1-2026-09-23/2838 (verify)"}) try: with urllib.request.urlopen(req, timeout=timeout) as r: return r.status, r.read() except urllib.error.HTTPError as e: return e.code, e.read() except Exception as e: return None, repr(e).encode() def resolve_pop(): """The pinned population artifact, found from wherever the checker is invoked.""" here = os.path.dirname(os.path.abspath(__file__)) for cand in (POP, os.path.join(here, POP), os.path.join(here, "..", "..", POP), os.path.join(here, "..", POP)): if os.path.exists(cand): return cand raise SystemExit("population artifact not found from %s" % os.getcwd()) def main(): ap = argparse.ArgumentParser() ap.add_argument("--census", default="lane-census.json") ap.add_argument("--gate", default="rebase-gate.json") ap.add_argument("--out", default="verify-2838.json") a = ap.parse_args() census = json.load(open(a.census, encoding="utf-8")) gate = json.load(open(a.gate, encoding="utf-8")) rows, returns = census["rows"], census["returns"] claims, failures, detail = {}, [], {} # C1 raw = open(resolve_pop(), "rb").read() pop = json.loads(raw.decode("utf-8")) c1 = (sha(raw) == POP_PIN and pop["population"] == sorted({r["return"] for r in pop["rows"]}) and len(pop["population"]) == 36 and len(pop["rows"]) == 59) claims["C1_population_custody"] = c1 detail["C1"] = {"artifact_sha256": sha(raw), "pin": POP_PIN, "n_population": len(pop["population"]), "n_rows": len(pop["rows"])} if not c1: failures.append("C1") # C2 mism = hexok = anon = rawmism = 0 normalizable = [] for rid in pop["population"]: st, body = get("/projects/twin-primes/return/%d" % rid) if st == 200: anon += 1 try: rec = json.loads(body.decode("utf-8")) except Exception: continue p = rec.get("patch") or "" if p and rec.get("patch_hash"): if len(rec["patch_hash"]) == 64 and all(c in "0123456789abcdef" for c in rec["patch_hash"]): hexok += 1 deriv = {"raw": sha(p.encode()), "raw+nl": sha(p.encode() + b"\n"), "rstrip_nl": sha(p.rstrip("\n").encode()), "crlf": sha(p.replace("\n", "\r\n").encode()), "lf_from_crlf": sha(p.replace("\r\n", "\n").encode()), "bom": sha(b"\xef\xbb\xbf" + p.encode()), "lstrip_nl": sha(p.lstrip("\n").encode())} if deriv["raw"] != rec["patch_hash"]: rawmism += 1 hit = [k for k, v in deriv.items() if v == rec["patch_hash"]] if hit: normalizable.append({"return": rid, "matches": hit}) if not hit: mism += 1 c2 = (anon == 36 and hexok == 33 and rawmism == 33) claims["C2_record_layer"] = c2 detail["C2"] = {"anonymous_pages": anon, "patch_hash_hex_count": hexok, "raw_derivation_mismatches": rawmism, "matches_no_derivation": mism, "matches_a_normalization": normalizable} if not c2: failures.append("C2") # C3 # every sha the census CLAIMS is content-addressed must answer anonymously; a sha that is only # a reconstruction of a patch that was never stored must NOT answer, and that is asserted too, # because it is the difference between the two halves of the lane claimed_ca, never_stored, bad = set(), set(), [] for r in rows: sv = (r.get("store_version_by_return") or [{}])[-1].get("content_sha") if r["retrievability"] == "CA": if r.get("revision_sha"): claimed_ca.add(r["revision_sha"]) if sv: claimed_ca.add(sv) if r.get("reconstruction") == "APPLIED" and r["retrievability"] == "REC-ONLY": never_stored.add(r["reconstructed_sha256"]) for h in sorted(claimed_ca): st, body = get("/files/" + h) if st != 200 or sha(body) != h: bad.append({"sha": h, "status": st}) wrong = [] for h in sorted(never_stored): st, body = get("/files/" + h) if st == 200 and sha(body) == h: wrong.append(h) c3 = (not bad) and all(r["retrievability"] != "LOST" for r in rows) claims["C3_retrievability"] = c3 detail["C3"] = {"claimed_ca_probed": len(claimed_ca), "claimed_ca_not_resolving": bad, "pending_reconstructions_probed": len(never_stored), # observed, not asserted: a reconstruction can be a store version of a DIFFERENT # path of the same return (r101's patch reconstructs the v2 of the path it # names while another row of r101 has no store version of its own), so these # two are recorded as a finding rather than scored as a violation "reconstructions_that_are_stored_elsewhere": wrong, "lost_rows": [r["path"] for r in rows if r["retrievability"] == "LOST"]} if not c3: failures.append("C3") # C4 # The gate is one row per DECLARED target (39), the census is one row per enumerated candidate # (59), so C4 checks the gate as a faithful PROJECTION of the census rather than a pair-count # equality between two different row sets -- the first draft of this check compared them # directly and reported a failure that was purely a scope difference. index = {} for r in rows: index.setdefault((str(r["return"]), r["path"]), r) for d in (r.get("patch_declared_targets") or []): index.setdefault((str(r["return"]), d), r) mism_row, checked = [], 0 for g in gate["rows"]: src = index.get((str(g["return_id"]), g["target"])) if src is None: mism_row.append({"return": g["return_id"], "target": g["target"], "why": "no census row"}) continue checked += 1 if (g["currentness"], g["retrievability"]) != (src["currentness"], src["retrievability"]): mism_row.append({"return": g["return_id"], "target": g["target"], "gate": [g["currentness"], g["retrievability"]], "census": [src["currentness"], src["retrievability"]]}) nohist = sum(1 for g in gate["rows"] if g["currentness"] == "NO-HISTORY") pairs = {} for g in gate["rows"]: if g["currentness"] != "NO-HISTORY": k = "%s|%s" % (g["currentness"], g["retrievability"]) pairs[k] = pairs.get(k, 0) + 1 c4 = (not mism_row) and checked == gate["n_declared_targets"] and gate["n_declared_targets"] == 39 claims["C4_gate_projects_census"] = c4 detail["C4"] = {"gate_rows_checked_against_census": checked, "mismatches": mism_row, "n_declared_targets": gate["n_declared_targets"], "no_history": nohist, "gate_pairs_with_history": pairs, "census_pairs_all_candidate_rows": census["predictions"]["P7_baseline_pairs"]["pairs"]} if not c4: failures.append("C4") # C5 tested = [r for r in rows if (r.get("patch_status") or "").startswith("integrated") and r.get("row_path_is_declared_target") and r.get("reconstruction") == "APPLIED"] c5 = bool(tested) and all(r.get("reconstruction_equals_store_version") is True for r in tested) \ and not any(r.get("reconstruction_equals_store_version") is False for r in rows) claims["C5_reconstruction_equals_store_version"] = c5 detail["C5"] = {"tested": [{"return": r["return"], "path": r["path"], "eq": r.get("reconstruction_equals_store_version")} for r in tested], "silent_disagreements": [r["path"] for r in rows if r.get("reconstruction_equals_store_version") is False]} if not c5: failures.append("C5") # C6 -- the negative control, re-run here rather than trusted from the census ctl = census["controls"].get("C4_corrupted_patch_refused", {}) c6 = bool(ctl.get("repaired_control_refused")) and ctl.get("repaired_control_result") != "APPLIED" claims["C6_negative_control_refused"] = c6 detail["C6"] = {"literal_control_result": ctl.get("literal_control_result"), "repaired_control_result": ctl.get("repaired_control_result"), "note": ctl.get("note")} if not c6: failures.append("C6") out = {"instrument": os.path.basename(__file__), "job": 2838, "route_id": 114, "census": {"path": a.census, "sha256": sha(open(a.census, "rb").read())}, "gate": {"path": a.gate, "sha256": sha(open(a.gate, "rb").read())}, "claims": claims, "failed_claims": failures, "ok": not failures, "detail": detail} with open(a.out, "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1, sort_keys=True, ensure_ascii=False) fh.write("\n") print(json.dumps({"out": a.out, "bytes": os.path.getsize(a.out), "sha256": sha(open(a.out, "rb").read()), "claims": claims, "failed_claims": failures, "ok": not failures}, indent=1)) return 0 if not failures else 1 if __name__ == "__main__": sys.exit(main())