slither 0.2.0

Encrypted peer-to-peer UDP transport: reliable messages, streams and datagrams, authenticated by raw public keys - no certificates, no TLS. WireGuard-shaped handshake, QUIC-shaped frames.
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
//! Conformance fence over `slither::constants`.
//!
//! Every constant asserted here is transcribed from `SPEC.md`'s
//! `## Named constants` consolidated table (grep `^## Named constants`),
//! cross-checked against the specific section that table cites as each
//! constant's `Home` where the table's own entry is terse (grouped ranges,
//! formulas, or prose fractions/rates rather than a bare literal). This
//! file is written from the spec, independently of the implementation and
//! of `.slices/00-ground/PLAN.md`'s transcription table — a value written
//! here that disagrees with what the crate defines is exactly the signal
//! this file exists to produce.
//!
//! A handful of constants are durations. `std::time::Duration` is the type
//! that reads naturally for them; if the crate instead exposes a raw
//! integer (seconds, millis, ...), this file fails to *compile*, not to
//! *assert* — that is itself useful information, per the brief.
//!
//! One `#[test]` per constant so that a single wrong transcription doesn't
//! stop the rest of the fence from reporting (`cargo test` runs every test
//! function regardless of another's panic).

// This file's whole job is to assert one constant against another, so
// `clippy::assertions_on_constants` fires on every relational fence in it.
// The lint's advice (`const { assert!(..) }`) would make a mis-transcription
// a *build* failure rather than a per-constant test failure, which defeats
// the "one `#[test]` per constant so one wrong value does not mask the
// rest" design above. Silenced here, and nowhere else in the crate.
// (Added by the slice-0 implementer to clear the `-D warnings` lint gate:
// no assertion, value or name in this file was changed.)
#![allow(clippy::assertions_on_constants)]

use slither::constants::*;
use std::time::Duration;

// ---------------------------------------------------------------------
// §3.1 — packet types, version, reserved packet-type values
// ---------------------------------------------------------------------

#[test]
fn version() {
    // SPEC.md §3.1 / Named constants: `VERSION` = 0x01.
    assert_eq!(VERSION, 0x01);
}

#[test]
fn pkt_handshake_init() {
    // SPEC.md §3.1: PKT_HANDSHAKE_INIT / PKT_HANDSHAKE_RESP / PKT_DATA = 0x01 / 0x02 / 0x03.
    assert_eq!(PKT_HANDSHAKE_INIT, 0x01);
}

#[test]
fn pkt_handshake_resp() {
    // SPEC.md §3.1: PKT_HANDSHAKE_INIT / PKT_HANDSHAKE_RESP / PKT_DATA = 0x01 / 0x02 / 0x03.
    assert_eq!(PKT_HANDSHAKE_RESP, 0x02);
}

#[test]
fn pkt_data() {
    // SPEC.md §3.1: PKT_HANDSHAKE_INIT / PKT_HANDSHAKE_RESP / PKT_DATA = 0x01 / 0x02 / 0x03.
    assert_eq!(PKT_DATA, 0x03);
}

#[test]
fn pkt_reserved_unused() {
    // SPEC.md §3.1: "reserved packet types | 0x04 (unused), 0x05 (cookie/mac2)".
    assert_eq!(PKT_RESERVED_UNUSED, 0x04);
}

#[test]
fn pkt_reserved_cookie() {
    // SPEC.md §3.1: "reserved packet types | 0x04 (unused), 0x05 (cookie/mac2)".
    assert_eq!(PKT_RESERVED_COOKIE, 0x05);
}

// ---------------------------------------------------------------------
// §3.2–3.4 — header lengths (INIT §3.2, RESP §3.3, DATA §3.4)
// ---------------------------------------------------------------------

#[test]
fn init_header_len() {
    // SPEC.md §3.2 / Named constants: INIT_HEADER_LEN / RESP_HEADER_LEN / DATA_HEADER_LEN = 6 / 10 / 14 B.
    assert_eq!(INIT_HEADER_LEN, 6);
}

#[test]
fn resp_header_len() {
    // SPEC.md §3.3 / Named constants: INIT_HEADER_LEN / RESP_HEADER_LEN / DATA_HEADER_LEN = 6 / 10 / 14 B.
    assert_eq!(RESP_HEADER_LEN, 10);
}

#[test]
fn data_header_len() {
    // SPEC.md §3.4 / Named constants: INIT_HEADER_LEN / RESP_HEADER_LEN / DATA_HEADER_LEN = 6 / 10 / 14 B.
    assert_eq!(DATA_HEADER_LEN, 14);
}

// ---------------------------------------------------------------------
// §3.5 — sizes and caps
// ---------------------------------------------------------------------

#[test]
fn max_datagram() {
    // SPEC.md §3.5 / Named constants: MAX_DATAGRAM / MAX_PLAINTEXT = 1200 / 1170 B.
    assert_eq!(MAX_DATAGRAM, 1200);
}

#[test]
fn max_plaintext() {
    // SPEC.md §3.5 / Named constants: MAX_DATAGRAM / MAX_PLAINTEXT = 1200 / 1170 B.
    assert_eq!(MAX_PLAINTEXT, 1170);
}

// ---------------------------------------------------------------------
// §2.3 / §2.4 — per-suite derived sizes (reference suite: P-256 / ChaCha20-Poly1305)
// ---------------------------------------------------------------------

#[test]
fn static_public_len() {
    // SPEC.md §2.3/§2.4: reference-suite `PK` = 65 (P-256 uncompressed SEC1
    // form, 0x04 ‖ X ‖ Y). Suite-dependent; this is the reference-suite value
    // the "Named constants" table's own header says it reports.
    assert_eq!(STATIC_PUBLIC_LEN, 65);
}

#[test]
fn aead_tag_len() {
    // SPEC.md §2.3 / Named constants: AEAD_TAG_LEN = 16 B.
    assert_eq!(AEAD_TAG_LEN, 16);
}

