Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-bench/blob/main/tests/tamper.py # omega-gpu-bench First-party Omega GPU kernel benchmark harness and receipts Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-bench / tests / tamper.py` 103 lines ยท 3614 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # tests/tamper.py KIT_RECEIPT IMPORT_RECEIPT OUT_DIR -- write tampered copies of two valid receipts. 3 # Each output file is named .json; tests/run.sh requires tools/validate.py to reject every one of 4 # them with the reason listed in CASES. All but "noreseal" are re-sealed, so the content rules (not just 5 # the receipt hash) have to catch them. 6 import copy, json, os, sys 7 8 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tools")) 9 import receipt as R # noqa: E402 10 11 12 def row(rec, verdict): 13 return next(r for r in rec["results"] if r["verdict"] == verdict) 14 15 16 def t_noreseal(r): 17 r["machine"]["gpu"] = "NVIDIA H100 80GB HBM3" 18 return False 19 20 21 def t_cubin_hash(r): 22 r["results"][0]["cubin_sha256"] = "0" * 64 23 24 25 def t_pass_with_mismatches(r): 26 row(r, "PASS")["mismatches"] = 5 27 28 29 def t_forged_ref(r): 30 row(r, "NEG_DETECTED")["first_bad"][0][2] += 1 31 32 33 def t_dropped_row(r): 34 r["results"].remove(row(r, "NEG_DETECTED")) 35 36 37 def t_output_hash(r): 38 row(r, "PASS")["output_sha256"] = "ab" * 32 39 40 41 def t_inflated_gbps(r): 42 p = row(r, "PASS") 43 p["gbps"] = round(p["gbps"] * 2, 3) 44 45 46 def t_label(r): 47 r["path"] = "CUDA++ user space" 48 49 50 def t_checked_short(r): 51 row(r, "PASS")["checked"] = 1000 52 53 54 def t_unknown_commit(r): 55 r["kit"]["commit"] = "f" * 40 56 57 58 def t_modified_kit(r): 59 r["kit"]["modified"] = True 60 61 62 def t_neg_not_run_as_detected(r): 63 n = row(r, "NEG_DETECTED") 64 n.update(checked=None, mismatches=None, first_bad=None, output_sha256=None, error="cuModuleLoadData: 200") 65 66 67 def t_withdrawn_kernel(r): 68 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 69 sums = R.read_sums(os.path.join(root, "kernels", "WITHDRAWN.sha256")) 70 p = row(r, "PASS") 71 p["cubin_sha256"] = sums[p["cubin"]] 72 73 74 CASES = { # case: (tamper, which receipt, reason the validator must give) 75 "noreseal": (t_noreseal, "kit", "receipt_sha256 does not match"), 76 "cubin-hash": (t_cubin_hash, "kit", "differs from kernels/SHA256SUMS"), 77 "withdrawn-kernel": (t_withdrawn_kernel, "kit", "kernel withdrawn from this kit"), 78 "pass-with-mismatches": (t_pass_with_mismatches, "kit", "contradicts 5 mismatches"), 79 "forged-ref": (t_forged_ref, "kit", "recomputed"), 80 "dropped-row": (t_dropped_row, "kit", "must run exactly"), 81 "output-hash": (t_output_hash, "kit", "differs from the reference output but mismatches = 0"), 82 "inflated-gbps": (t_inflated_gbps, "kit", "is not 12 *"), 83 "label-removed": (t_label, "kit", "path label"), 84 "checked-short": (t_checked_short, "kit", "checked must be"), 85 "unknown-commit": (t_unknown_commit, "kit", "is not in"), 86 "modified-kit": (t_modified_kit, "kit", "local changes"), 87 "neg-not-run-as-detected": (t_neg_not_run_as_detected, "kit", "a kernel that ran has no error"), 88 "import-not-allowlisted": (lambda r: r.update(provider="my own 4090"), "import", "imports.sha256"), 89 "import-forged-ref": (t_forged_ref, "import", "recomputed"), 90 } 91 92 if __name__ == "__main__": 93 src = {"kit": json.load(open(sys.argv[1])), "import": None if sys.argv[2] == "-" else json.load(open(sys.argv[2]))} 94 os.makedirs(sys.argv[3], exist_ok=True) 95 for case, (fn, which, reason) in CASES.items(): 96 if src[which] is None: 97 continue # no imported receipt in this checkout 98 rec = copy.deepcopy(src[which]) 99 if fn(rec) is not False: 100 R.seal(rec) 101 with open(os.path.join(sys.argv[3], case + ".json"), "w") as f: 102 json.dump(rec, f, indent=1, sort_keys=True) 103 print("%s\t%s" % (case, reason))