1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
13pub struct SecureFieldMirror {
14 pub a: u32,
15 pub b: u32,
16 pub c: u32,
17 pub d: u32,
18}
19
20impl SecureFieldMirror {
21 pub fn as_f32(&self) -> f32 {
23 self.a as f32 / (0x7fff_ffff_u32 as f32)
24 }
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct RoundPolyViz {
30 pub c0: SecureFieldMirror,
31 pub c1: SecureFieldMirror,
32 pub c2: SecureFieldMirror,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct RoundPolyDeg3Viz {
38 pub c0: SecureFieldMirror,
39 pub c1: SecureFieldMirror,
40 pub c2: SecureFieldMirror,
41 pub c3: SecureFieldMirror,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
48pub enum LayerKind {
49 MatMul,
50 Activation,
51 LayerNorm,
52 RMSNorm,
53 Add,
54 Mul,
55 Attention,
56 Embedding,
57 Dequantize,
58 Quantize,
59 Input,
60 Unknown,
61}
62
63impl LayerKind {
64 pub fn color_rgb(&self) -> [u8; 3] {
66 match self {
67 LayerKind::MatMul => [0x42, 0x9b, 0xf5], LayerKind::Activation => [0xf5, 0xa5, 0x42], LayerKind::LayerNorm => [0x4c, 0xc6, 0x71], LayerKind::RMSNorm => [0x38, 0xb2, 0xac], LayerKind::Add => [0xa0, 0xa0, 0xa0], LayerKind::Mul => [0xa8, 0x55, 0xd4], LayerKind::Attention => [0xf5, 0xd0, 0x42], LayerKind::Embedding => [0xec, 0x6e, 0xad], LayerKind::Dequantize => [0xff, 0x8c, 0x00], LayerKind::Quantize => [0xff, 0x4c, 0x4c], LayerKind::Input => [0x80, 0x80, 0xff], LayerKind::Unknown => [0x60, 0x60, 0x60], }
80 }
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
85pub enum LayerProofKind {
86 Sumcheck,
87 LogUp,
88 Linear,
89 Skipped,
90 Deferred,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct CircuitNodeMeta {
96 pub layer_idx: usize,
97 pub node_id: usize,
98 pub kind: LayerKind,
99 pub input_shape: (usize, usize),
100 pub output_shape: (usize, usize),
101 pub trace_cost: usize,
103 pub input_layers: Vec<usize>,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct GpuSnapshot {
110 pub device_id: usize,
111 pub device_name: String,
112 pub utilization: f32,
114 pub free_memory_bytes: Option<usize>,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct ActivationStats {
121 pub mean: f32,
122 pub std_dev: f32,
123 pub min: f32,
124 pub max: f32,
125 pub sparsity: f32,
126}
127
128#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
130pub enum LogLevel {
131 Trace,
132 Debug,
133 Info,
134 Warn,
135 Error,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
145#[non_exhaustive]
146pub enum ProofEvent {
147 CircuitCompiled {
150 total_layers: usize,
151 input_shape: (usize, usize),
152 output_shape: (usize, usize),
153 nodes: Vec<CircuitNodeMeta>,
154 has_simd: bool,
155 simd_num_blocks: usize,
156 },
157
158 LayerActivation {
161 layer_idx: usize,
162 node_id: usize,
163 kind: LayerKind,
164 output_shape: (usize, usize),
165 output_sample: Vec<u32>,
167 stats: ActivationStats,
168 },
169 AttentionHeatmap {
171 layer_idx: usize,
172 head_idx: usize,
173 num_heads: usize,
174 seq_len: usize,
175 scores: Vec<f32>,
177 },
178
179 ProofStart {
182 model_name: Option<String>,
183 backend: String,
184 num_layers: usize,
185 input_shape: (usize, usize),
186 output_shape: (usize, usize),
187 },
188 LayerStart {
190 layer_idx: usize,
191 kind: LayerKind,
192 input_shape: (usize, usize),
193 output_shape: (usize, usize),
194 trace_cost: usize,
196 claim_value_approx: f32,
198 gpu_device: Option<usize>,
199 },
200 SumcheckRound {
202 layer_idx: usize,
203 round: usize,
204 total_rounds: usize,
205 poly_deg2: Option<RoundPolyViz>,
207 poly_deg3: Option<RoundPolyDeg3Viz>,
209 claim_value_approx: f32,
211 },
212 LayerEnd {
214 layer_idx: usize,
215 kind: LayerProofKind,
216 final_claim_value_approx: f32,
217 duration_ms: u64,
218 rounds_completed: usize,
219 },
220 ProofComplete {
222 duration_ms: u64,
223 num_layer_proofs: usize,
224 num_weight_openings: usize,
225 weight_binding_mode: String,
226 },
227
228 WeightOpeningStart {
230 weight_node_id: usize,
231 eval_point_len: usize,
232 },
233 WeightOpeningEnd {
234 weight_node_id: usize,
235 duration_ms: u64,
236 commitment_hex: String,
238 },
239
240 AggregatedBindingStart {
242 num_claims: usize,
243 num_matrices: usize,
244 },
245 AggregatedBindingEnd {
246 duration_ms: u64,
247 estimated_calldata_felts: usize,
248 },
249
250 GpuStatus {
252 devices: Vec<GpuSnapshot>,
253 matmul_done: usize,
254 matmul_total: usize,
255 layers_done: usize,
256 layers_total: usize,
257 },
258
259 StarkProofStart {
261 num_activation_layers: usize,
262 num_add_layers: usize,
263 num_layernorm_layers: usize,
264 },
265 StarkProofEnd {
266 duration_ms: u64,
267 },
268
269 Log {
271 level: LogLevel,
272 message: String,
273 },
274}