#[test]
fn msg1_payload_len() {
    // SPEC.md §5.2 / §2.3 (test-pinned) / Named constants: MSG1_PAYLOAD_LEN = 12 B.
    assert_eq!(MSG1_PAYLOAD_LEN, 12);
}

#[test]
fn ik_msg1_len() {
    // SPEC.md §2.3 / Named constants: IK_MSG1_LEN / IK_MSG2_LEN = 174 / 81 B.
    assert_eq!(IK_MSG1_LEN, 174);
}

#[test]
fn ik_msg2_len() {
    // SPEC.md §2.3 / Named constants: IK_MSG1_LEN / IK_MSG2_LEN = 174 / 81 B.
    assert_eq!(IK_MSG2_LEN, 81);
}

#[test]
fn init_packet_len() {
    // SPEC.md §2.3 / Named constants: INIT_PACKET_LEN / RESP_PACKET_LEN = 196 / 107 B.
    assert_eq!(INIT_PACKET_LEN, 196);
}

#[test]
fn resp_packet_len() {
    // SPEC.md §2.3 / Named constants: INIT_PACKET_LEN / RESP_PACKET_LEN = 196 / 107 B.
    assert_eq!(RESP_PACKET_LEN, 107);
}

// ---------------------------------------------------------------------
// §5.1 / §5.2 — handshake prologue and mac1
// ---------------------------------------------------------------------

#[test]
fn prologue() {
    // SPEC.md §5.1 / Named constants: PROLOGUE = b"slither\x01".
    assert_eq!(PROLOGUE, b"slither\x01");
}

#[test]
fn timestamp_len() {
    // SPEC.md §5.2 / Named constants: TIMESTAMP_LEN / MSG1_PAYLOAD_LEN = 12 / 12 B.
    assert_eq!(TIMESTAMP_LEN, 12);
}

#[test]
fn mac1_label() {
    // SPEC.md §4.1 / Named constants: MAC1_LABEL / MAC1_LEN = b"slither mac1" / 16 B.
    assert_eq!(MAC1_LABEL, b"slither mac1");
}

#[test]
fn mac1_len() {
    // SPEC.md §4.1 / Named constants: MAC1_LABEL / MAC1_LEN = b"slither mac1" / 16 B.
    assert_eq!(MAC1_LEN, 16);
}

// ---------------------------------------------------------------------
// §5.5 — handshake retransmit / give-up
// ---------------------------------------------------------------------

#[test]
fn retransmit_base() {
    // SPEC.md §5.5 / Named constants: RETRANSMIT_BASE / RETRANSMIT_JITTER_MAX = 5 s / 333 ms.
    assert_eq!(RETRANSMIT_BASE, Duration::from_secs(5));
}

#[test]
fn retransmit_jitter_max() {
    // SPEC.md §5.5 / Named constants: RETRANSMIT_BASE / RETRANSMIT_JITTER_MAX = 5 s / 333 ms.
    assert_eq!(RETRANSMIT_JITTER_MAX, Duration::from_millis(333));
}

#[test]
fn handshake_giveup() {
    // SPEC.md §5.5 / Named constants: HANDSHAKE_GIVEUP = 90 s.
    assert_eq!(HANDSHAKE_GIVEUP, Duration::from_secs(90));
}

// ---------------------------------------------------------------------
// §6.3 — Intro parking
// ---------------------------------------------------------------------

#[test]
fn intro_queue_cap() {
    // SPEC.md §6.3 / Named constants: INTRO_QUEUE_CAP / INTRO_MAX_PER_SOURCE / INTRO_TTL = 1024 / 4 / 15 s.
    assert_eq!(INTRO_QUEUE_CAP, 1024);
}

#[test]
fn intro_max_per_source() {
    // SPEC.md §6.3 / Named constants: INTRO_QUEUE_CAP / INTRO_MAX_PER_SOURCE / INTRO_TTL = 1024 / 4 / 15 s.
    assert_eq!(INTRO_MAX_PER_SOURCE, 4);
}

#[test]
fn intro_ttl() {
    // SPEC.md §6.3 / Named constants: INTRO_QUEUE_CAP / INTRO_MAX_PER_SOURCE / INTRO_TTL = 1024 / 4 / 15 s.
    assert_eq!(INTRO_TTL, Duration::from_secs(15));
}

// ---------------------------------------------------------------------
// §7.2 / §7.3 / §7.5 / §7.7 — datagram session: replay, roaming, liveness, rekey
// ---------------------------------------------------------------------

#[test]
fn replay_window() {
    // SPEC.md §7.2 / Named constants: REPLAY_WINDOW = 2048 bits.
    assert_eq!(REPLAY_WINDOW, 2048);
}

#[test]
fn amplification_factor() {
    // SPEC.md §7.3 / Named constants: AMPLIFICATION_FACTOR = 3 (x authenticated bytes received).
    assert_eq!(AMPLIFICATION_FACTOR, 3);
}

#[test]
fn keepalive_timeout() {
    // SPEC.md §7.5 / Named constants: KEEPALIVE_TIMEOUT / DEAD_TIMEOUT = 10 s / 25 s.
    assert_eq!(KEEPALIVE_TIMEOUT, Duration::from_secs(10));
}

#[test]
fn dead_timeout() {
    // SPEC.md §7.5 / Named constants: KEEPALIVE_TIMEOUT / DEAD_TIMEOUT = 10 s / 25 s.
    assert_eq!(DEAD_TIMEOUT, Duration::from_secs(25));
}

#[test]
fn persistent_keepalive_default() {
    // SPEC.md §7.5 / Named constants: PERSISTENT_KEEPALIVE default = 10 s.
    assert_eq!(PERSISTENT_KEEPALIVE_DEFAULT, Duration::from_secs(10));
}

