summarize_receipts.py

benches/crypto/garbled-circuit/ot-reference/summarize_receipts.py

summarize_receipts.py64 lines← Benchmarks
1#!/usr/bin/env python32"""Normalize isolated Wasmtime receipts without converting their fuel units."""3import argparse4import hashlib5import json6from pathlib import Path789def main():10    parser = argparse.ArgumentParser()11    parser.add_argument("--evidence", type=Path, required=True)12    parser.add_argument("--source-manifest", type=Path, required=True)13    parser.add_argument("--out", type=Path, required=True)14    args = parser.parse_args()15    source_hash = hashlib.sha256(args.source_manifest.read_bytes()).hexdigest()16    rows = []17    for path in args.evidence.rglob("receipt.json"):18        receipt = json.loads(path.read_text())19        count = receipt.get("selected_logical_count")20        control = receipt.get("selected_control")21        # The complete audit suite is a correctness run, outside the isolated22        # measurement matrix. Failed earlier attempts remain in their raw files.23        if count is None and control is None:24            continue25        if not receipt["passed"]:26            raise RuntimeError(f"An isolated qualification failed: {path}")27        outputs = [json.loads(line) for line in (path.parent / "stdout.jsonl").read_text().splitlines()]28        if len(outputs) != 1:29            raise RuntimeError(f"Expected one isolated output row: {path}")30        output = outputs[0]31        sample = next((int(part[7:]) for part in path.parts if part.startswith("sample-")), 0)32        rows.append({33            "case": control or f"chosen-{count}",34            "scope": "standalone-wasm32-wasi",35            "phase": "fresh-base-and-chosen" if count else control,36            "party": "both",37            "sample": sample,38            "logical_chosen_ots": count or 0,39            "base_ots": output.get("base_ots", 0),40            "internal_padded_ots": output.get("internal_ots", 0),41            "checked_outputs": output.get("checked_outputs", 0),42            "total_transport_bytes": output.get("total_transport_bytes", output.get("transport_bytes", 0)),43            "wasmtime_fuel": receipt["wasmtime_fuel_consumed"],44            "wasmtime_fuel_limit": receipt["wasmtime_fuel_limit"],45            "wasmtime_version": receipt["wasmtime_python_version"],46            "fuel_policy": "Wasmtime default fuel operator costs; no operator customization; whole process",47            "initial_linear_memory_pages": receipt["initial_linear_memory_pages"],48            "final_linear_memory_pages": receipt["final_linear_memory_pages"],49            "maximum_linear_memory_pages": receipt["maximum_linear_memory_pages"],50            "linear_memory_page_bytes": receipt["linear_memory_page_bytes"],51            "ic_instructions": None,52            "ic_cycles": None,53            "wasm_sha256": receipt["wasm_sha256"],54            "source_manifest_sha256": source_hash,55            "raw_receipt": str(path.relative_to(args.evidence)),56            "passed": True,57        })58    rows.sort(key=lambda row: (row["case"], row["sample"]))59    args.out.write_text("".join(json.dumps(row, sort_keys=True) + "\n" for row in rows))60    print(json.dumps({"rows": len(rows), "out": str(args.out), "fuel_unit": "wasmtime_fuel"}))616263if __name__ == "__main__":64    main()