#!/usr/bin/env python3 """ Standalone offline verification script for Job #9797 (Route #338 Window 30 / 31st Disjoint Campaign Window): Native C libsmhost.so Slot-Drain / MD5-Verification Micro-Benchmark (Gate G2), Sustained >= 35,000-GPU-Batch (~1.6068e14-Cand) async4_pinned8c_9772 Disjoint Self-Match Harvest, and 31-Window Cumulative Consolidation (> 3.783e15 Cands = > 13.44x 2^48 = > 84.01% — Crossing Five-Sixths (83.33%)! — of 2^52 across 825,000+ GPU batches). Run with: python3 -W error job9797-verify.py """ import hashlib import json import math import pathlib DIR = pathlib.Path(__file__).resolve().parent PRIOR_GPU_SEEDS = { 392500001, 395900001, 415800001, 418500001, 420700001, 977200001, 977300001, 42047729827841, 42120744271873, 42172283879425, 42215233552385, 42241003356161, 42288247996417, 42331197669377, 42382737276929, 42417097015297, 42485816492033, 42554535968769, 42627550412801, 42666205118465, 42709154791425, 42743514529793, 42769284333569, 42795054137345, 42829413875713, 42850888712193, 42889543417857, 42936788058113, 43001212567553, 43057047142401, 43108586749953, 43164421324801, 43194486095873, 43267500539905, 43323335114753, } PRIOR_CPU_SEEDS = { 395900002, 418500002, 977200002, 977300002, 42034844925954, 42047729827842, 42120744271874, 42172283879426, 42215233552386, 42241003356162, 42288247996418, 42331197669378, 42382737276930, 42417097015298, 42485816492034, 42554535968770, 42627550412802, 42666205118466, 42709154791426, 42743514529794, 42769284333570, 42795054137346, 42829413875714, 42850888712194, 42889543417858, 42936788058114, 43001212567554, 43057047142402, 43108586749954, 43164421324802, 43194486095874, 43267500539906, 43323335114754, } def splitmix64(x: int) -> int: x = (x + 0x9E3779B97F4A7C15) & 0xFFFFFFFFFFFFFFFF x = ((x ^ (x >> 30)) * 0xBF58476D1CE4E5B9) & 0xFFFFFFFFFFFFFFFF x = ((x ^ (x >> 27)) * 0x94D049BB133111EB) & 0xFFFFFFFFFFFFFFFF return (x ^ (x >> 31)) & 0xFFFFFFFFFFFFFFFF def reconstruct_cand(h: dict) -> str: seed = int(h["seed"]) batch = int(h["batch"]) i_idx = int(h["i"]) j_idx = int(h["j"]) if str(h["source"]).startswith("cpu_"): a = splitmix64(seed ^ ((batch * 2) & 0xFFFFFFFFFFFFFFFF)) b = splitmix64(seed ^ ((batch * 2 + 1) & 0xFFFFFFFFFFFFFFFF)) p16 = "".join("0123456789abcdef"[(a >> (4 * k)) & 0xF] for k in range(16)) p12 = "".join("0123456789abcdef"[(b >> (4 * k)) & 0xF] for k in range(12)) return f"{p16}{p12}{j_idx:04x}" base24 = hashlib.sha256(f"sm2|{seed}|{batch}".encode("ascii")).hexdigest()[:24] return f"{base24}{i_idx:04x}{j_idx:04x}" def count_mirror_matches(word: str) -> tuple[int, str, int]: assert len(word) == 32, f"Expected 32-char word, got len={len(word)}" assert all(c in "0123456789abcdef" for c in word), f"Non-lowercase-hex word: {word}" digest_hex = hashlib.md5(word.encode("ascii")).hexdigest() matches = 0 for a_ch, b_ch in zip(word, digest_hex): if a_ch == b_ch: matches += 1 else: break mask = (1 << matches) - 1 return matches, digest_hex, mask def poisson_cdf(k: int, lam: float) -> float: if lam <= 0.0: return 1.0 if k < 0: return 0.0 mode = int(lam) log_mode_term = -lam + mode * math.log(lam) - math.lgamma(mode + 1.0) total = 0.0 start_down = min(k, mode) log_t = -lam + start_down * math.log(lam) - math.lgamma(start_down + 1.0) if start_down > 0 else -lam for i in range(start_down, -1, -1): val = math.exp(log_t) if log_t > -745.0 else 0.0 total += val if val < 1e-17 * total and i < start_down - 10: break if i > 0: log_t += math.log(i / lam) if k > mode: log_t = log_mode_term for i in range(mode + 1, k + 1): log_t += math.log(lam / i) val = math.exp(log_t) if log_t > -745.0 else 0.0 total += val if val < 1e-17 * total and i > mode + 10: break return min(1.0, max(0.0, total)) def garwood_poisson_ci95(obs: int, expected: float) -> dict: alpha = 0.05 if obs == 0: lam_lo = 0.0 else: target_lo = 1.0 - alpha / 2.0 lo = 0.0 hi = max(1.0, float(obs) * 2.0) while poisson_cdf(obs - 1, hi) > target_lo: hi *= 2.0 for _ in range(80): mid = 0.5 * (lo + hi) if poisson_cdf(obs - 1, mid) > target_lo: lo = mid else: hi = mid lam_lo = 0.5 * (lo + hi) target_hi = alpha / 2.0 lo = float(obs) hi = max(4.0, float(obs) * 2.0 + 4.0) while poisson_cdf(obs, hi) > target_hi: hi *= 2.0 for _ in range(80): mid = 0.5 * (lo + hi) if poisson_cdf(obs, mid) > target_hi: lo = mid else: hi = mid lam_hi = 0.5 * (lo + hi) return { "lambda_ci95_lo": round(lam_lo, 4), "lambda_ci95_hi": round(lam_hi, 4), "ratio_vs_null_ci95_lo": round(lam_lo / expected, 4) if expected > 0 else 0.0, "ratio_vs_null_ci95_hi": round(lam_hi / expected, 4) if expected > 0 else 0.0, } def main() -> None: required_files = [ "job9797-prereg.md", "job9797-selfmatch_nvtd_bcast.c", "job9797-harvest.py", "job9797-search_results.json", "job9797-submissions.json", ] for fname in required_files: p = DIR / fname assert p.exists() and p.stat().st_size > 0, f"Missing or empty artifact: {fname}" harvest = json.loads((DIR / "job9797-search_results.json").read_text(encoding="utf-8")) subs = json.loads((DIR / "job9797-submissions.json").read_text(encoding="utf-8")) assert harvest["job_id"] == 9797 assert harvest["route_id"] == 338 assert harvest["predecessor_return_ids"] == [4879, 4884, 4892, 4898, 4907, 4914, 4924, 4933, 4944, 4955, 4973, 4991, 5004, 5012, 5020, 5026, 5031, 5036, 5040, 5044, 5050, 5058, 5066, 5074, 5078, 5085, 5087, 5095, 5102, 5108] g1 = harvest["gate_g1"] g1_word = "54db1011d76dc70a0a9df3ff3e0b390f" g1_score, g1_md5, g1_mask = count_mirror_matches(g1_word) assert g1_score == 12 and g1_mask == 0xFFF assert g1["fixture"] == g1_word and g1["found"] is True and g1["score"] == 12 and g1["digest"] == g1_md5 assert ( g1["sass_physical_registers"] == 38 and g1["sass_unpadded_insts"] == 566 and g1["sass_lop3_lut"] == 112 and g1["sass_shf_l"] == 115 and g1["sass_iadd3"] == 158 and g1["c_setup_prm_16batch_byte_exact"] is True and g1["c_verify_gpu_hits_fixture_exact"] is True ) g2 = harvest["gate_g2"] assert g2["batches_tested"] == 16 assert g2["c_vs_py_16batch_hit_parity"] is True assert g2["host_verify_fraction_of_gpu_batch_pct"] < 0.05 camp = harvest["campaign"] gpu_seed = camp["gpu"]["seed"] cpu_seed = camp["cpu"]["seed"] assert gpu_seed == ((9797 << 32) | 1) == 42077794598913 assert cpu_seed == ((9797 << 32) | 2) == 42077794598914 assert gpu_seed != cpu_seed assert gpu_seed not in PRIOR_GPU_SEEDS and gpu_seed not in PRIOR_CPU_SEEDS assert cpu_seed not in PRIOR_GPU_SEEDS and cpu_seed not in PRIOR_CPU_SEEDS for sp in PRIOR_GPU_SEEDS: assert (gpu_seed ^ sp) >= (1 << 32), f"GPU seed XOR delta < 2^32 vs {sp}" for sp in PRIOR_CPU_SEEDS: assert (cpu_seed ^ sp) >= (1 << 32), f"CPU seed XOR delta < 2^32 vs {sp}" assert ((cpu_seed ^ sp) >> 1) >= (1 << 32), f"CPU seed XOR-shift delta < 2^32 vs {sp}" gpu_total_batches = camp["gpu"]["total_batches"] assert gpu_total_batches >= 35000 assert camp["gpu"]["candidates"] == gpu_total_batches * (1 << 32) assert camp["cpu"]["candidates"] == camp["cpu"]["batches"] * 65536 assert camp["total_candidates"] == camp["gpu"]["candidates"] + camp["cpu"]["candidates"] assert camp["total_candidates"] >= 1.60e14 assert camp["combined_effective_ghs"] >= 60.0 disp = harvest["gpu_batch_dispersion"] n8_all = disp["batch_n8_all"] assert len(n8_all) == gpu_total_batches and disp["n8_num_batches"] == gpu_total_batches assert sum(n8_all) == disp["n8_total"] == camp["gpu"]["cum_counts"]["8"] mean_n8 = sum(n8_all) / len(n8_all) var_n8 = sum((x - mean_n8) ** 2 for x in n8_all) / (len(n8_all) - 1) d8 = var_n8 / mean_n8 assert abs(round(mean_n8, 6) - disp["n8_mean"]) <= 1e-6 assert abs(round(var_n8, 6) - disp["n8_var"]) <= 1e-6 assert abs(round(d8, 6) - disp["n8_dispersion_index"]) <= 1e-6 assert 0.96 <= disp["n8_dispersion_index"] <= 1.04, f"Dispersion outside [0.96, 1.04]: {disp['n8_dispersion_index']}" hist_check = {} for x in n8_all: hist_check[str(x)] = hist_check.get(str(x), 0) + 1 assert hist_check == disp["batch_n8_histogram"] assert sum(w["win_batches"] for w in harvest["window_1000_stats"]) == gpu_total_batches assert sum(w["win_n8"] for w in harvest["window_1000_stats"]) == disp["n8_total"] for k_lvl in range(8, 15): ks = str(k_lvl) na = harvest["null_model_audit"][ks] obs = camp["gpu"]["cum_counts"][ks] + camp["cpu"]["cum_counts"][ks] assert na["observed"] == obs p_k = 16.0 ** (-k_lvl) exp_k = camp["total_candidates"] * p_k sd_k = math.sqrt(exp_k * (1.0 - p_k)) z_k = (obs - exp_k) / sd_k if sd_k > 0 else 0.0 ci = garwood_poisson_ci95(obs, exp_k) assert abs(round(exp_k, 4) - na["expected"]) <= 1e-4 assert abs(round(sd_k, 4) - na["sd"]) <= 1e-4 assert abs(round(z_k, 4) - na["z_score"]) <= 1e-4 assert abs(ci["lambda_ci95_lo"] - na["lambda_ci95_lo"]) <= 1e-3 assert abs(ci["lambda_ci95_hi"] - na["lambda_ci95_hi"]) <= 1e-3 if k_lvl <= 12: assert abs(z_k) < 3.0 elif k_lvl == 13: assert obs == 1 wcum = harvest["thirty_one_window_cumulative"] assert wcum["windows_completed"] == 31 assert wcum["window0_job9772_candidates"] == 59685436653568 assert wcum["window1_job9787_candidates"] == 161415242448896 assert wcum["window2_job9790_candidates"] == 114780032466944 assert wcum["window3_job9807_candidates"] == 117085914005504 assert wcum["window4_job9819_candidates"] == 117086399496192 assert wcum["window5_job9829_candidates"] == 117070809268224 assert wcum["window6_job9835_candidates"] == 117072636936192 assert wcum["window7_job9846_candidates"] == 117077942730752 assert wcum["window8_job9856_candidates"] == 121667824123904 assert wcum["window9_job9868_candidates"] == 121660700098560 assert wcum["window10_job9876_candidates"] == 121663982141440 assert wcum["window11_job9892_candidates"] == 126255136505856 assert wcum["window12_job9908_candidates"] == 121661937418240 assert wcum["window13_job9925_candidates"] == 121659848654848 assert wcum["window14_job9934_candidates"] == 121665264549888 assert wcum["window15_job9944_candidates"] == 121634275983360 assert wcum["window16_job9952_candidates"] == 121690322370560 assert wcum["window17_job9958_candidates"] == 121660765110272 assert wcum["window18_job9964_candidates"] == 121655590387712 assert wcum["window19_job9972_candidates"] == 121647247917056 assert wcum["window20_job9977_candidates"] == 121657723191296 assert wcum["window21_job9986_candidates"] == 121655551590400 assert wcum["window22_job9997_candidates"] == 121663851069440 assert wcum["window23_job10012_candidates"] == 121658274742272 assert wcum["window24_job10025_candidates"] == 128548552572928 assert wcum["window25_job10037_candidates"] == 130844052160512 assert wcum["window26_job10050_candidates"] == 121655914397696 assert wcum["window27_job10057_candidates"] == 126254475902976 assert wcum["window28_job10074_candidates"] == 121671319027712 assert wcum["window29_job10087_candidates"] == 121660485140480 assert wcum["window30_job9797_candidates"] == camp["total_candidates"] assert wcum["route338_direct_candidates"] == 59685436653568 + 161415242448896 + camp["total_candidates"] assert wcum["route338_direct_candidates"] >= 381000000000000 assert wcum["cumulative_candidates"] == 3623067509063680 + camp["total_candidates"] assert wcum["cumulative_candidates"] >= 3783000000000000 assert wcum["cumulative_gpu_batches"] == 790000 + gpu_total_batches assert wcum["cumulative_gpu_batches"] >= 825000 assert wcum["cross_window_duplicate_ge9_count"] == 0 assert wcum["fraction_of_2pow48_score12_expectation"] >= 13.44 assert wcum["fraction_of_2pow52_score13_expectation"] >= 0.8401 assert 0.97 <= wcum["cumulative_gpu_dispersion"]["n8_dispersion_index"] <= 1.03 for k_lvl in range(8, 15): ks = str(k_lvl) cna = wcum["cumulative_null_model_audit"][ks] assert abs(cna["z_score"]) < 3.0 hits_ge9 = harvest["hits_ge9"] assert len(hits_ge9) == harvest["null_model_audit"]["9"]["observed"] and len(hits_ge9) > 0 seen_words = set() ge10_words = set() ge12_words = set() for h in hits_ge9: w = h["candidate"] assert w not in seen_words, f"Duplicate witness candidate: {w}" seen_words.add(w) expected_w = reconstruct_cand(h) assert w == expected_w, f"Candidate reconstruction mismatch for {w} vs {expected_w}" sc, md5_hex, _ = count_mirror_matches(w) assert sc == h["score"], f"Score mismatch for {w}: computed={sc} vs record={h['score']}" assert md5_hex == h["md5"], f"MD5 mismatch for {w}: computed={md5_hex} vs record={h['md5']}" if sc >= 10: ge10_words.add(w) if sc >= 12: ge12_words.add(w) assert len(ge10_words) >= 130, f"Expected >= 130 local score>=10 witnesses, got {len(ge10_words)}" for h in harvest["sample_hits_eq8"]: w = h["candidate"] assert w == reconstruct_cand(h) sc, md5_hex, _ = count_mirror_matches(w) assert sc == 8 and md5_hex == h["md5"] sub_list = subs["submissions"] assert len(sub_list) == len(ge12_words), ( f"Expected {len(ge12_words)} live submissions for score>=12 hits, got {len(sub_list)}" ) for s in sub_list: cand_w = s["candidate"] assert cand_w in ge12_words, f"Submitted candidate {cand_w} not in verified score>=12 set" assert s["submission_id"] is not None and int(s["submission_id"]) > 0, f"Invalid submission_id: {s}" assert s.get("verified") is True or s.get("status") in ("verified", "accepted"), f"Unexpected submission status: {s}" assert s.get("duplicate") is False, f"Unexpected duplicate submission: {s}" assert int(s["score"]) >= 12, f"Submission score < 12: {s}" best_score = harvest["verification"]["best_hit"]["score"] assert best_score >= 10 print( f"VERIFY_OK job_id=9797 route_id=338 manifest=5/5 cands={camp['total_candidates']} " f"cum_cands={wcum['cumulative_candidates']} ghs={camp['combined_effective_ghs']:.4f} " f"D8={disp['n8_dispersion_index']:.4f} cum_D8={wcum['cumulative_gpu_dispersion']['n8_dispersion_index']:.4f} " f"verified_ge9={len(hits_ge9)} submissions={len(sub_list)} best_score={best_score}" ) if __name__ == "__main__": main()