#[test]
fn persistent_keepalive_min() {
    // SPEC.md §7.5 / Named constants: admissible range [1 s, DEAD_TIMEOUT) — floor is 1 s (ruling 42).
    assert_eq!(PERSISTENT_KEEPALIVE_MIN, Duration::from_secs(1));
}

#[test]
fn rekey_epoch_msgs() {
    // SPEC.md §7.7 / Named constants: REKEY_EPOCH_MSGS / MAX_EPOCH_JUMP = 65 536 / 2 (hiss-fixed).
    assert_eq!(REKEY_EPOCH_MSGS, 65_536);
}

#[test]
fn max_epoch_jump() {
    // SPEC.md §7.7 / Named constants: REKEY_EPOCH_MSGS / MAX_EPOCH_JUMP = 65 536 / 2 (hiss-fixed).
    assert_eq!(MAX_EPOCH_JUMP, 2);
}

// ---------------------------------------------------------------------
// §8.3 — the frame table (SPEC.md §8.3's own registry, cited as `Home` by
// the consolidated table's compressed "frame types" row: 0x00, 0x01, 0x02,
// 0x04, 0x08-0x0f, 0x10-0x13, 0x1a, 0x1b, 0x1c, 0x30/0x31; 0x05 reserved)
//
// **[ruling 208]** `0x1a` PATH_CHALLENGE and `0x1b` PATH_RESPONSE were
// added to §8.3 on 2026/08/16 — the first wire change since v1 froze.
// `CONTRACT-7b.md` §1.1 names this comment as one of *three* lists that
// enumerate §8.3 and therefore go stale together (the other two are
// `constants.rs`'s uniqueness table and `frame.rs`'s inline
// `ack_eliciting_matches_the_whole_of_table_8_3`). Working rule 8 reads
// each of them as exhaustive whether or not it says so.
// ---------------------------------------------------------------------

#[test]
fn frame_padding() {
    // SPEC.md §8.3: `0x00` | PADDING.
    assert_eq!(FRAME_PADDING, 0x00);
}

#[test]
fn frame_ping() {
    // SPEC.md §8.3: `0x01` | PING.
    assert_eq!(FRAME_PING, 0x01);
}

#[test]
fn frame_ack() {
    // SPEC.md §8.3: `0x02` | ACK.
    assert_eq!(FRAME_ACK, 0x02);
}

#[test]
fn frame_reset_stream() {
    // SPEC.md §8.3: `0x04` | RESET_STREAM.
    assert_eq!(FRAME_RESET_STREAM, 0x04);
}

#[test]
fn frame_stop_sending_reserved() {
    // SPEC.md §8.3: `0x05` | (reserved: STOP_SENDING).
    assert_eq!(FRAME_STOP_SENDING_RESERVED, 0x05);
}

#[test]
fn frame_stream_base() {
    // SPEC.md §8.3: `0x08`-`0x0f` | STREAM (base of the flagged range).
    assert_eq!(FRAME_STREAM_BASE, 0x08);
}

#[test]
fn frame_stream_max() {
    // SPEC.md §8.3: `0x08`-`0x0f` | STREAM (top of the flagged range).
    assert_eq!(FRAME_STREAM_MAX, 0x0f);
}

#[test]
fn frame_max_data() {
    // SPEC.md §8.3: `0x10` | MAX_DATA.
    assert_eq!(FRAME_MAX_DATA, 0x10);
}

#[test]
fn frame_max_stream_data() {
    // SPEC.md §8.3: `0x11` | MAX_STREAM_DATA.
    assert_eq!(FRAME_MAX_STREAM_DATA, 0x11);
}

#[test]
fn frame_max_streams_bidi() {
    // SPEC.md §8.3: `0x12` | MAX_STREAMS_BIDI.
    assert_eq!(FRAME_MAX_STREAMS_BIDI, 0x12);
}

#[test]
fn frame_max_streams_uni() {
    // SPEC.md §8.3: `0x13` | MAX_STREAMS_UNI.
    assert_eq!(FRAME_MAX_STREAMS_UNI, 0x13);
}

#[test]
fn frame_close() {
    // SPEC.md §8.3: `0x1c` | CLOSE.
    assert_eq!(FRAME_CLOSE, 0x1c);
}

#[test]
fn frame_datagram() {
    // SPEC.md §8.3: `0x30`/`0x31` | DATAGRAM (0x30 = no length field).
    assert_eq!(FRAME_DATAGRAM, 0x30);
}

#[test]
fn frame_datagram_len() {
    // SPEC.md §8.3: `0x30`/`0x31` | DATAGRAM (0x31 = length field present).
    assert_eq!(FRAME_DATAGRAM_LEN, 0x31);
}

// ---------------------------------------------------------------------
// §8.4 — STREAM frame flags and CLOSE reason cap
// ---------------------------------------------------------------------

#[test]
fn stream_off() {
    // SPEC.md §8.4 / Named constants: STREAM_OFF / STREAM_LEN / STREAM_FIN = 0x04 / 0x02 / 0x01.
    assert_eq!(STREAM_OFF, 0x04);
}

#[test]
fn stream_len() {
    // SPEC.md §8.4 / Named constants: STREAM_OFF / STREAM_LEN / STREAM_FIN = 0x04 / 0x02 / 0x01.
    assert_eq!(STREAM_LEN, 0x02);
}

#[test]
fn stream_fin() {
    // SPEC.md §8.4 / Named constants: STREAM_OFF / STREAM_LEN / STREAM_FIN = 0x04 / 0x02 / 0x01.
    assert_eq!(STREAM_FIN, 0x01);
}

#[test]
fn stream_flag_mask() {
    // SPEC.md §8.4: not given a bare literal in the consolidated table; it is
    // the union of the three flag bits listed there (0x04 | 0x02 | 0x01).
    // See also `stream_flag_mask_is_union_of_flags` below for the derivation
    // asserted independently of this literal.
    assert_eq!(STREAM_FLAG_MASK, 0x07);
}

