arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
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, combined guest MEASURED, piece-07,
 30#    KEM payload included)
 31ks = ["32", "64", "128", "256"]
 32vps = [1.41, 1.92, 2.25, 2.46]
 33fig, ax = plt.subplots(figsize=(7.0, 3.4))
 34bars = ax.bar(ks, vps, color=GREEN, edgecolor=GREEN_S, width=0.6)
 35ax.axhline(2.71, ls="--", lw=1.2, color=BLUE_S)
 36ax.text(3.45, 2.74, "asymptote ≈2.7", ha="right", va="bottom", fontsize=9, color=BLUE_S)
 37for b, v in zip(bars, vps):
 38    ax.text(b.get_x() + b.get_width() / 2, v + 0.05, f"{v:.2f}", ha="center", fontsize=9)
 39ax.set_xlabel("batch size (ballots per batch proof)")
 40ax.set_ylabel("votes / second / GPU")
 41ax.set_ylim(0, 3.4)
 42ax.set_title("Sequencer throughput, one RTX 5090 (combined guest, measured end to end)")
 43ax.grid(axis="y", alpha=0.3)
 44save(fig, "annex-throughput.svg")
 45
 46# 2. Where one vote's proving goes (K=256, measured steps)
 47fig, ax = plt.subplots(figsize=(7.0, 2.1))
 48parts = [("ballot-proof verification  2.62M", 2.62, BLUE, BLUE_S),
 49         ("state kernel  0.161M", 0.161, GREEN, GREEN_S),
 50         ("KEM payload share  0.014M", 0.014, ORANGE, ORANGE_S)]
 51left = 0.0
 52for label, v, c, s in parts:
 53    ax.barh([0], [v], left=left, color=c, edgecolor=s, height=0.5)
 54    left += v
 55ax.text(2.62 / 2, 0, "verification 94%", ha="center", va="center", fontsize=10)
 56ax.text(2.62 + 0.161 / 2, 0.45, "state kernel 5.8%", ha="center", fontsize=9, color=GREEN_S)
 57ax.text(2.62 + 0.161 + 0.25, -0.45, "ML-KEM payload 0.5% (per-batch, amortized at K=256)",
 58        ha="center", fontsize=9, color=ORANGE_S)
 59ax.set_xlim(0, 3.1)
 60ax.set_yticks([])
 61ax.set_xlabel("ZisK guest steps per admitted ballot (millions), measured")
 62ax.set_title("Where one vote's batch proving goes (ν=8, nf=16, measured)")
 63ax.spines["left"].set_visible(False)
 64save(fig, "annex-vote-cost.svg")
 65
 66# 3. Warden GPU time: tally vs worst-case complaints (log minutes)
 67import numpy as np
 68sizes = ["10k casts", "120k casts", "1M casts"]
 69tally_min = [4 / 60, 52 / 60, 7.2]
 70compl_min = [10.7, 128, 1067]
 71x = np.arange(3)
 72w = 0.35
 73fig, ax = plt.subplots(figsize=(7.0, 3.6))
 74b1 = ax.bar(x - w / 2, tally_min, w, color=GREEN, edgecolor=GREEN_S,
 75            label="tally contribution proof (routine)")
 76b2 = ax.bar(x + w / 2, compl_min, w, color=RED, edgecolor=RED_S,
 77            label="complaint proofs, worst case: every package malformed")
 78ax.set_yscale("log")
 79for b, v, t in [(b1, tally_min, ["4 s", "52 s", "7.2 min"]),
 80                (b2, compl_min, ["11 min", "2.1 h", "17.8 h"])]:
 81    for bb, vv, tt in zip(b, v, t):
 82        ax.text(bb.get_x() + bb.get_width() / 2, vv * 1.25, tt, ha="center", fontsize=9)
 83ax.set_xticks(x, sizes)
 84ax.set_ylabel("GPU time (minutes, log scale)")
 85ax.set_ylim(0.03, 4000)
 86ax.set_title("Warden GPU time, one RTX 5090")
 87ax.legend(fontsize=9, loc="upper left")
 88ax.grid(axis="y", alpha=0.3)
 89save(fig, "annex-warden.svg")
 90
 91# 4. Ethereum cost per election (log ETH)
 92fees = ["1 gwei", "10 gwei", "50 gwei"]
 93small = [0.0083, 0.083, 0.41]
 94big = [0.69, 6.9, 34.25]
 95x = np.arange(3)
 96fig, ax = plt.subplots(figsize=(7.0, 3.6))
 97b1 = ax.bar(x - w / 2, small, w, color=YELLOW, edgecolor=YELLOW_S, label="500 voters (5 batches)")
 98b2 = ax.bar(x + w / 2, big, w, color=ORANGE, edgecolor=ORANGE_S, label="100k voters (470 batches)")
 99ax.set_yscale("log")
