vellaveto-types 6.1.1

Core type definitions for Vellaveto policy engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright 2026 Paolo Vella
// SPDX-License-Identifier: MPL-2.0

//! Zero-Knowledge Audit Trail types (Phase 37).
//!
//! Defines the public types for Pedersen commitments and ZK batch proofs.
//! These types are serialized into audit entries and API responses.

use serde::{Deserialize, Serialize};
use std::fmt;

/// A Pedersen commitment to an audit entry hash.
///
/// The commitment binds the entry contents without revealing them:
/// `C = entry_hash * G + blinding * H`
///
/// The `blinding_hint` is the hex-encoded blinding factor, stored
/// for the commitment holder only (not shared with verifiers).
/// It is redacted from Debug output and excluded from serialization
/// to prevent accidental exposure.
#[derive(Clone, Serialize, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct PedersenCommitment {
    /// Hex-encoded compressed Ristretto point (64 hex chars = 32 bytes).
    pub commitment: String,
    /// Hex-encoded blinding factor (64 hex chars = 32 bytes).
    /// For the holder only — not shared with external verifiers.
    /// SECURITY: Excluded from serialization and redacted in Debug.
    #[serde(default, skip_serializing)]
    pub blinding_hint: String,
}

impl PedersenCommitment {
    /// Maximum length for hex-encoded commitment (64 hex chars for 32-byte Ristretto point, with margin).
    const MAX_COMMITMENT_LEN: usize = 128;
    /// Maximum length for hex-encoded blinding hint.
    const MAX_BLINDING_HINT_LEN: usize = 128;

    /// Validate structural bounds on string fields.
    ///
    /// SECURITY (IMP-R118-001): Prevents memory exhaustion from oversized
    /// commitment strings deserialized from untrusted input.
    pub fn validate(&self) -> Result<(), String> {
        if self.commitment.len() > Self::MAX_COMMITMENT_LEN {
            return Err(format!(
                "PedersenCommitment commitment length {} exceeds max {}",
                self.commitment.len(),
                Self::MAX_COMMITMENT_LEN,
            ));
        }
        // SECURITY (FIND-R158-004): Reject control/format chars in commitment
        // to prevent invisible character injection in hex-encoded commitments.
        if crate::core::has_dangerous_chars(&self.commitment) {
            return Err(
                "PedersenCommitment commitment contains control or format characters".to_string(),
            );
        }
        if self.blinding_hint.len() > Self::MAX_BLINDING_HINT_LEN {
            return Err(format!(
                "PedersenCommitment blinding_hint length {} exceeds max {}",
                self.blinding_hint.len(),
                Self::MAX_BLINDING_HINT_LEN,
            ));
        }
        // SECURITY (FIND-R158-004): Reject control/format chars in blinding_hint
        // to prevent invisible character injection in hex-encoded blinding factors.
        if crate::core::has_dangerous_chars(&self.blinding_hint) {
            return Err(
                "PedersenCommitment blinding_hint contains control or format characters"
                    .to_string(),
            );
        }
        Ok(())
    }
}

impl fmt::Debug for PedersenCommitment {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("PedersenCommitment")
            .field("commitment", &self.commitment)
            .field("blinding_hint", &"[REDACTED]")
            .finish()
    }
}

/// A batch ZK proof covering a range of audit entries.
///
/// Proves that a sequence of audit entries forms a valid hash chain
/// and that their Pedersen commitments match, without revealing the
/// entry contents.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ZkBatchProof {
    /// Hex-encoded Groth16 proof bytes.
    pub proof: String,
    /// Unique batch identifier (UUID).
    pub batch_id: String,
    /// Inclusive range of entry sequence numbers covered by this proof.
    pub entry_range: (u64, u64),
    /// Hex-encoded Merkle root at the end of the batch.
    pub merkle_root: String,
    /// Hex-encoded prev_hash of the first entry (public input).
    pub first_prev_hash: String,
    /// Hex-encoded entry_hash of the last entry (public input).
    pub final_entry_hash: String,
    /// ISO 8601 timestamp when the proof was created.
    pub created_at: String,
    /// Number of entries in the batch.
    pub entry_count: usize,
}