#[test]
fn close_reason_max() {
    // SPEC.md §8.4 / Named constants: CLOSE_REASON_MAX = 256 B.
    assert_eq!(CLOSE_REASON_MAX, 256);
}

// ---------------------------------------------------------------------
// §9.8 — message mode
// ---------------------------------------------------------------------

#[test]
fn message_recv_max() {
    // SPEC.md §9.8 / Named constants: MESSAGE_RECV_MAX = INITIAL_MAX_STREAM_DATA.
    assert_eq!(MESSAGE_RECV_MAX, 262_144);
}

// ---------------------------------------------------------------------
// §10.2 / §10.3 / §10.4 / §10.6 — flow control and stream limits
//
// **[RATIFIED 2026/08/15 — ruling 103]** These pins are three kinds of
// thing and this file's uniform treatment used to imply one. Marked, and
// **no asserted value changes** — the point of the ruling is that moving one
// would be wire-pin churn for nothing:
//
//   * the four initial windows are **wire constants**: unnegotiated, so a
//     red here needs a ruling, not an updated expectation;
//   * `STREAMS_CREDIT_BATCH` and `CREDIT_REGRANT_DIVISOR` are **receiver
//     policy, invisible** — two peers running different values interoperate
//     perfectly. A red here is a *tuning* decision, and does not need a
//     ratification round;
//   * `REASSEMBLY_CHUNKS_MAX` is **receiver policy, observable** — still
//     policy, but a peer can tell, because being killed past one receiver's
//     ceiling and not past another's is externally visible. Shipped
//     ratified-but-revisitable, and a tolerance.
// ---------------------------------------------------------------------

#[test]
fn initial_max_data() {
    // SPEC.md §10.2 / Named constants: INITIAL_MAX_DATA = 1 048 576 B (1 MiB).
    // Kind: **wire constant** (ruling 103).
    assert_eq!(INITIAL_MAX_DATA, 1_048_576);
}

#[test]
fn initial_max_stream_data() {
    // SPEC.md §10.2 / Named constants: INITIAL_MAX_STREAM_DATA = 262 144 B (256 KiB).
    // Kind: **wire constant** (ruling 103).
    assert_eq!(INITIAL_MAX_STREAM_DATA, 262_144);
}

#[test]
fn initial_max_streams_bidi() {
    // SPEC.md §10.2 / Named constants: INITIAL_MAX_STREAMS_BIDI / _UNI = 32 / 128 (cumulative).
    // Kind: **wire constant** (ruling 103).
    assert_eq!(INITIAL_MAX_STREAMS_BIDI, 32);
}

#[test]
fn initial_max_streams_uni() {
    // SPEC.md §10.2 / Named constants: INITIAL_MAX_STREAMS_BIDI / _UNI = 32 / 128 (cumulative).
    // Kind: **wire constant** (ruling 103).
    assert_eq!(INITIAL_MAX_STREAMS_UNI, 128);
}

#[test]
fn streams_credit_batch() {
    // SPEC.md §10.4 / Named constants: STREAMS_CREDIT_BATCH = 8.
    // Kind: **receiver policy, invisible** (ruling 103) — and §10.4's two
    // triggers are both this one constant (ruling 102).
    assert_eq!(STREAMS_CREDIT_BATCH, 8);
}

#[test]
fn credit_regrant_divisor() {
    // SPEC.md §10.3 / Named constants: "credit re-grant threshold | ½ window
    // consumed". Not given a bare literal; the divisor implied by "half" is 2.
    // Kind: **receiver policy, invisible** — ruling 103 classifies §10.2's
    // five rows and §10.6's ceiling and does not reach this one; it is the
    // same kind as STREAMS_CREDIT_BATCH by the same argument.
    assert_eq!(CREDIT_REGRANT_DIVISOR, 2);
}

#[test]
fn reassembly_chunks_max() {
    // SPEC.md §10.6 / Named constants: REASSEMBLY_CHUNKS_MAX = 1024 stored discontiguous ranges per stream.
    // Kind: **receiver policy, observable** (ruling 103) — a tolerance, and
    // the §10 violation §10.5 omits (ruling 104).
    assert_eq!(REASSEMBLY_CHUNKS_MAX, 1024);
}

// ---------------------------------------------------------------------
// §11.2 / §11.3 — datagrams
// ---------------------------------------------------------------------

#[test]
fn max_datagram_payload() {
    // SPEC.md §11.2 / Named constants: MAX_DATAGRAM_PAYLOAD = 1169 B (= MAX_PLAINTEXT - 1).
    assert_eq!(MAX_DATAGRAM_PAYLOAD, 1169);
}

#[test]
fn datagram_send_queue() {
    // SPEC.md §11.3 / Named constants: DATAGRAM_SEND_QUEUE / DATAGRAM_RECV_QUEUE = 64 / 64.
    assert_eq!(DATAGRAM_SEND_QUEUE, 64);
}

#[test]
fn datagram_recv_queue() {
    // SPEC.md §11.3 / Named constants: DATAGRAM_SEND_QUEUE / DATAGRAM_RECV_QUEUE = 64 / 64.
    assert_eq!(DATAGRAM_RECV_QUEUE, 64);
}

// ---------------------------------------------------------------------
// §12.2 / §12.4 — ACKs
// ---------------------------------------------------------------------

#[test]
fn max_ack_ranges() {
    // SPEC.md §12.2 / Named constants: MAX_ACK_RANGES = 64.
    assert_eq!(MAX_ACK_RANGES, 64);
}

#[test]
fn ack_eliciting_per_ack() {
    // SPEC.md §12.4 / Named constants: "ACK policy | every 2nd ack-eliciting, ...".
    assert_eq!(ACK_ELICITING_PER_ACK, 2);
}

#[test]
fn max_ack_delay() {
    // SPEC.md §12.4 / §13.3 / Named constants: MAX_ACK_DELAY = 25 ms.
    assert_eq!(MAX_ACK_DELAY, Duration::from_millis(25));
}

