#!/usr/bin/env bash # Offline cryptographic & functional verification of the Foundry Flagship public preview. # Verifies SHA384SUMS, checks the specimen-allowlisted preview verifier, replays both # dev-00 reference episodes to their exact 96-hex SHA-384 suite seals, and confirms # non-allowlisted specimens and batch-grade sweeps are refused by name. set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" cd "$HERE" echo "[1/4] Verifying SHA384SUMS across all repository files..." python3 -I - <<'PY' import hashlib, os bad = 0 checked = 0 for ln in open("SHA384SUMS", encoding="utf-8"): s = ln.strip() if not s: continue exp, rel = s.split(" ", 1) h = hashlib.sha384() with open(rel, "rb") as fh: for ch in iter(lambda: fh.read(1 << 20), b""): h.update(ch) if h.hexdigest() != exp: print(f"MISMATCH: {rel}") bad += 1 checked += 1 assert bad == 0, f"{bad} hash mismatches" print(f" OK: {checked}/{checked} files match SHA-384 digests.") PY echo "[2/4] Checking host preview verifier allowlist & refusal controls..." python3 -I - <<'PY' import json, os, platform, subprocess, sys, tempfile sys.path.insert(0, os.path.abspath("preview")) from core.ztp_client import _host_arch_subdir arch = _host_arch_subdir() if not arch: print(f" SKIP native binary execution on unsupported host {platform.system()}/{platform.machine()}") raise SystemExit(0) vbin = os.path.abspath(f"preview/bin/{arch}/ztp_foundry_preview_verifier") st = json.loads(subprocess.check_output([vbin, "self-test"], text=True)) assert st["verifier_kind"] == "preview_dev00_allowlisted", st print(f" OK: {arch}/ztp_foundry_preview_verifier self-test -> {st['allowed_tasks']}") # Prove non-allowlisted specimen is refused fake_probe = { "hidden": { "case_id_seed": 999999, "entrained_air_fraction": 0.002, "fouling_factor": 0.25, "cold_bay_ambient_c": -5.0, "temp_sensor_bias_k": 1.0, "grid_inverter_fraction": 0.30, "rested_bess_soc": 0.75, }, "memory": {"probes_used": 0, "current_bess_soc": 0.75, "current_coolant_temp_c": 22.0, "accumulated_wear_factor": 0.0}, "request": {"flow_m3_s": 0.006, "valve_pulse_closure_s": 3.5, "heater_test_power_w": 1000.0, "bess_test_current_a": 0.0, "duration_s": 1.0}, } with tempfile.NamedTemporaryFile("w", suffix=".json") as tf: json.dump(fake_probe, tf); tf.flush() r = subprocess.run([vbin, "probe", tf.name], capture_output=True, text=True) assert r.returncode != 0 and "PreviewSpecimenNotAllowlisted" in r.stderr, (r.returncode, r.stderr) rb = subprocess.run([vbin, "batch-grade", "/dev/null"], capture_output=True, text=True) assert rb.returncode != 0 and "PreviewBatchGradeDisabled" in rb.stderr, (rb.returncode, rb.stderr) print(" OK: non-allowlisted specimen and batch-grade refused by name.") PY echo "[3/4] Recomputing both dev-00 reference episodes offline via verifier_core..." python3 -I - <<'PY' import json, os, platform, sys, tempfile sys.path.insert(0, os.path.abspath("preview")) from core.ztp_client import _host_arch_subdir from core.verifier_core import grade_task if not _host_arch_subdir(): print(" SKIP native recompute on unsupported host arch.") raise SystemExit(0) pdir = os.path.abspath("preview/packs/foundry_flagship") vdir = os.path.join(pdir, ".vault") for fn, tid in ( ("reference/foundry-001-dev-00_reference_episode.json", "foundry-001"), ("reference/foundry-002-dev-00_reference_episode.json", "foundry-002"), ): ep = json.load(open(fn, encoding="utf-8")) with tempfile.NamedTemporaryFile("w", suffix=".jsonl", encoding="utf-8") as lf: for rec in ep["ledger_records"]: lf.write(json.dumps(rec, separators=(",", ":")) + "\n") lf.flush() rep = grade_task(tid, ep["submission"], pack_name="foundry_flagship", pack_dir=pdir, ledger_path=lf.name, vault_dir=vdir) exp_seal = ep["grade_report"]["stage_breakdown"]["suite_seal_sha384"] got_seal = rep["stage_breakdown"]["suite_seal_sha384"] assert rep["binary_reward"] == 1 and rep["seals_verified"] is True and got_seal == exp_seal, rep print(f" OK: {ep['case_id']} -> reward=1, 8/8 corners safe, suite_seal_sha384={got_seal[:24]}...") PY echo "[4/4] Preview verification complete: ALL CHECKS PASSED."