impl ZkBatchProof {
    /// Maximum length for hex-encoded proof bytes.
    const MAX_PROOF_LEN: usize = 65_536;
    /// Maximum length for batch_id (UUID string).
    const MAX_BATCH_ID_LEN: usize = 256;
    /// Maximum length for hex-encoded hash strings.
    const MAX_HASH_LEN: usize = 256;
    /// Maximum length for ISO 8601 timestamp strings.
    const MAX_TIMESTAMP_LEN: usize = 64;
    /// Maximum entry count per batch proof.
    const MAX_ENTRY_COUNT: usize = 10_000;

    /// Validate structural bounds on string fields.
    ///
    /// SECURITY: Prevents memory exhaustion from oversized proof payloads
    /// deserialized from untrusted API input.
    pub fn validate(&self) -> Result<(), String> {
        if self.proof.len() > Self::MAX_PROOF_LEN {
            return Err(format!(
                "ZkBatchProof proof length {} exceeds max {}",
                self.proof.len(),
                Self::MAX_PROOF_LEN,
            ));
        }
        // SECURITY (FIND-R158-005): Reject control/format chars in proof field
        // to prevent invisible character injection in hex-encoded proof bytes.
        if crate::core::has_dangerous_chars(&self.proof) {
            return Err("ZkBatchProof proof contains control or format characters".to_string());
        }
        if self.batch_id.len() > Self::MAX_BATCH_ID_LEN {
            return Err(format!(
                "ZkBatchProof batch_id length {} exceeds max {}",
                self.batch_id.len(),
                Self::MAX_BATCH_ID_LEN,
            ));
        }
        // SECURITY (FIND-R115-003): Reject control/format chars in identity fields.
        if crate::core::has_dangerous_chars(&self.batch_id) {
            return Err("ZkBatchProof batch_id contains control or format characters".to_string());
        }
        if self.merkle_root.len() > Self::MAX_HASH_LEN {
            return Err(format!(
                "ZkBatchProof merkle_root length {} exceeds max {}",
                self.merkle_root.len(),
                Self::MAX_HASH_LEN,
            ));
        }
        // SECURITY: Reject control/format chars in merkle_root to prevent
        // integrity check inconsistencies via invisible characters.
        if crate::core::has_dangerous_chars(&self.merkle_root) {
            return Err(
                "ZkBatchProof merkle_root contains control or format characters".to_string(),
            );
        }
        if self.first_prev_hash.len() > Self::MAX_HASH_LEN {
            return Err(format!(
                "ZkBatchProof first_prev_hash length {} exceeds max {}",
                self.first_prev_hash.len(),
                Self::MAX_HASH_LEN,
            ));
        }
        // SECURITY: Reject control/format chars in first_prev_hash to prevent
        // hash chain verification bypass via invisible characters.
        if crate::core::has_dangerous_chars(&self.first_prev_hash) {
            return Err(
                "ZkBatchProof first_prev_hash contains control or format characters".to_string(),
            );
        }
        if self.final_entry_hash.len() > Self::MAX_HASH_LEN {
            return Err(format!(
                "ZkBatchProof final_entry_hash length {} exceeds max {}",
                self.final_entry_hash.len(),
                Self::MAX_HASH_LEN,
            ));
        }
        // SECURITY: Reject control/format chars in final_entry_hash to prevent
        // hash chain verification bypass via invisible characters.
        if crate::core::has_dangerous_chars(&self.final_entry_hash) {
            return Err(
                "ZkBatchProof final_entry_hash contains control or format characters".to_string(),
            );
        }
        if self.created_at.len() > Self::MAX_TIMESTAMP_LEN {
            return Err(format!(
                "ZkBatchProof created_at length {} exceeds max {}",
                self.created_at.len(),
                Self::MAX_TIMESTAMP_LEN,
            ));
        }
        // SECURITY (FIND-R115-003): Reject control/format chars in timestamp fields.
        if crate::core::has_dangerous_chars(&self.created_at) {
            return Err(
                "ZkBatchProof created_at contains control or format characters".to_string(),
            );
        }
        // SECURITY: Validate entry_range ordering — start must not exceed end.
        if self.entry_range.0 > self.entry_range.1 {
            return Err(format!(
                "ZkBatchProof entry_range start {} exceeds end {}",
                self.entry_range.0, self.entry_range.1,
            ));
        }
        // SECURITY: Bound entry_count to prevent memory abuse from crafted payloads.
        if self.entry_count > Self::MAX_ENTRY_COUNT {
            return Err(format!(
                "ZkBatchProof entry_count {} exceeds max {}",
                self.entry_count,
                Self::MAX_ENTRY_COUNT,
            ));
        }
        // SECURITY: Consistency check — entry_count must match the range span.
        // SECURITY (R235-TYP-6): Use try_from instead of `as usize` for defense-in-depth
        // on 32-bit platforms (bounded by MAX_ENTRY_COUNT check above).
        let expected_count =
            usize::try_from((self.entry_range.1 - self.entry_range.0).saturating_add(1))
                .unwrap_or(usize::MAX);
        if self.entry_count != expected_count {
            return Err(format!(
                "ZkBatchProof entry_count {} does not match entry_range span {} (range {}-{})",
                self.entry_count, expected_count, self.entry_range.0, self.entry_range.1,
            ));
        }
        Ok(())
    }
}