// ---------------------------------------------------------------------
// §13.1 / §13.2 / §13.3 — loss detection
// ---------------------------------------------------------------------

#[test]
fn k_packet_threshold() {
    // SPEC.md §13.2 / Named constants: K_PACKET_THRESHOLD / time threshold / K_GRANULARITY = 3 / 9/8 / 1 ms.
    assert_eq!(K_PACKET_THRESHOLD, 3);
}

#[test]
fn k_time_threshold_num() {
    // SPEC.md §13.2 / Named constants: time threshold = 9/8.
    assert_eq!(K_TIME_THRESHOLD_NUM, 9);
}

#[test]
fn k_time_threshold_den() {
    // SPEC.md §13.2 / Named constants: time threshold = 9/8.
    assert_eq!(K_TIME_THRESHOLD_DEN, 8);
}

#[test]
fn k_granularity() {
    // SPEC.md §13.2 / Named constants: K_GRANULARITY = 1 ms.
    assert_eq!(K_GRANULARITY, Duration::from_millis(1));
}

#[test]
fn k_initial_rtt() {
    // SPEC.md §13.1 / Named constants: K_INITIAL_RTT / PTO_BACKOFF_CAP = 333 ms / 2^3.
    assert_eq!(K_INITIAL_RTT, Duration::from_millis(333));
}

#[test]
fn pto_backoff_cap() {
    // SPEC.md §13.3 / Named constants: K_INITIAL_RTT / PTO_BACKOFF_CAP = 333 ms / 2^3.
    // [RATIFIED 2026/08/17 — ruling 254] 2^6 until this ruling.
    // The constant is the **multiplier**, not the exponent: a build storing
    // 3 here and shifting by it is the transcription ruling 254 says is now
    // silent (`1u32 << 8` = 256 is legal), so the value is asserted whole.
    assert_eq!(PTO_BACKOFF_CAP, 8);
}

// ---------------------------------------------------------------------
// §14.2 / §14.4 — congestion control
// ---------------------------------------------------------------------

#[test]
fn initial_window() {
    // SPEC.md §14.2 / Named constants: INITIAL_WINDOW / MINIMUM_WINDOW = 12 000 / 2 400 B.
    assert_eq!(INITIAL_WINDOW, 12_000);
}

#[test]
fn minimum_window() {
    // SPEC.md §14.2 / Named constants: INITIAL_WINDOW / MINIMUM_WINDOW = 12 000 / 2 400 B.
    assert_eq!(MINIMUM_WINDOW, 2_400);
}

#[test]
fn loss_reduction_factor() {
    // SPEC.md §14.2 / Named constants: LOSS_REDUCTION_FACTOR / PERSISTENT_CONGESTION_THRESHOLD = 0.5 / 3.
    assert_eq!(LOSS_REDUCTION_FACTOR, 0.5);
}

#[test]
fn persistent_congestion_threshold() {
    // SPEC.md §14.4 / Named constants: LOSS_REDUCTION_FACTOR / PERSISTENT_CONGESTION_THRESHOLD = 0.5 / 3.
    assert_eq!(PERSISTENT_CONGESTION_THRESHOLD, 3);
}

// ---------------------------------------------------------------------
// §15.1 — close and linger
// ---------------------------------------------------------------------

#[test]
fn close_linger() {
    // SPEC.md §15.1 / Named constants: CLOSE_LINGER / close-reply rate = 5 s / <= 1 per s.
    assert_eq!(CLOSE_LINGER, Duration::from_secs(5));
}

#[test]
fn close_reply_min_interval() {
    // SPEC.md §15.1 / Named constants: close-reply rate <= 1 per s, i.e. replies
    // are spaced at least 1 s apart. Not given a bare literal in the table.
    assert_eq!(CLOSE_REPLY_MIN_INTERVAL, Duration::from_secs(1));
}

// ---------------------------------------------------------------------
// §15.3 — error-code registry
// ---------------------------------------------------------------------

#[test]
fn no_error() {
    // SPEC.md §15.3: `0x00` | NO_ERROR.
    assert_eq!(NO_ERROR, 0x00);
}

#[test]
fn protocol_violation() {
    // SPEC.md §15.3: `0x01` | PROTOCOL_VIOLATION.
    assert_eq!(PROTOCOL_VIOLATION, 0x01);
}

#[test]
fn flow_control_error() {
    // SPEC.md §15.3: `0x02` | FLOW_CONTROL_ERROR.
    assert_eq!(FLOW_CONTROL_ERROR, 0x02);
}

#[test]
fn stream_limit_error() {
    // SPEC.md §15.3: `0x03` | STREAM_LIMIT_ERROR.
    assert_eq!(STREAM_LIMIT_ERROR, 0x03);
}

#[test]
fn stream_state_error() {
    // SPEC.md §15.3: `0x04` | STREAM_STATE_ERROR.
    assert_eq!(STREAM_STATE_ERROR, 0x04);
}

#[test]
fn final_size_error() {
    // SPEC.md §15.3: `0x05` | FINAL_SIZE_ERROR.
    assert_eq!(FINAL_SIZE_ERROR, 0x05);
}

#[test]
fn message_overflow() {
    // SPEC.md §15.3: `0x06` | MESSAGE_OVERFLOW — ratified 2026/08/14, ruling 52.
    // As of this ruling's landing, both §15.3 and the consolidated table read
    // 0x00-0x06 (previously 0x00-0x05); §18.1 flags that the two restating
    // spots (this table and its own prose) needed the same update. No
    // disagreement was found between them as read here.
    assert_eq!(MESSAGE_OVERFLOW, 0x06);
}

#[test]
fn application_error_base() {
    // SPEC.md §15.3: codes >= 0x10 are application-defined via close().
    assert_eq!(APPLICATION_ERROR_BASE, 0x10);
}

// ---------------------------------------------------------------------
// §16.5 — time and timers (shell)
// ---------------------------------------------------------------------

