davinci-paper/v3-pq/figures/src/annex_charts.py
v3-pq/figures/src/annex_charts.pyRaw
1#!/usr/bin/env python3
2"""Annex A charts for the v3-PQ spec (draft v1.6).
3
4Data sources: PoC_by_pieces/piece-03, -04, -07, -09 RESULTS.md, econ/econ.py (cost model)
5and davinci-zkvm BENCHMARK.md (v2 production numbers).
6Run: ~/.cache/chartenv/bin/python annex_charts.py (writes ../annex-*.svg)
7"""
8import matplotlib
9matplotlib.use("svg")
10import matplotlib.pyplot as plt
11import numpy as np
12
13GREEN, GREEN_S = "#d5e8d4", "#82b366"
14BLUE, BLUE_S = "#dae8fc", "#6c8ebf"
15YELLOW, YELLOW_S = "#fff2cc", "#d6b656"
16ORANGE, ORANGE_S = "#ffe6cc", "#d79b00"
17RED, RED_S = "#f8cecc", "#b85450"
18GREY, GREY_S = "#f5f5f5", "#999999"
19
20plt.rcParams.update({
21 "font.size": 10, "axes.titlesize": 11, "axes.edgecolor": "#999999",
22 "axes.spines.top": False, "axes.spines.right": False, "svg.fonttype": "none",
23})
24
25def save(fig, name):
26 fig.tight_layout()
27 fig.savefig(f"../{name}", format="svg")
28 plt.close(fig)
29 print(name)
30
31def label(ax, bars, texts, dy):
32 for b, t in zip(bars, texts):
33 ax.text(b.get_x() + b.get_width() / 2, b.get_height() + dy, t, ha="center", fontsize=8)
34
35# 1. Throughput: v3 STARK stage (piece-07), v3 with wrap (piece-09), v2 with wrap (v2 benchmark, nf=16)
36ks = ["64", "128", "256"]
37stark, wrapped, v2 = [1.94, 2.27, 2.47], [1.68, 2.10, 2.39], [2.12, 2.80, 3.33]
38x, w = np.arange(3), 0.27
39fig, ax = plt.subplots(figsize=(7.0, 3.5))
40b1 = ax.bar(x - w, stark, w, color=BLUE, edgecolor=BLUE_S, label="v3, STARK stage only")
41b2 = ax.bar(x, wrapped, w, color=GREEN, edgecolor=GREEN_S, label="v3, wrapped proof (on-chain ready)")
42b3 = ax.bar(x + w, v2, w, color=GREY, edgecolor=GREY_S, label="v2 production, wrapped, 16 fields")
43for b, v in ((b1, stark), (b2, wrapped), (b3, v2)):
44 label(ax, b, [f"{t:.2f}" for t in v], 0.05)
45ax.set_xticks(x, ks)
46ax.set_xlabel("batch size (ballots per batch proof)")
47ax.set_ylabel("votes / second / GPU")
48ax.set_ylim(0, 4.2)
49ax.set_title("Sequencer throughput on one RTX 5090 (measured)")
50ax.legend(fontsize=8, loc="upper left")
51ax.grid(axis="y", alpha=0.3)
52save(fig, "annex-throughput.svg")
53
54# 2. Where one vote's proving time goes at K=256 (seconds per vote)
55parts = [("ballot-proof verification", 0.333, BLUE, BLUE_S),
56 ("state work", 0.036, GREEN, GREEN_S),
57 ("fixed pipeline / 256", 0.036, YELLOW, YELLOW_S),
58 ("wrap / 256", 0.020, ORANGE, ORANGE_S)]
59fig, ax = plt.subplots(figsize=(7.0, 2.2))
60left = 0.0
61for name, v, c, s in parts:
62 ax.barh([0], [v], left=left, color=c, edgecolor=s, height=0.5)
63 left += v
64ax.text(0.333 / 2, 0, "verifying the ballot proof 0.333 s (78%)", ha="center", va="center", fontsize=9)
65ax.text(0.351, 0.42, "state work 0.036", ha="center", fontsize=8, color=GREEN_S)
66ax.text(0.387, -0.52, "pipeline 0.036", ha="center", fontsize=8, color=YELLOW_S)
67ax.text(0.425, 0.42, "wrap 0.020", ha="center", fontsize=8, color=ORANGE_S)
68ax.set_xlim(0, 0.46)
69ax.set_ylim(-0.75, 0.75)
70ax.set_yticks([])
71ax.set_xlabel("GPU seconds per admitted ballot at 256 ballots per batch (measured components)")
72ax.set_title("Where one vote's batch proving goes")
73ax.spines["left"].set_visible(False)
74save(fig, "annex-vote-cost.svg")
75
76# 3. Warden GPU time (minutes, log): tally contribution vs worst-case complaints
77sizes = ["10k casts", "120k casts", "1M casts"]
78tally_min = [19 / 60, 60 / 60, 8.0]
79compl_min = [10.7, 128, 1067]
80w = 0.35
81fig, ax = plt.subplots(figsize=(7.0, 3.6))
82b1 = ax.bar(x - w / 2, tally_min, w, color=GREEN, edgecolor=GREEN_S,
83 label="tally contribution proof, wrapped (routine)")
84b2 = ax.bar(x + w / 2, compl_min, w, color=RED, edgecolor=RED_S,
85 label="complaint proofs if every package were malformed")
86ax.set_yscale("log")
87for b, v, t in ((b1, tally_min, ["19 s", "≈1 min", "≈8 min"]), (b2, compl_min, ["11 min", "2.1 h", "17.8 h"])):
88 for bb, vv, tt in zip(b, v, t):
89 ax.text(bb.get_x() + bb.get_width() / 2, vv * 1.25, tt, ha="center", fontsize=9)
90ax.set_xticks(x, sizes)
91ax.set_ylabel("GPU time (minutes, log scale)")
92ax.set_ylim(0.1, 4000)
93ax.set_title("Warden GPU time, one RTX 5090 (extrapolated from measured runs)")
94ax.legend(fontsize=8, loc="upper left")
95ax.grid(axis="y", alpha=0.3)
96save(fig, "annex-warden.svg")
97
98# 4. Execution gas per voter, native settlement mode (econ.py)
99cfg = ["ν=1\nθ=1", "ν=3\nθ=2", "ν=5\nθ=3", "ν=8\nθ=5"]
100small = [4152, 13113, 20207, 30127]
101big = [2638, 4387, 7249, 11648]
102x4 = np.arange(4)
103fig, ax = plt.subplots(figsize=(7.0, 3.6))
104b1 = ax.bar(x4 - w / 2, small, w, color=YELLOW, edgecolor=YELLOW_S, label="500 voters")
105b2 = ax.bar(x4 + w / 2, big, w, color=ORANGE, edgecolor=ORANGE_S, label="100,000 voters (120k casts)")
106label(ax, b1, [f"{v/1000:.1f}k" for v in small], 400)
107label(ax, b2, [f"{v/1000:.1f}k" for v in big], 400)
108ax.set_xticks(x4, cfg)
109ax.set_ylabel("execution gas per voter")
110ax.set_ylim(0, 34000)
111ax.set_title("Ethereum execution gas per voter, native settlement (measured parts + estimates)")
112ax.legend(fontsize=8, loc="upper left")
113ax.grid(axis="y", alpha=0.3)
114save(fig, "annex-eth-cost.svg")
115
116# 5. Voter: ballot proving time and memory per profile (piece-04, prototype circuit)
117profiles = ["blowup 8\n34 queries", "fallback\n16 / 26q", "pinned\n32 / 18q"]
118wasm_cold, native_1t, mem_mib = [2.45, 3.37, 5.16], [0.701, 1.049, 1.714], [122, 240, 478]
119fig, (a1, a2) = plt.subplots(1, 2, figsize=(7.2, 3.4))
120b1 = a1.bar(x - w / 2, native_1t, w, color=BLUE, edgecolor=BLUE_S, label="native, 1 thread")
121b2 = a1.bar(x + w / 2, wasm_cold, w, color=GREEN, edgecolor=GREEN_S, label="WASM, cold (first proof)")
122a1.axhline(10, ls="--", lw=1.2, color=RED_S)
123a1.text(2.4, 10.25, "gate: 10 s", ha="right", fontsize=9, color=RED_S)
124label(a1, b1, [f"{v:.1f}" for v in native_1t], 0.15)
125label(a1, b2, [f"{v:.1f}" for v in wasm_cold], 0.15)
126a1.set_xticks(x, profiles, fontsize=8)
127a1.set_ylabel("seconds per ballot proof")
128a1.set_ylim(0, 11.5)
129a1.set_title("Proving time (desktop)", fontsize=10)
130a1.legend(fontsize=8, loc="upper left")
131a1.grid(axis="y", alpha=0.3)
132b3 = a2.bar(x, mem_mib, 0.5, color=YELLOW, edgecolor=YELLOW_S)
133a2.axhline(1536, ls="--", lw=1.2, color=RED_S)
134a2.text(2.4, 1560, "gate: 1.5 GiB", ha="right", fontsize=9, color=RED_S)
135label(a2, b3, [str(v) for v in mem_mib], 30)
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")