davinci-paper/v3-pq/figures/src/annex_charts.py
v3-pq/figures/src/annex_charts.pyRaw
1#!/usr/bin/env python3
2"""Generate Annex A charts for the v3-PQ spec from the PoC measurements (2026-10-25).
3
4Numbers come from PoC_by_pieces/{piece-01..05}/RESULTS.md and poc/zisk-p3-verify.
5Run: ~/.cache/chartenv/bin/python annex_charts.py (writes ../annex-*.svg)
6"""
7import matplotlib
8matplotlib.use("svg")
9import matplotlib.pyplot as plt
10
11GREEN, GREEN_S = "#d5e8d4", "#82b366"
12BLUE, BLUE_S = "#dae8fc", "#6c8ebf"
13YELLOW, YELLOW_S = "#fff2cc", "#d6b656"
14ORANGE, ORANGE_S = "#ffe6cc", "#d79b00"
15RED, RED_S = "#f8cecc", "#b85450"
16
17plt.rcParams.update({
18 "font.size": 10, "axes.titlesize": 11, "axes.edgecolor": "#999999",
19 "axes.spines.top": False, "axes.spines.right": False,
20 "svg.fonttype": "none",
21})
22
23def save(fig, name):
24 fig.tight_layout()
25 fig.savefig(f"../{name}", format="svg")
26 plt.close(fig)
27 print(name)
28
29# 1. Sequencer throughput vs batch size (RTX 5090, measured 0.338 s/vote + ~11.1 s/batch)
30ks = ["32", "64", "128", "256"]
31vps = [1.46, 1.96, 2.35, 2.62]
32fig, ax = plt.subplots(figsize=(7.0, 3.4))
33bars = ax.bar(ks, vps, color=GREEN, edgecolor=GREEN_S, width=0.6)
34ax.axhline(2.96, ls="--", lw=1.2, color=BLUE_S)
35ax.text(3.45, 2.99, "asymptote 2.96", ha="right", va="bottom", fontsize=9, color=BLUE_S)
36for b, v in zip(bars, vps):
37 ax.text(b.get_x() + b.get_width() / 2, v + 0.05, f"{v:.2f}", ha="center", fontsize=9)
38ax.set_xlabel("batch size (ballots per batch proof)")
39ax.set_ylabel("votes / second / GPU")
40ax.set_ylim(0, 3.4)
41ax.set_title("Sequencer throughput, one RTX 5090 (measured)")
42ax.grid(axis="y", alpha=0.3)
43save(fig, "annex-throughput.svg")
44
45# 2. Where one vote's proving goes (K=256, measured steps)
46fig, ax = plt.subplots(figsize=(7.0, 2.1))
47parts = [("ballot-proof verification 2.62M", 2.62, BLUE, BLUE_S),
48 ("state kernel 0.161M", 0.161, GREEN, GREEN_S),
49 ("KEM payload share 0.014M", 0.014, ORANGE, ORANGE_S)]
50left = 0.0
51for label, v, c, s in parts:
52 ax.barh([0], [v], left=left, color=c, edgecolor=s, height=0.5)
53 left += v
54ax.text(2.62 / 2, 0, "verification 94%", ha="center", va="center", fontsize=10)
55ax.text(2.62 + 0.161 / 2, 0.45, "state kernel 5.8%", ha="center", fontsize=9, color=GREEN_S)
56ax.text(2.62 + 0.161 + 0.25, -0.45, "ML-KEM payload 0.5% (per-batch, amortized at K=256)",
57 ha="center", fontsize=9, color=ORANGE_S)
58ax.set_xlim(0, 3.1)
59ax.set_yticks([])
60ax.set_xlabel("ZisK guest steps per admitted ballot (millions), measured")
61ax.set_title("Where one vote's batch proving goes (ν=8, nf=16, measured)")
62ax.spines["left"].set_visible(False)
63save(fig, "annex-vote-cost.svg")
64
65# 3. Warden GPU time: tally vs worst-case complaints (log minutes)
66import numpy as np
67sizes = ["10k casts", "120k casts", "1M casts"]
68tally_min = [4 / 60, 52 / 60, 7.2]
69compl_min = [10.7, 128, 1067]
70x = np.arange(3)
71w = 0.35
72fig, ax = plt.subplots(figsize=(7.0, 3.6))
73b1 = ax.bar(x - w / 2, tally_min, w, color=GREEN, edgecolor=GREEN_S,
74 label="tally contribution proof (routine)")
75b2 = ax.bar(x + w / 2, compl_min, w, color=RED, edgecolor=RED_S,
76 label="complaint proofs, worst case: every package malformed")
77ax.set_yscale("log")
78for b, v, t in [(b1, tally_min, ["4 s", "52 s", "7.2 min"]),
79 (b2, compl_min, ["11 min", "2.1 h", "17.8 h"])]:
80 for bb, vv, tt in zip(b, v, t):
81 ax.text(bb.get_x() + bb.get_width() / 2, vv * 1.25, tt, ha="center", fontsize=9)
82ax.set_xticks(x, sizes)
83ax.set_ylabel("GPU time (minutes, log scale)")
84ax.set_ylim(0.03, 4000)
85ax.set_title("Warden GPU time, one RTX 5090")
86ax.legend(fontsize=9, loc="upper left")
87ax.grid(axis="y", alpha=0.3)
88save(fig, "annex-warden.svg")
89
90# 4. Ethereum cost per election (log ETH)
91fees = ["1 gwei", "10 gwei", "50 gwei"]
92small = [0.0083, 0.083, 0.41]
93big = [0.69, 6.9, 34.25]
94x = np.arange(3)
95fig, ax = plt.subplots(figsize=(7.0, 3.6))
96b1 = ax.bar(x - w / 2, small, w, color=YELLOW, edgecolor=YELLOW_S, label="500 voters (5 batches)")
97b2 = ax.bar(x + w / 2, big, w, color=ORANGE, edgecolor=ORANGE_S, label="100k voters (470 batches)")
98ax.set_yscale("log")
99for b, vals in [(b1, small), (b2, big)]:
100 for bb, vv in zip(b, vals):
101 ax.text(bb.get_x() + bb.get_width() / 2, vv * 1.25, f"{vv:g}", ha="center", fontsize=9)
102ax.set_xticks(x, fees)
103ax.set_ylabel("ETH per election (log scale)")
104ax.set_ylim(0.004, 120)
105ax.set_title("Ethereum cost per election (pessimistic blob pricing)")
106ax.legend(fontsize=9, loc="upper left")
107ax.grid(axis="y", alpha=0.3)
108save(fig, "annex-eth-cost.svg")