#[test]
fn shell_lateness_bound() {
    // SPEC.md §16.5 / Named constants: `L` (shell lateness bound) = 250 ms.
    assert_eq!(SHELL_LATENESS_BOUND, Duration::from_millis(250));
}

// ---------------------------------------------------------------------
// §17.1 — replay guard orphan cap
// ---------------------------------------------------------------------

#[test]
fn ts_guard_orphan_cap() {
    // SPEC.md §17.1 / Named constants: TS_GUARD_ORPHAN_CAP = 1024.
    assert_eq!(TS_GUARD_ORPHAN_CAP, 1024);
}

// =======================================================================
// Derived relationships — asserted independently of the literals above.
// A wrong literal that happens to be internally self-consistent would slip
// past the tests above only if the *same* wrong value were used everywhere
// it appears; these tests instead recompute one constant from others and
// check the result, which is a different failure mode than "copied the
// table wrong."
// =======================================================================

#[test]
fn max_plaintext_is_datagram_minus_header_minus_tag() {
    // SPEC.md §3.5: MAX_PLAINTEXT is what remains of MAX_DATAGRAM after the
    // 14-byte Data header and the 16-byte AEAD tag.
    assert_eq!(MAX_PLAINTEXT, MAX_DATAGRAM - DATA_HEADER_LEN - AEAD_TAG_LEN);
}

#[test]
fn max_datagram_payload_is_max_plaintext_minus_one() {
    // SPEC.md §11.2: MAX_DATAGRAM_PAYLOAD = MAX_PLAINTEXT - 1 (the DATAGRAM
    // frame's type byte's LEN variant still needs to fit in the remaining
    // plaintext budget after the frame-type/length overhead).
    assert_eq!(MAX_DATAGRAM_PAYLOAD, MAX_PLAINTEXT - 1);
}

#[test]
fn init_packet_len_is_header_plus_msg1_plus_mac1() {
    // SPEC.md §2.3: INIT_PACKET_LEN = 6 + MSG1_LEN + 16 (InitHeader | msg1 | mac1).
    assert_eq!(INIT_PACKET_LEN, INIT_HEADER_LEN + IK_MSG1_LEN + MAC1_LEN);
}

#[test]
fn resp_packet_len_is_header_plus_msg2_plus_mac1() {
    // SPEC.md §2.3: RESP_PACKET_LEN = 10 + MSG2_LEN + 16 (RespHeader | msg2 | mac1).
    assert_eq!(RESP_PACKET_LEN, RESP_HEADER_LEN + IK_MSG2_LEN + MAC1_LEN);
}

#[test]
fn ik_msg1_len_is_two_statics_two_tags_plus_payload() {
    // SPEC.md §2.3: MSG1_LEN = PK + (PK + TAG) + (MSG1_PAYLOAD_LEN + TAG)
    // (e || enc_s || enc_payload) = 2*PK + 2*TAG + MSG1_PAYLOAD_LEN.
    assert_eq!(
        IK_MSG1_LEN,
        2 * STATIC_PUBLIC_LEN + 2 * AEAD_TAG_LEN + MSG1_PAYLOAD_LEN
    );
}

#[test]
fn ik_msg2_len_is_one_static_plus_tag() {
    // SPEC.md §2.3: MSG2_LEN = PK + TAG (e || the empty payload's tag).
    assert_eq!(IK_MSG2_LEN, STATIC_PUBLIC_LEN + AEAD_TAG_LEN);
}

#[test]
fn dead_timeout_is_twice_keepalive_plus_five_seconds() {
    // SPEC.md §7.5: liveness fires at DEAD_TIMEOUT, and the contested-probe
    // path (§7.5, rulings 36/41) ties the 25 s figure to 2x KEEPALIVE_TIMEOUT
    // (10 s) plus the 5 s the probe/verdict machinery allows on top.
    assert_eq!(DEAD_TIMEOUT, 2 * KEEPALIVE_TIMEOUT + Duration::from_secs(5));
}

#[test]
fn message_recv_max_equals_initial_max_stream_data() {
    // SPEC.md §9.8 / Named constants: "MESSAGE_RECV_MAX | = INITIAL_MAX_STREAM_DATA".
    assert_eq!(MESSAGE_RECV_MAX, INITIAL_MAX_STREAM_DATA);
}

#[test]
fn stream_flag_mask_is_union_of_flags() {
    // SPEC.md §8.4: the STREAM frame's flag byte is built from STREAM_OFF /
    // STREAM_LEN / STREAM_FIN; the mask covering all three is their bitwise OR.
    assert_eq!(STREAM_FLAG_MASK, STREAM_OFF | STREAM_LEN | STREAM_FIN);
}

#[test]
fn frame_stream_max_is_base_or_flag_mask() {
    // SPEC.md §8.3/§8.4: the STREAM frame type range 0x08-0x0f is the base
    // type with every combination of the three flag bits set; the top of the
    // range is the base OR'd with the full flag mask.
    assert_eq!(FRAME_STREAM_MAX, FRAME_STREAM_BASE | STREAM_FLAG_MASK);
}

#[test]
fn persistent_keepalive_default_is_within_admissible_range() {
    // SPEC.md §7.5: admissible range is [1 s, DEAD_TIMEOUT); the 10 s default
    // must fall inside the range its own setter would accept.
    assert!(PERSISTENT_KEEPALIVE_DEFAULT >= PERSISTENT_KEEPALIVE_MIN);
    assert!(PERSISTENT_KEEPALIVE_DEFAULT < DEAD_TIMEOUT);
}