/// Result of verifying a ZK batch proof.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ZkVerifyResult {
    /// Whether the proof is valid.
    pub valid: bool,
    /// The batch ID that was verified.
    pub batch_id: String,
    /// The entry range that was verified.
    pub entry_range: (u64, u64),
    /// ISO 8601 timestamp when verification was performed.
    pub verified_at: String,
    /// Error message if verification failed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

impl ZkVerifyResult {
    /// Maximum length for batch_id.
    const MAX_BATCH_ID_LEN: usize = 256;
    /// Maximum length for ISO 8601 timestamp.
    const MAX_TIMESTAMP_LEN: usize = 64;
    /// Maximum length for error messages.
    const MAX_ERROR_LEN: usize = 4096;

    /// Validate structural bounds on string fields.
    pub fn validate(&self) -> Result<(), String> {
        if self.batch_id.len() > Self::MAX_BATCH_ID_LEN {
            return Err(format!(
                "ZkVerifyResult batch_id length {} exceeds max {}",
                self.batch_id.len(),
                Self::MAX_BATCH_ID_LEN,
            ));
        }
        // SECURITY (FIND-R172-002): Reject control/format chars in batch_id —
        // parity with ZkBatchProof::validate() (line 123).
        if crate::core::has_dangerous_chars(&self.batch_id) {
            return Err(
                "ZkVerifyResult batch_id contains control or format characters".to_string(),
            );
        }
        if self.verified_at.len() > Self::MAX_TIMESTAMP_LEN {
            return Err(format!(
                "ZkVerifyResult verified_at length {} exceeds max {}",
                self.verified_at.len(),
                Self::MAX_TIMESTAMP_LEN,
            ));
        }
        // SECURITY (FIND-R172-002): Reject control/format chars in verified_at —
        // parity with ZkBatchProof::validate() created_at (line 159).
        if crate::core::has_dangerous_chars(&self.verified_at) {
            return Err(
                "ZkVerifyResult verified_at contains control or format characters".to_string(),
            );
        }
        if let Some(ref err) = self.error {
            if err.len() > Self::MAX_ERROR_LEN {
                return Err(format!(
                    "ZkVerifyResult error length {} exceeds max {}",
                    err.len(),
                    Self::MAX_ERROR_LEN,
                ));
            }
            // SECURITY (FIND-R172-001): Reject control/format chars in error field
            // to prevent log injection via crafted error messages.
            if crate::core::has_dangerous_chars(err) {
                return Err(
                    "ZkVerifyResult error contains control or format characters".to_string()
                );
            }
        }
        Ok(())
    }
}

/// Status of the ZK audit scheduler.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ZkSchedulerStatus {
    /// Whether the batch prover is active.
    pub active: bool,
    /// Number of pending witnesses awaiting batch proof.
    pub pending_witnesses: usize,
    /// Number of completed batch proofs.
    pub completed_proofs: usize,
    /// Sequence number of the last proved entry.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_proved_sequence: Option<u64>,
    /// ISO 8601 timestamp of the last batch proof.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_proof_at: Option<String>,
}

impl ZkSchedulerStatus {
    /// Maximum length for ISO 8601 timestamp.
    const MAX_TIMESTAMP_LEN: usize = 64;

