interplane.Get Omega
Read in your language

aien-receipts

Append-only AIEN verification receipts, indexed by repository and exact source commit. Read verdicts, signatures and retained logs before making a claim.

Brought by drakestapleton

branch main Branches Tags History

aien-receipts / audit / tls / omega-mv / bench / run.py

129 lines · 6020 bytes Raw Blame History
1#!/usr/bin/env python3
2"""THROWAWAY HOST TOOLING: orchestrates the frozen PROTOCOL.md benchmark. Statistics are NOT done here
3(Wolfram does them from raw.jsonl). Usage: run.py BIN_DIR WWW_DIR OUT_DIR [ROUNDS] [CPUS]"""
4import hashlib, json, os, random, subprocess, sys, time
5
6BIN, WWW, OUT = sys.argv[1], sys.argv[2], sys.argv[3]
7ROUNDS = int(sys.argv[4]) if len(sys.argv) > 4 else 30
8CPUS = [int(c) for c in (sys.argv[5] if len(sys.argv) > 5 else "16,2").split(",")]
9SERVER_CPU = 18
10SUITES = {"chacha": "TLS_CHACHA20_POLY1305_SHA256", "aes128gcm": "TLS_AES_128_GCM_SHA256"}
11ARMS = {
12 "omega": ([f"{BIN}/omega"], {}),
13 "omega-asis": ([f"{BIN}/omega-asis"], {}),
14 "openssl": ([f"{BIN}/openssl"], {}),
15 "rustls-awslc": ([f"{BIN}/rustls"], {"BENCH_PROVIDER": "aws-lc-rs"}),
16 "rustls-ring": ([f"{BIN}/rustls"], {"BENCH_PROVIDER": "ring"}),
17}
18# id: (mode, path, frag, n, warmup)
19WORK = {
20 "hs": ("h", "small.bin", 16384, 40, 5),
21 "get1k": ("g", "small.bin", 16384, 20, 3),
22 "get1m": ("g", "1m.bin", 16384, 8, 2),
23 "bulk16k": ("b", "16m.bin", 16384, 3, 1),
24 "bulk1k": ("b", "16m.bin", 1024, 3, 1),
25}
26os.makedirs(OUT, exist_ok=True)
27servers, ports = [], {}
28
29
30def start_servers():
31 port = 15920
32 for s, name in SUITES.items():
33 for frag in (16384, 1024):
34 port += 1
35 cmd = ["taskset", "-c", str(SERVER_CPU), "openssl", "s_server", "-accept", f"127.0.0.1:{port}",
36 "-cert", "leaf.pem", "-key", "leaf.key", "-tls1_3", "-ciphersuites", name,
37 "-groups", "X25519", "-no_ticket", "-WWW", "-quiet", "-max_send_frag", str(frag)]
38 servers.append(subprocess.Popen(cmd, cwd=WWW, stdin=subprocess.DEVNULL,
39 stdout=subprocess.DEVNULL, stderr=open(f"{OUT}/server-{port}.log", "w")))
40 ports[(s, frag)] = port
41 time.sleep(1.5)
42
43
44def run_ru(arm, cpu, mode, port, n, path):
45 """fork+exec under GNU time: peak RSS and CPU of the client itself, not of the forked Python image"""
46 argv, env = ARMS[arm]
47 e = dict(os.environ, **env)
48 r, w = os.pipe()
49 r2, w2 = os.pipe()
50 pid = os.fork()
51 if pid == 0:
52 os.chdir(WWW)
53 os.dup2(w, 1); os.dup2(w2, 2)
54 os.close(r); os.close(r2)
55 os.execvpe("/usr/bin/time", ["/usr/bin/time", "-f", "RUSAGE %M %U %S", "taskset", "-c", str(cpu)] + argv + [mode, str(port), str(n), path, "root.pem"], e)
56 os.close(w); os.close(w2)
57 out = b""
58 with os.fdopen(r, "rb") as f:
59 out = f.read()
60 with os.fdopen(r2, "rb") as f:
61 err = f.read()
62 _, status, ru = os.wait4(pid, 0)
63 return os.waitstatus_to_exitcode(status), out, err, ru
64
65
66def cpu_busy():
67 d = {}
68 for line in open("/proc/stat"):
69 if line.startswith("cpu") and line[3].isdigit():
70 f = line.split()
71 c = int(f[0][3:])
72 v = list(map(int, f[1:]))
73 d[c] = (sum(v) - v[3] - v[4], sum(v))
74 return d
75
76
77def gate():
78 res = []
79 want = {p: hashlib.sha256(open(f"{WWW}/{p}", "rb").read()).hexdigest() for p in ("1m.bin", "16m.bin")}
80 for s in SUITES:
81 for arm in ARMS:
82 for path, frag in (("1m.bin", 16384), ("16m.bin", 1024)):
83 rc, out, err, _ = run_ru(arm, CPUS[0], "d", ports[(s, frag)], 1, path)
84 i = out.find(b"\r\n\r\n")
85 h = hashlib.sha256(out[i + 4:]).hexdigest() if i >= 0 else ""
86 ok = rc == 0 and h == want[path]
87 res.append({"suite": s, "arm": arm, "path": path, "frag": frag, "rc": rc, "sha256": h, "ok": ok,
88 "err": err.decode(errors="replace")[-300:]})
89 json.dump(res, open(f"{OUT}/gate.json", "w"), indent=1)
90 return {(r["suite"], r["arm"]) for r in res if not r["ok"]}
91
92
93def main():
94 start_servers()
95 try:
96 bad = gate()
97 print("gate failures:", sorted(bad), flush=True)
98 raw = open(f"{OUT}/raw.jsonl", "a")
99 for cpu in CPUS:
100 for s in SUITES:
101 for rnd in range(ROUNDS):
102 order = list(ARMS)
103 random.Random(cpu * 100000 + rnd * 10 + len(s)).shuffle(order) # fixed, published seed
104 b0 = cpu_busy(); l0 = open("/proc/loadavg").read().split()[0]
105 for arm in order:
106 if (s, arm) in bad:
107 continue
108 for wid, (mode, path, frag, n, warm) in WORK.items():
109 t = time.time()
110 rc, out, err, ru = run_ru(arm, cpu, mode, ports[(s, frag)], n, path)
111 ru_l = [l.split() for l in err.decode(errors="replace").splitlines() if l.startswith("RUSAGE ")]
112 maxrss, cpu_s = (int(ru_l[-1][1]), float(ru_l[-1][2]) + float(ru_l[-1][3])) if ru_l else (None, None)
113 samp = [tuple(map(int, l.split()[1:3])) for l in out.decode().splitlines() if l.startswith("S ")]
114 raw.write(json.dumps({"cpu": cpu, "suite": s, "round": rnd, "arm": arm, "work": wid, "rc": rc,
115 "ns": [x[0] for x in samp], "bytes": [x[1] for x in samp], "warm": warm,
116 "maxrss_kib": maxrss, "cpu_s": cpu_s,
117 "t": t, "err": err.decode(errors="replace")[-200:]}) + "\n")
118 b1 = cpu_busy(); l1 = open("/proc/loadavg").read().split()[0]
119 busy = {c: round((b1[c][0] - b0[c][0]) / max(1, b1[c][1] - b0[c][1]), 3) for c in (16, 2, 18)}
120 raw.write(json.dumps({"cpu": cpu, "suite": s, "round": rnd, "env": True, "order": order,
121 "load_start": l0, "load_end": l1, "busy": busy}) + "\n")
122 raw.flush()
123 print(f"cpu{cpu} {s} round {rnd} done load {l1}", flush=True)
124 finally:
125 for p in servers:
126 p.terminate()
127
128
129main()