#[test]
fn wire_error_codes_are_all_below_application_base() {
    // SPEC.md §15.3: 0x00-0x06 are transport codes, 0x07-0x0f are reserved,
    // and application codes begin at 0x10 — every named transport code must
    // sit strictly below APPLICATION_ERROR_BASE.
    assert!(NO_ERROR < APPLICATION_ERROR_BASE);
    assert!(PROTOCOL_VIOLATION < APPLICATION_ERROR_BASE);
    assert!(FLOW_CONTROL_ERROR < APPLICATION_ERROR_BASE);
    assert!(STREAM_LIMIT_ERROR < APPLICATION_ERROR_BASE);
    assert!(STREAM_STATE_ERROR < APPLICATION_ERROR_BASE);
    assert!(FINAL_SIZE_ERROR < APPLICATION_ERROR_BASE);
    assert!(MESSAGE_OVERFLOW < APPLICATION_ERROR_BASE);
}

// ---------------------------------------------------------------------
// §8.3 / §8.4 / §7.3 — ruling 208's two path-validation frames
//
// **[ruling 208, RATIFIED 2026/08/16]** The first wire change since v1
// froze. Ruling 210(d) is the governing constraint on *this* file: the
// change "adds two *new* type codes and moves **no existing byte**, so
// every golden vector must stay byte-identical." Every test below is
// written to fail if that stops being true.
//
// Written by the blind test author against `CONTRACT-7b.md` §1.1 and §10,
// and `SPEC.md` §8.3:3267-3268, §8.4:3429-3470, §7.3:2204-2213.
// ---------------------------------------------------------------------

#[test]
fn frame_path_challenge() {
    // SPEC.md §8.3:3267: `0x1a` | PATH_CHALLENGE | data (8 opaque bytes,
    // **not** a varint) | ack-eliciting yes | rtx never | home §7.3.
    // Ruling 208: "`0x1a`/`0x1b` are QUIC's own code points for these two
    // frames" (RFC 9000 §19.17/§19.18).
    assert_eq!(FRAME_PATH_CHALLENGE, 0x1a);
}

#[test]
fn frame_path_response() {
    // SPEC.md §8.3:3268: `0x1b` | PATH_RESPONSE.
    assert_eq!(FRAME_PATH_RESPONSE, 0x1b);
}

#[test]
fn path_frames_are_distinct_and_ordered() {
    // The two `assert_eq!`s above are in separate `#[test]`s by this file's
    // design, so neither can see the other's value. The degenerate build
    // this catches and they do not: one `const` copy-pasted and edited in
    // only one place, leaving `CHALLENGE == RESPONSE` — under which a
    // responder echoes a challenge as a challenge, forever.
    assert_ne!(FRAME_PATH_CHALLENGE, FRAME_PATH_RESPONSE);
    assert!(FRAME_PATH_CHALLENGE < FRAME_PATH_RESPONSE);
    assert_eq!(FRAME_PATH_RESPONSE, FRAME_PATH_CHALLENGE + 1);
}

#[test]
fn path_frame_codes_collide_with_no_existing_frame_type() {
    // **This is the ruling-210(d) pin, and the one test here that catches a
    // *missed* edit rather than a wrong one.**
    //
    // `CONTRACT-7b.md` §1.1, of `constants.rs:670-683`'s FRAME_* uniqueness
    // table: "Nothing fails if it is missed; that is what makes it a
    // defect." This test is the thing that fails. A build that reused a
    // code already in the table — `0x1c` CLOSE is the nearest neighbour and
    // an easy typo — turns this red, and no golden-wire vector would.
    //
    // Working rule 8: §8.3's table is read as exhaustive, so every named
    // code in the crate is listed here and the list is the assertion.
    let existing: [u64; 14] = [
        FRAME_PADDING,
        FRAME_PING,
        FRAME_ACK,
        FRAME_RESET_STREAM,
        FRAME_STOP_SENDING_RESERVED,
        FRAME_STREAM_BASE,
        FRAME_STREAM_MAX,
        FRAME_MAX_DATA,
        FRAME_MAX_STREAM_DATA,
        FRAME_MAX_STREAMS_BIDI,
        FRAME_MAX_STREAMS_UNI,
        FRAME_CLOSE,
        FRAME_DATAGRAM,
        FRAME_DATAGRAM_LEN,
    ];
    for code in existing {
        assert_ne!(
            code, FRAME_PATH_CHALLENGE,
            "PATH_CHALLENGE (0x1a) collides with an existing §8.3 frame code",
        );
        assert_ne!(
            code, FRAME_PATH_RESPONSE,
            "PATH_RESPONSE (0x1b) collides with an existing §8.3 frame code",
        );
    }
    // The STREAM entry is a *range*, not a point, so membership in it is
    // not covered by the pairwise check above.
    for code in [FRAME_PATH_CHALLENGE, FRAME_PATH_RESPONSE] {
        assert!(
            !(FRAME_STREAM_BASE..=FRAME_STREAM_MAX).contains(&code),
            "a path frame code fell inside §8.3's 0x08-0x0f STREAM range",
        );
    }
}

#[test]
fn no_existing_frame_code_moved_for_ruling_208() {
    // **Ruling 210(d), stated as a test.** "My 'the wire vectors will go red
    // by design' licence is withdrawn... every golden vector must stay
    // byte-identical." The per-constant tests above each pin one code; this
    // pins the *set*, so a build that renumbered the table to "make room"
    // for 0x1a/0x1b fails here under one readable name rather than as a
    // scatter of apparently unrelated reds.
    assert_eq!(FRAME_PADDING, 0x00);
    assert_eq!(FRAME_PING, 0x01);
    assert_eq!(FRAME_ACK, 0x02);
    assert_eq!(FRAME_RESET_STREAM, 0x04);
    assert_eq!(FRAME_STOP_SENDING_RESERVED, 0x05);
    assert_eq!(FRAME_STREAM_BASE, 0x08);
    assert_eq!(FRAME_STREAM_MAX, 0x0f);
    assert_eq!(FRAME_MAX_DATA, 0x10);
    assert_eq!(FRAME_MAX_STREAM_DATA, 0x11);
    assert_eq!(FRAME_MAX_STREAMS_BIDI, 0x12);
    assert_eq!(FRAME_MAX_STREAMS_UNI, 0x13);
    assert_eq!(FRAME_CLOSE, 0x1c);
    assert_eq!(FRAME_DATAGRAM, 0x30);
    assert_eq!(FRAME_DATAGRAM_LEN, 0x31);
}

