| """Offline release-gate verifier for this static source/proof crosswalk.""" |
|
|
| from __future__ import annotations |
|
|
| import hashlib |
| import json |
| import re |
| import shutil |
| import stat |
| import subprocess |
| import sys |
| import tempfile |
| from pathlib import Path |
|
|
|
|
| ALLOWLIST = { |
| ".gitignore", |
| "LICENSE", |
| "README.md", |
| "index.html", |
| "evidence/claims-active.json", |
| "evidence/provenance.json", |
| "manifest.json", |
| "pages/claims-crosswalk.md", |
| "scripts/verify.py", |
| } |
| REQUIRED_TAGS = {"icml2026-repro", "paper-u4klflLAX3"} |
| SOURCE_ONLY_LIMIT = ( |
| "does not report an empirical reproduction, proof verification, " |
| "author-code result, or independent execution" |
| ) |
| PAPER_ARXIV_ID = "2606.06287v1" |
| PAPER_SOURCE_URL = "https://arxiv.org/e-print/2606.06287v1" |
| PAPER_SOURCE_SHA256 = "e9cbf11dfdb3b18c59235dbc1c358f1b796940170b55ff2eeb15cdb17dc97a9c" |
|
|
|
|
| class ReleaseGateError(RuntimeError): |
| """A package failed a deterministic release-gate condition.""" |
|
|
|
|
| def fail(message: str) -> None: |
| raise ReleaseGateError(message) |
|
|
|
|
| def package_files(root: Path) -> list[Path]: |
| if (root / ".git").exists(): |
| result = subprocess.run( |
| ["git", "-C", str(root), "ls-files"], |
| check=True, |
| capture_output=True, |
| text=True, |
| ) |
| return [root / line for line in result.stdout.splitlines()] |
| return sorted( |
| path |
| for path in root.rglob("*") |
| if path.is_file() and ".git" not in path.relative_to(root).parts |
| ) |
|
|
|
|
| def read_text(path: Path) -> str: |
| try: |
| return path.read_text(encoding="utf-8") |
| except UnicodeDecodeError as error: |
| fail(f"non-text public file: {path}") |
| raise AssertionError from error |
|
|
|
|
| def sha256(path: Path) -> str: |
| return hashlib.sha256(path.read_bytes()).hexdigest() |
|
|
|
|
| def verify(root: Path) -> None: |
| root = root.resolve() |
| if not root.is_dir(): |
| fail(f"package root does not exist: {root}") |
|
|
| relative_files = {path.relative_to(root).as_posix() for path in package_files(root)} |
| unknown = sorted(relative_files - ALLOWLIST) |
| missing = sorted(ALLOWLIST - relative_files) |
| if unknown: |
| fail(f"public-safe allowlist violation: {unknown}") |
| if missing: |
| fail(f"required public file missing: {missing}") |
|
|
| for relative in relative_files: |
| path = root / relative |
| if path.stat().st_mode & stat.S_IXUSR: |
| fail(f"executable payload is not allowed: {relative}") |
|
|
| texts = {relative: read_text(root / relative) for relative in relative_files} |
| combined = "\n".join( |
| text for relative, text in texts.items() if relative != "scripts/verify.py" |
| ) |
| forbidden_content = { |
| "private path": r"/(?:Users|home)/[^/]+", |
| "credential-like token": r"(?:hf|sk|api)[_-][A-Za-z0-9]{16,}", |
| "unsafe HTML": r"<(?:script|iframe|object|embed)\b|\bon[a-z]+\s*=", |
| "overclaimed evidence": r"\b(?:we reproduced|reproduction result|proof verified|independently verified)\b", |
| } |
| for label, pattern in forbidden_content.items(): |
| if re.search(pattern, combined, flags=re.IGNORECASE): |
| fail(f"{label} detected") |
|
|
| readme = texts["README.md"] |
| for required in ("sdk: static", "app_file: index.html", *REQUIRED_TAGS): |
| if required not in readme: |
| fail(f"missing required Space metadata or tag: {required}") |
| if SOURCE_ONLY_LIMIT not in re.sub(r"\s+", " ", readme): |
| fail("required bounded source-only wording is absent") |
|
|
| pages = sorted((root / "pages").glob("**/*.md")) |
| if not pages: |
| fail("at least one pages/**/*.md file is required") |
| stripped_pages = re.sub(r"\s+", "", "".join(read_text(page) for page in pages)) |
| if len(stripped_pages) < 200: |
| fail("combined stripped page content is below 200 characters") |
|
|
| claims = json.loads(texts["evidence/claims-active.json"]) |
| if claims.get("openreview_id") != "u4klflLAX3" or len(claims.get("claims", [])) != 5: |
| fail("active claim set is incomplete or points to the wrong paper") |
| if claims.get("active_resolution") != "{**claims.json, **claims_anchored.json}; anchored entries overwrite legacy entries": |
| fail("active claim merge statement is missing or incorrect") |
|
|
| provenance = json.loads(texts["evidence/provenance.json"]) |
| paper = provenance.get("paper", {}) |
| if paper.get("arxiv_id") != PAPER_ARXIV_ID: |
| fail("paper source version pin is missing or incorrect") |
| if paper.get("source_url") != PAPER_SOURCE_URL: |
| fail("paper source URL is not the immutable versioned URL") |
| if paper.get("source_sha256") != PAPER_SOURCE_SHA256: |
| fail("paper source SHA-256 does not match the versioned source URL") |
| feeds = provenance.get("challenge_claim_feeds", {}) |
| if feeds.get("challenge_revision") != "7b5b56aebf3abe590eab9f2c241a796125cab928": |
| fail("challenge revision pin is missing or incorrect") |
| for feed in ("claims_json", "claims_anchored_json"): |
| pin = feeds.get(feed, {}) |
| if not re.fullmatch(r"[0-9a-f]{64}", pin.get("sha256", "")): |
| fail(f"{feed} SHA-256 pin is invalid") |
| if "/resolve/7b5b56aebf3abe590eab9f2c241a796125cab928/" not in pin.get("immutable_url", ""): |
| fail(f"{feed} immutable URL does not use the pinned challenge revision") |
| if "anchored entries overwrite legacy entries" not in feeds.get("active_merge", ""): |
| fail("judge merge rule is absent") |
|
|
| manifest = json.loads(texts["manifest.json"]) |
| if manifest.get("allowlist") != sorted(ALLOWLIST): |
| fail("manifest allowlist differs from verifier allowlist") |
| manifest_hashes = manifest.get("sha256", {}) |
| expected_hashed = sorted(ALLOWLIST - {"manifest.json"}) |
| if sorted(manifest_hashes) != expected_hashed: |
| fail("manifest hash coverage is incomplete") |
| for relative in expected_hashed: |
| if manifest_hashes[relative] != sha256(root / relative): |
| fail(f"hash integrity failure: {relative}") |
|
|
|
|
| def self_test(root: Path) -> None: |
| ignored_staging = shutil.ignore_patterns( |
| ".git", |
| ".source-screen", |
| "__pycache__", |
| "claims.json", |
| "claims_anchored.json", |
| "*.headers", |
| "arxiv-abstract.html", |
| "arxiv-source.tar", |
| "judge-app.py", |
| "judge-space-api.json", |
| "openreview-paper.pdf", |
| ) |
| with tempfile.TemporaryDirectory() as temporary: |
| copied = Path(temporary) / "candidate" |
| shutil.copytree(root, copied, ignore=ignored_staging) |
| readme = copied / "README.md" |
| readme.write_text(readme.read_text(encoding="utf-8").replace("paper-u4klflLAX3", "paper-missing"), encoding="utf-8") |
| try: |
| verify(copied) |
| except ReleaseGateError as error: |
| if "missing required Space metadata or tag" not in str(error): |
| fail(f"tag negative check failed for the wrong reason: {error}") |
| else: |
| fail("tag negative check was not rejected") |
|
|
| with tempfile.TemporaryDirectory() as temporary: |
| copied = Path(temporary) / "candidate" |
| shutil.copytree(root, copied, ignore=ignored_staging) |
| manifest_path = copied / "manifest.json" |
| manifest = json.loads(manifest_path.read_text(encoding="utf-8")) |
| manifest["sha256"]["README.md"] = "0" * 64 |
| manifest_path.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8") |
| try: |
| verify(copied) |
| except ReleaseGateError as error: |
| if "hash integrity failure: README.md" not in str(error): |
| fail(f"hash negative check failed for the wrong reason: {error}") |
| else: |
| fail("hash negative check was not rejected") |
|
|
| with tempfile.TemporaryDirectory() as temporary: |
| copied = Path(temporary) / "candidate" |
| shutil.copytree(root, copied, ignore=ignored_staging) |
| index = copied / "index.html" |
| index.write_text(index.read_text(encoding="utf-8") + "<script>bad()</script>\n", encoding="utf-8") |
| try: |
| verify(copied) |
| except ReleaseGateError as error: |
| if "unsafe HTML detected" not in str(error): |
| fail(f"unsafe-HTML negative check failed for the wrong reason: {error}") |
| else: |
| fail("unsafe-HTML negative check was not rejected") |
|
|
| with tempfile.TemporaryDirectory() as temporary: |
| copied = Path(temporary) / "candidate" |
| shutil.copytree(root, copied, ignore=ignored_staging) |
| provenance_path = copied / "evidence/provenance.json" |
| provenance = json.loads(provenance_path.read_text(encoding="utf-8")) |
| provenance["paper"]["source_sha256"] = "0" * 64 |
| provenance_path.write_text(json.dumps(provenance, indent=2) + "\n", encoding="utf-8") |
| try: |
| verify(copied) |
| except ReleaseGateError as error: |
| if "paper source SHA-256 does not match the versioned source URL" not in str(error): |
| fail(f"source-provenance negative check failed for the wrong reason: {error}") |
| else: |
| fail("source-provenance negative check was not rejected") |
|
|
|
|
| def main() -> int: |
| arguments = sys.argv[1:] |
| root = Path(arguments[0]) if arguments and not arguments[0].startswith("-") else Path(".") |
| self_test_requested = "--self-test" in arguments |
| try: |
| verify(root) |
| if self_test_requested: |
| self_test(root) |
| except ReleaseGateError as error: |
| print(f"FAIL: {error}") |
| return 1 |
| print("PASS: static source/proof crosswalk release gate") |
| if self_test_requested: |
| print("PASS: negative checks rejected missing tag, bad manifest hash, unsafe HTML, and source-provenance mismatch") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|