    /// Validate structural bounds on string fields.
    pub fn validate(&self) -> Result<(), String> {
        if let Some(ref ts) = self.last_proof_at {
            if ts.len() > Self::MAX_TIMESTAMP_LEN {
                return Err(format!(
                    "ZkSchedulerStatus last_proof_at length {} exceeds max {}",
                    ts.len(),
                    Self::MAX_TIMESTAMP_LEN,
                ));
            }
            // SECURITY (FIND-R172-003): Reject control/format chars in timestamp —
            // parity with ZkBatchProof::validate() created_at (line 159).
            if crate::core::has_dangerous_chars(ts) {
                return Err(
                    "ZkSchedulerStatus last_proof_at contains control or format characters"
                        .to_string(),
                );
            }
        }
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    // ── Helper: minimal valid ZkBatchProof ───────────────────────────────

    fn valid_batch_proof() -> ZkBatchProof {
        ZkBatchProof {
            proof: "deadbeef".to_string(),
            batch_id: "batch-001".to_string(),
            entry_range: (1, 10),
            merkle_root: "aabbccdd".to_string(),
            first_prev_hash: "00001111".to_string(),
            final_entry_hash: "ffffeeee".to_string(),
            created_at: "2025-06-01T12:00:00Z".to_string(),
            entry_count: 10,
        }
    }

    // ── PedersenCommitment::validate() ──────────────────────────────────

    #[test]
    fn test_pedersen_commitment_validate_valid_ok() {
        let pc = PedersenCommitment {
            commitment: "a".repeat(64),
            blinding_hint: "b".repeat(64),
        };
        assert!(pc.validate().is_ok());
    }

    #[test]
    fn test_pedersen_commitment_validate_commitment_too_long_rejected() {
        let pc = PedersenCommitment {
            commitment: "x".repeat(129),
            blinding_hint: String::new(),
        };
        let err = pc.validate().unwrap_err();
        assert!(err.contains("commitment length"), "got: {err}");
    }

    #[test]
    fn test_pedersen_commitment_validate_blinding_hint_too_long_rejected() {
        let pc = PedersenCommitment {
            commitment: "ok".to_string(),
            blinding_hint: "y".repeat(129),
        };
        let err = pc.validate().unwrap_err();
        assert!(err.contains("blinding_hint length"), "got: {err}");
    }

    #[test]
    fn test_pedersen_commitment_validate_commitment_control_chars_rejected() {
        let pc = PedersenCommitment {
            commitment: "abc\x00def".to_string(),
            blinding_hint: String::new(),
        };
        let err = pc.validate().unwrap_err();
        assert!(err.contains("commitment contains control"), "got: {err}");
    }

    #[test]
    fn test_pedersen_commitment_validate_blinding_hint_control_chars_rejected() {
        let pc = PedersenCommitment {
            commitment: "ok".to_string(),
            blinding_hint: "hint\x07bell".to_string(),
        };
        let err = pc.validate().unwrap_err();
        assert!(err.contains("blinding_hint contains control"), "got: {err}");
    }

    #[test]
    fn test_pedersen_commitment_debug_redacts_blinding_hint() {
        let pc = PedersenCommitment {
            commitment: "abc123".to_string(),
            blinding_hint: "supersecret".to_string(),
        };
        let debug_str = format!("{pc:?}");
        assert!(debug_str.contains("[REDACTED]"));
        assert!(!debug_str.contains("supersecret"));
    }

    // ── ZkBatchProof::validate() ────────────────────────────────────────

    #[test]
    fn test_zk_batch_proof_validate_valid_ok() {
        assert!(valid_batch_proof().validate().is_ok());
    }

    #[test]
    fn test_zk_batch_proof_validate_proof_too_long_rejected() {
        let mut bp = valid_batch_proof();
        bp.proof = "p".repeat(65_537);
        let err = bp.validate().unwrap_err();
        assert!(err.contains("proof length"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_proof_control_chars_rejected() {
        let mut bp = valid_batch_proof();
        bp.proof = "abc\x01def".to_string();
        let err = bp.validate().unwrap_err();
        assert!(err.contains("proof contains control"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_batch_id_control_chars_rejected() {
        let mut bp = valid_batch_proof();
        bp.batch_id = "id\x00null".to_string();
        let err = bp.validate().unwrap_err();
        assert!(err.contains("batch_id contains control"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_entry_range_inverted_rejected() {
        let mut bp = valid_batch_proof();
        bp.entry_range = (10, 1);
        let err = bp.validate().unwrap_err();
        assert!(err.contains("entry_range start"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_entry_count_too_large_rejected() {
        let mut bp = valid_batch_proof();
        bp.entry_count = 10_001;
        // Fix range to match
        bp.entry_range = (1, 10_001);
        let err = bp.validate().unwrap_err();
        assert!(err.contains("entry_count"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_entry_count_mismatch_rejected() {
        let mut bp = valid_batch_proof();
        bp.entry_count = 5; // range is (1,10) -> expected 10
        let err = bp.validate().unwrap_err();
        assert!(
            err.contains("does not match entry_range span"),
            "got: {err}"
        );
    }

    #[test]
    fn test_zk_batch_proof_validate_merkle_root_too_long_rejected() {
        let mut bp = valid_batch_proof();
        bp.merkle_root = "m".repeat(257);
        let err = bp.validate().unwrap_err();
        assert!(err.contains("merkle_root length"), "got: {err}");
    }

    #[test]
    fn test_zk_batch_proof_validate_hash_fields_control_chars_rejected() {
        let mut bp = valid_batch_proof();
        bp.first_prev_hash = "hash\x02bad".to_string();
        assert!(bp
            .validate()
            .unwrap_err()
            .contains("first_prev_hash contains control"));

        let mut bp2 = valid_batch_proof();
        bp2.final_entry_hash = "hash\x03bad".to_string();
        assert!(bp2
            .validate()
            .unwrap_err()
            .contains("final_entry_hash contains control"));

        let mut bp3 = valid_batch_proof();
        bp3.merkle_root = "root\x04bad".to_string();
        assert!(bp3
            .validate()
            .unwrap_err()
            .contains("merkle_root contains control"));
    }

    // ── ZkVerifyResult::validate() ──────────────────────────────────────

    #[test]
    fn test_zk_verify_result_validate_valid_ok() {
        let vr = ZkVerifyResult {
            valid: true,
            batch_id: "batch-001".to_string(),
            entry_range: (1, 10),
            verified_at: "2025-06-01T12:00:00Z".to_string(),
            error: None,
        };
        assert!(vr.validate().is_ok());
    }

    #[test]
    fn test_zk_verify_result_validate_error_too_long_rejected() {
        let vr = ZkVerifyResult {
            valid: false,
            batch_id: "b1".to_string(),
            entry_range: (1, 1),
            verified_at: "2025-01-01T00:00:00Z".to_string(),
            error: Some("e".repeat(4097)),
        };
        assert!(vr.validate().unwrap_err().contains("error length"));
    }

    #[test]
    fn test_zk_verify_result_validate_error_control_chars_rejected() {
        let vr = ZkVerifyResult {
            valid: false,
            batch_id: "b1".to_string(),
            entry_range: (1, 1),
            verified_at: "2025-01-01T00:00:00Z".to_string(),
            error: Some("err\x00msg".to_string()),
        };
        assert!(vr
            .validate()
            .unwrap_err()
            .contains("error contains control"));
    }

    // ── ZkSchedulerStatus::validate() ───────────────────────────────────

    #[test]
    fn test_zk_scheduler_status_validate_valid_ok() {
        let ss = ZkSchedulerStatus {
            active: true,
            pending_witnesses: 5,
            completed_proofs: 10,
            last_proved_sequence: Some(100),
            last_proof_at: Some("2025-06-01T12:00:00Z".to_string()),
        };
        assert!(ss.validate().is_ok());
    }

    #[test]
    fn test_zk_scheduler_status_validate_timestamp_too_long_rejected() {
        let ss = ZkSchedulerStatus {
            active: false,
            pending_witnesses: 0,
            completed_proofs: 0,
            last_proved_sequence: None,
            last_proof_at: Some("t".repeat(65)),
        };
        assert!(ss.validate().unwrap_err().contains("last_proof_at length"));
    }

    #[test]
    fn test_zk_scheduler_status_validate_timestamp_control_chars_rejected() {
        let ss = ZkSchedulerStatus {
            active: false,
            pending_witnesses: 0,
            completed_proofs: 0,
            last_proved_sequence: None,
            last_proof_at: Some("2025-01-01\x00T00:00:00Z".to_string()),
        };
        assert!(ss.validate().unwrap_err().contains("control or format"));
    }
}