100for b, vals in [(b1, small), (b2, big)]:
101    for bb, vv in zip(b, vals):
102        ax.text(bb.get_x() + bb.get_width() / 2, vv * 1.25, f"{vv:g}", ha="center", fontsize=9)
103ax.set_xticks(x, fees)
104ax.set_ylabel("ETH per election (log scale)")
105ax.set_ylim(0.004, 120)
106ax.set_title("Ethereum cost per election (pessimistic blob pricing)")
107ax.legend(fontsize=9, loc="upper left")
108ax.grid(axis="y", alpha=0.3)
109save(fig, "annex-eth-cost.svg")
110
111# 5. Voter: ballot proving time and memory per profile (piece-04, prototype AIR)
112profiles = ["blowup 8\n34 queries", "fallback\n16 / 26q", "pinned\n32 / 18q"]
113wasm_cold = [2.45, 3.37, 5.16]
114native_1t = [0.701, 1.049, 1.714]
115mem_mib = [122, 240, 478]
116x = np.arange(3)
117fig, (a1, a2) = plt.subplots(1, 2, figsize=(7.2, 3.4))
118b1 = a1.bar(x - w / 2, native_1t, w, color=BLUE, edgecolor=BLUE_S, label="native, 1 thread")
119b2 = a1.bar(x + w / 2, wasm_cold, w, color=GREEN, edgecolor=GREEN_S, label="WASM, cold (first proof)")
120a1.axhline(10, ls="--", lw=1.2, color=RED_S)
121a1.text(2.4, 10.25, "gate: 10 s", ha="right", fontsize=9, color=RED_S)
122for b, vals in [(b1, native_1t), (b2, wasm_cold)]:
123    for bb, vv in zip(b, vals):
124        a1.text(bb.get_x() + bb.get_width() / 2, vv + 0.15, f"{vv:.1f}", ha="center", fontsize=8)
125a1.set_xticks(x, profiles, fontsize=8)
126a1.set_ylabel("seconds per ballot proof")
127a1.set_ylim(0, 11.5)
128a1.set_title("Proving time (desktop)", fontsize=10)
129a1.legend(fontsize=8, loc="upper left")
130a1.grid(axis="y", alpha=0.3)
131b3 = a2.bar(x, mem_mib, 0.5, color=YELLOW, edgecolor=YELLOW_S)
132a2.axhline(1536, ls="--", lw=1.2, color=RED_S)
133a2.text(2.4, 1560, "gate: 1.5 GB", ha="right", fontsize=9, color=RED_S)
134for bb, vv in zip(b3, mem_mib):
135    a2.text(bb.get_x() + bb.get_width() / 2, vv + 30, f"{vv}", ha="center", fontsize=8)
136a2.set_xticks(x, profiles, fontsize=8)
137a2.set_ylabel("peak WASM linear memory (MiB)")
138a2.set_ylim(0, 1750)
139a2.set_title("Memory (CPU-independent)", fontsize=10)
140a2.grid(axis="y", alpha=0.3)
141fig.suptitle("Voter ballot proving, prototype circuit at the v3.0 profiles (measured)", fontsize=11)
142save(fig, "annex-voter.svg")