mcp-sandbox-authority-boundary-profile / scripts /verify_evidence_bindings.py
Michael Saleme
feat: bind synthetic evidence payloads to released receipts
45c2a8c unverified
Raw
History Blame
2.73 kB
#!/usr/bin/env python3
"""Verify that released synthetic observations resolve only to local evidence."""
from __future__ import annotations
import hashlib
import json
import sys
from pathlib import Path
ROOT = Path(sys.argv[1]).resolve() if len(sys.argv) == 2 else Path(__file__).resolve().parents[1]
INDEX_PATH = ROOT / "evidence" / "evidence-index-v0.2.0.json"
def digest(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def fail(message: str) -> None:
raise SystemExit(f"invalid evidence binding: {message}")
def local_path(relative: str) -> Path:
candidate = (ROOT / relative).resolve()
if not candidate.is_relative_to(ROOT) or not candidate.is_file():
fail(f"unreleased or external reference: {relative}")
return candidate
def main() -> None:
index = json.loads(INDEX_PATH.read_text())
run = json.loads((ROOT / "examples" / "synthetic-characterization.json").read_text())
if index["contract_version"] != "0.2.0" or index["classification"] != "synthetic-only":
fail("contract metadata")
configuration = index["target_configuration"]
config_path = local_path(configuration["path"])
if digest(config_path) != configuration["sha256"] or config_path.stat().st_size != configuration["bytes"]:
fail("target configuration manifest")
receipts = {receipt["case_id"]: receipt for receipt in index["receipts"]}
if len(receipts) != len(index["receipts"]):
fail("duplicate receipt case")
for observation in run["observations"]:
case_id = observation["case"]["id"]
receipt = receipts.get(case_id)
if receipt is None:
fail(f"missing receipt: {case_id}")
payload = local_path(receipt["path"])
if receipt["media_type"] != "application/json":
fail(f"media type: {case_id}")
if digest(payload) != receipt["sha256"] or payload.stat().st_size != receipt["bytes"]:
fail(f"payload bytes or digest: {case_id}")
payload_data = json.loads(payload.read_text())
if payload_data.get("classification") != "synthetic-only" or payload_data.get("case_id") != case_id:
fail(f"payload binding: {case_id}")
if observation["evidence"]["digest"] != receipt["sha256"]:
fail(f"observation evidence digest: {case_id}")
if observation["target_configuration_digest"] != configuration["sha256"]:
fail(f"observation target digest: {case_id}")
if set(receipts) != {item["case"]["id"] for item in run["observations"]}:
fail("unbound receipt")
print(f"valid: {len(receipts)} local synthetic evidence receipts and configuration manifest")
if __name__ == "__main__":
main()