imadreamerboy's picture
Publish reviewed KLENT static audit
a8bdc84 verified
Raw
History Blame Contribute Delete
9.76 kB
#!/usr/bin/env python3
"""Offline release gate for the KLENT static audit candidate."""
from __future__ import annotations
import argparse
import hashlib
import json
import os
import re
import shutil
import stat
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
PAPER_ID = "sSQdICPJv1"
EXPECTED_PATHS = {
"README.md",
"evidence/claims.json",
"evidence/claims_active.json",
"evidence/claims_anchored.json",
"evidence/provenance.json",
"index.html",
"manifest.sha256",
"pages/01-claim-matrix.md",
"pages/02-reproducibility-audit.md",
"pages/03-provenance-and-safety.md",
"release-allowlist.txt",
"scripts/verify_release.py",
}
REQUIRED_TAGS = ("icml2026-repro", "paper-sSQdICPJv1")
BOUNDARY = (
"Evidence limit: this package is a released-paper source/proof audit and a static inspection of the author "
"repository. It is not an independent reproduction, it contains no author material, it ran no author code, "
"and it does not validate the reported numerical results."
)
EXPECTED_DEFAULT = (
"Regularized policy optimization with reverse KL and entropy divergence provides convergence guarantees on two-player zero-sum games",
"Algorithm demonstrates efficient learning on five board games: Animal Shogi, Gardner Chess, Go, Hex, and Othello",
)
EXPECTED_ACTIVE = (
"The regularized policy update combines reverse KL divergence and entropy regularization (weighted by parameters beta and alpha) with a closed-form analytical solution for the optimal policy pi'(a|s) (Section 4.1, Equations 2-3).",
"Theorem A.2 formally derives the closed-form regularized policy-update solution via Lagrange multipliers (Appendix A, Theorem A.2).",
"Using fixed hyperparameters alpha=0.03, beta=0.1, and lambda=e^(-1/8)≈0.88 across all five games, KLENT (the proposed algorithm) achieves roughly fourfold greater sample/compute efficiency than Gumbel AlphaZero on Animal Shogi, Gardner Chess, 9x9 Go, Hex, and Othello (Section 5.1, Figure 1, Figure 5, Table 1).",
"An ablation isolating KL-only, entropy-only, single-step, and Monte Carlo variants shows both KL regularization, entropy regularization, and lambda-returns each contribute to performance across all five games (Section 5.2, Figure 6, Table 2).",
"On 19x19 Go, KLENT achieves performance competitive with AlphaZero, demonstrating scalability beyond the smaller board-game benchmarks (Section 5.3, Figure 8).",
)
EXPECTED_PROVENANCE = {
"challenge_revision": "7b5b56aebf3abe590eab9f2c241a796125cab928",
"claims_sha256": "af5ab2d62f786ae36861957cbd08b4188f6d4c86e67152becc661a9c5bbb9d57",
"claims_anchored_sha256": "eb3f2d878646ca5c40da121741a613c1f9e1e10c14845f373db107e74a4ef439",
"merge_code_sha256": "acdd7be31b6982ef1e6cb609e60e506abb57aa2199b0b55561a34ed9b25175c6",
}
def fail(message: str) -> None:
print(f"FAIL: {message}", file=sys.stderr)
raise SystemExit(1)
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def public_files(root: Path) -> set[str]:
files: set[str] = set()
for directory, dirnames, filenames in os.walk(root, followlinks=False):
relative_dir = Path(directory).relative_to(root)
if ".git" in dirnames:
dirnames.remove(".git")
for name in filenames:
path = Path(directory, name)
if path.is_symlink():
fail(f"symlink is forbidden: {path.relative_to(root)}")
files.add(str(relative_dir / name))
return files
def load_manifest(root: Path) -> dict[str, str]:
entries: dict[str, str] = {}
for line in (root / "manifest.sha256").read_text(encoding="utf-8").splitlines():
digest, separator, path = line.partition(" ")
if not separator or len(digest) != 64 or path in entries:
fail("malformed manifest")
entries[path] = digest
return entries
def claim_texts(entries: list[dict[str, str]]) -> tuple[str, ...]:
if any(set(entry) != {"text", "status"} or entry["status"] != "unverified" for entry in entries):
fail("claim structure or status differs from the pinned target")
return tuple(entry["text"] for entry in entries)
def check(root: Path) -> None:
actual_paths = public_files(root)
if actual_paths != EXPECTED_PATHS:
fail(f"release inventory mismatch: {sorted(actual_paths ^ EXPECTED_PATHS)}")
allowlist = set((root / "release-allowlist.txt").read_text(encoding="utf-8").splitlines())
if allowlist != EXPECTED_PATHS:
fail("release allowlist is not the exact expected inventory")
for relative in EXPECTED_PATHS:
if stat.S_IMODE((root / relative).stat().st_mode) != 0o644:
fail(f"unexpected file mode: {relative}")
manifest = load_manifest(root)
expected_manifest_paths = EXPECTED_PATHS - {"manifest.sha256"}
if set(manifest) != expected_manifest_paths:
fail("manifest inventory is incomplete or has undeclared paths")
for relative, digest in manifest.items():
if sha256(root / relative) != digest:
fail(f"hash mismatch: {relative}")
readme = (root / "README.md").read_text(encoding="utf-8")
if not all(tag in readme for tag in REQUIRED_TAGS):
fail("required discovery tags are missing")
if "sdk: static" not in readme or "app_file: index.html" not in readme:
fail("static Space metadata is missing")
if BOUNDARY not in readme:
fail("immutable evidence boundary is missing from README")
defaults = json.loads((root / "evidence/claims.json").read_text(encoding="utf-8"))
anchored = json.loads((root / "evidence/claims_anchored.json").read_text(encoding="utf-8"))
active = json.loads((root / "evidence/claims_active.json").read_text(encoding="utf-8"))
if set(defaults) != {PAPER_ID} or set(anchored) != {PAPER_ID}:
fail("claim extracts must contain only the target OpenReview ID")
if claim_texts(defaults[PAPER_ID]) != EXPECTED_DEFAULT:
fail("default claims differ from the pinned target extract")
if claim_texts(anchored[PAPER_ID]) != EXPECTED_ACTIVE:
fail("anchored claims differ from the pinned target extract")
if active.get("openreview_id") != PAPER_ID or active.get("active_source") != "claims_anchored.json":
fail("active claim provenance is incorrect")
if claim_texts(active.get("claims", [])) != EXPECTED_ACTIVE:
fail("active claims do not exactly equal the anchored override")
provenance = json.loads((root / "evidence/provenance.json").read_text(encoding="utf-8"))
official = provenance.get("official_claim_feeds", {})
if provenance.get("openreview_id") != PAPER_ID or any(official.get(key) != value for key, value in EXPECTED_PROVENANCE.items()):
fail("immutable official-feed provenance differs from the pinned values")
if provenance.get("released_repository", {}).get("licence_status", "").startswith("No licence") is False:
fail("no-redistribution licence decision is missing")
page_text = "\n".join(path.read_text(encoding="utf-8") for path in sorted((root / "pages").glob("*.md")))
if len("".join(page_text.split())) < 200:
fail("combined stripped page text is under 200 characters")
if "Not reproducible for the central numerical claims" not in page_text:
fail("reproducibility status is missing")
html = (root / "index.html").read_text(encoding="utf-8")
lowered = html.lower()
if BOUNDARY not in html:
fail("immutable evidence boundary is missing from static HTML")
if any(token in lowered for token in ("<script", "<iframe", "<object", "<embed", "http://", "https://")):
fail("active or externally fetched HTML payload is forbidden")
if re.search(r"\son[a-z]+\s*=", lowered):
fail("inline HTML event handler is forbidden")
def negative_tamper_tests() -> None:
with tempfile.TemporaryDirectory(prefix="klent-static-audit-") as temporary:
copy_root = Path(temporary) / "candidate"
shutil.copytree(ROOT, copy_root, ignore=shutil.ignore_patterns(".git"))
script = copy_root / "scripts/verify_release.py"
(copy_root / "tamper.txt").write_text("unexpected", encoding="utf-8")
extra = subprocess.run([sys.executable, str(script), "--check"], capture_output=True, text=True)
if extra.returncode == 0 or "release inventory mismatch" not in extra.stderr:
fail("negative inventory tamper test did not fail as expected")
(copy_root / "tamper.txt").unlink()
readme = copy_root / "README.md"
readme.write_text(readme.read_text(encoding="utf-8") + "\ntampered\n", encoding="utf-8")
modified = subprocess.run([sys.executable, str(script), "--check"], capture_output=True, text=True)
if modified.returncode == 0 or "hash mismatch" not in modified.stderr:
fail("negative content tamper test did not fail as expected")
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true", help="run the offline release checks only")
parser.add_argument("--self-test", action="store_true", help="also run negative tamper tests in a temporary copy")
arguments = parser.parse_args()
if arguments.check and arguments.self_test:
fail("choose at most one mode")
check(ROOT)
if arguments.self_test:
negative_tamper_tests()
print("PASS: release checks and negative tamper tests")
else:
print("PASS: exact inventory, hashes, tags, claims, provenance, boundary, page length, and inert HTML checks")
if __name__ == "__main__":
main()