#[test]
fn path_frame_codes_encode_as_a_one_byte_varint() {
    // SPEC.md §8.4:3435-3437: "Nine bytes each, fixed: no length prefix and
    // no varint anywhere". `CONTRACT-7b.md` §1.1's table derives
    // `encoded_len() == 9` from "both codes are < 64 so the varint is one
    // byte".
    //
    // **Working rule 9.** Nine bytes is a *derived* quantity and this bound
    // is what it derives from. A build that chose `0x40`/`0x41` would still
    // be "two new unused code points" and would still pass every uniqueness
    // check above, but each frame would encode in ten bytes and §7.3's
    // 90-byte no-deadlock arithmetic would be wrong by construction. This
    // is the assertion that separates them.
    assert!(FRAME_PATH_CHALLENGE < 64);
    assert!(FRAME_PATH_RESPONSE < 64);
}

#[test]
fn a_path_challenge_datagram_fits_the_smallest_budget_its_arming_creates() {
    // **[ruling 208 / `CONTRACT-7b.md` §1.6]** "The challenge must fit
    // inside the budget its own arming creates, or an address roamed to by
    // a bare keepalive can never be validated."
    //
    // SPEC.md §7.3:2241-2247 states the arithmetic normatively: "3x the
    // *smallest* packet that can arm the budget — §7.5's 30-byte keepalive,
    // 90 B — still admits a packet carrying the challenge, which costs 14 B
    // of header, 9 B of frame and a 16 B tag."
    //
    // The contract asks for this as a `const _: () = assert!(..)` in
    // `constants.rs` — the *implementer's* file. This is the runtime twin in
    // the test author's file, so the pin exists on both sides of the blind
    // split and neither agent's omission can hide it.
    let smallest_arming_credit = DATA_HEADER_LEN + AEAD_TAG_LEN;
    let budget = AMPLIFICATION_FACTOR as usize * smallest_arming_credit;
    let challenge_datagram = DATA_HEADER_LEN + 1 + 8 + AEAD_TAG_LEN;

    // The components pinned individually, so a change to any one of them
    // names itself rather than surfacing as a failed inequality.
    assert_eq!(smallest_arming_credit, 30);
    assert_eq!(budget, 90);
    assert_eq!(challenge_datagram, 39);

    // The bound the contract states. Not decoration: it fails if anyone
    // grows `DATA_HEADER_LEN`, shrinks `AMPLIFICATION_FACTOR`, or widens the
    // challenge past 8 bytes.
    assert!(budget >= challenge_datagram);

    // **Working rule 9 applied to the bound itself.** `budget >=
    // challenge_datagram` alone is satisfied for free by many wrong builds,
    // including one with `AMPLIFICATION_FACTOR == 2` (60 >= 39). §7.3 and
    // the contract both claim a *specific* headroom — "51 bytes — room for
    // the challenge *and* an ACK" — and that number is what excludes the
    // satisfied-for-free reading. Asserting it is what makes this test
    // sensitive to the factor at all.
    assert_eq!(budget - challenge_datagram, 51);
}

#[test]
fn a_challenge_and_a_contested_probe_fit_one_arming_together() {
    // SPEC.md §7.3:2409-2412, inside the flagged rank-2/rank-4 interaction:
    // "probe and challenge together cost 14 B of header + 1 B of PING + 9 B
    // of challenge + a 16 B tag = **40 B**, inside the 90 B floor computed
    // above."
    //
    // Load-bearing for ruling 212(c), which resolves that flag by ranking
    // the path frames *above* the probe: the resolution is free of cost only
    // because the two never actually contend ("in practice they do not
    // compete at all"). If this goes red, the rank stops being free and
    // becomes a real trade-off that needs re-deciding.
    let ping = 1;
    let challenge_frame = 1 + 8;
    let both = DATA_HEADER_LEN + ping + challenge_frame + AEAD_TAG_LEN;
    assert_eq!(both, 40);

    let budget = AMPLIFICATION_FACTOR as usize * (DATA_HEADER_LEN + AEAD_TAG_LEN);
    assert!(both <= budget);
    // The two-sided form again: `40 <= 60` holds for a degenerate factor of
    // 2. The spec's claim is the 90 B floor.
    assert_eq!(budget, 90);
}

#[test]
fn the_msg1_anchor_budget_still_admits_a_challenge_after_the_msg2_charge() {
    // **[`CONTRACT-7b.md` §2, finding A2]** The responder's msg2 —
    // `RESP_PACKET_LEN` = 107 bytes — is emitted before the connection
    // exists and is now charged to the budget its own arming created. §2's
    // arithmetic: "588 - 107 = 481, against 39 for a challenge datagram. It
    // does."
    //
    // The contract says "no second assertion is needed, but the arithmetic
    // belongs in a comment". A comment is not a pin — working rule 9's "a
    // name is not a pin", one register up — and this arithmetic decides
    // whether a responder-side connection can ever validate its own anchor.
    // It is cheap, so it is here.
    let anchor_credit = INIT_PACKET_LEN;
    let budget = AMPLIFICATION_FACTOR as usize * anchor_credit;
    assert_eq!(budget, 588);

    let after_msg2 = budget - RESP_PACKET_LEN;
    assert_eq!(after_msg2, 481);

    let challenge_datagram = DATA_HEADER_LEN + 1 + 8 + AEAD_TAG_LEN;
    assert!(after_msg2 >= challenge_datagram);
    // The separating form: a build that charged msg2 *and* msg1 (196 + 107 =
    // 303) still satisfies `>= 39`. What it violates is the claim that the
    // charge is exactly one msg2.
    assert_eq!(budget - after_msg2, RESP_PACKET_LEN);
}