Download sample/tasks/inspect/pack_score.py from zero-trust-physics/zero-trust-physics-sample-group-1: direct link, hf CLI and curl.
- Browser
- Download file 4.26 kB
-
https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-sample-group-1/resolve/main/sample/tasks/inspect/pack_score.py
- Command line
-
hf download hf://datasets/zero-trust-physics/zero-trust-physics-sample-group-1/sample/tasks/inspect/pack_score.py
-
curl -L -o pack_score.py https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-sample-group-1/resolve/main/sample/tasks/inspect/pack_score.py
4.26 kB
| """Cross-platform release-pinned scorer wrapper for Zero-Trust Physics packs (macOS arm64, Linux amd64, Linux arm64, HTTP). | |
| python3 pack_score.py REPLIES --engine ENGINE --environments F [score.py's options] [--strict-binary] | |
| python3 pack_score.py --run run_cheat_suite.py [its options] [--strict-binary] | |
| Verifies that the target verifier answers MCP initialize as release 0.15.3 (matching reference.gateway_version and | |
| engine_tag) on kernel genesis_kernel_v0.13.1, while recording engine_binary_sha256_seen and engine_binary_is_reference on | |
| every score row. Pass --strict-binary to additionally require exact SHA-256 identity with reference.engine_binary_sha256. | |
| All deterministic recomputation, seal, budget, and grading invariants of score.py apply unchanged. | |
| Standard library only. Licence: Apache-2.0. | |
| """ | |
| import inspect | |
| import os | |
| import re | |
| import runpy | |
| import sys | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| if HERE not in sys.path: | |
| sys.path.insert(0, HERE) | |
| KERNEL = "genesis_kernel_v0.13.1" | |
| STRICT = False | |
| def _kernel_of(replay): | |
| """The kernel the verifier names: its serverInfo.description is the kernel's name (0.15.2), or one line that ends | |
| with it ("... Cards: genesis_kernel_v0.13.1", 0.15.3).""" | |
| server = getattr(getattr(replay, "verifier", None), "server", None) or {} | |
| found = re.findall(r"genesis_kernel_v[0-9][0-9.]*[0-9]", server.get("description") or "") | |
| return found[-1] if found else server.get("description") | |
| def install(strict=False): | |
| """Configure cross-platform release identity verification on score (idempotent). Returns the score module.""" | |
| global STRICT | |
| STRICT = bool(strict) | |
| import score | |
| if getattr(score, "_pack_engine_identity", False): | |
| return score | |
| original = score.engine_problem | |
| original_score = score.score | |
| def engine_problem(env, replay): | |
| ref = env.get("reference") or {} | |
| want = ref.get("engine_binary_sha256") | |
| seen = getattr(replay, "binary_sha256", None) | |
| if STRICT or not (seen and want and seen != want): | |
| return original(env, replay) | |
| # a different file: held to the release by what it says it is, every other rule as score.py's | |
| saved = replay.binary_sha256 | |
| replay.binary_sha256 = None | |
| try: | |
| problem = original(env, replay) | |
| finally: | |
| replay.binary_sha256 = saved | |
| if problem: | |
| return problem | |
| kernel = _kernel_of(replay) | |
| if kernel != KERNEL: | |
| return "the verifier reports kernel %s; release %s runs %s" % (kernel, replay.version, KERNEL) | |
| return None | |
| def scored(env, reply, replay, *args, **kwargs): | |
| row = original_score(env, reply, replay, *args, **kwargs) | |
| if isinstance(row, dict): | |
| want = (env.get("reference") or {}).get("engine_binary_sha256") | |
| seen = getattr(replay, "binary_sha256", None) | |
| row["engine_binary_sha256_seen"] = seen | |
| row["engine_binary_is_reference"] = None if not seen else (seen == want) | |
| return row | |
| # score.py may one day hold its own source-build rule; then it is left as it is | |
| if "strict" in inspect.getsource(original).lower(): | |
| return score | |
| score.engine_problem = engine_problem | |
| score.score = scored | |
| score._pack_engine_identity = True | |
| return score | |
| def main(): | |
| argv = sys.argv[1:] | |
| strict = "--strict-binary" in argv | |
| argv = [a for a in argv if a != "--strict-binary"] | |
| if argv[:1] == ["--run"]: | |
| if len(argv) < 2: | |
| sys.exit("give the program: --run run_cheat_suite.py [options]") | |
| program = argv[1] if os.path.isabs(argv[1]) or os.path.isfile(argv[1]) else os.path.join(HERE, argv[1]) | |
| folder = os.path.dirname(os.path.abspath(program)) | |
| if folder not in sys.path: | |
| sys.path.insert(0, folder) | |
| install(strict) | |
| # a program that does `from score import score` takes the replaced function, as the module now holds it | |
| sys.argv = [program] + argv[2:] | |
| runpy.run_path(program, run_name="__main__") | |
| return | |
| score = install(strict) | |
| sys.argv = [os.path.join(HERE, "score.py")] + argv | |
| score.main() | |
| if __name__ == "__main__": | |
| main() | |