-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnested_bytes.rs
More file actions
1981 lines (1662 loc) · 67.2 KB
/
Copy pathnested_bytes.rs
File metadata and controls
1981 lines (1662 loc) · 67.2 KB
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
#![allow(warnings)]
use vest_lib::combinators::mapped::spec::*;
use vest_lib::combinators::recursive::*;
use vest_lib::combinators::*;
use vest_lib::core::exec::bytes_eq;
use vest_lib::core::exec::input::{InputBuf, InputSlice};
use vest_lib::core::exec::output::OutputBuf;
use vest_lib::core::exec::parser::*;
use vest_lib::core::exec::serializer::*;
use vest_lib::core::exec::ParseError;
use vest_lib::core::{proof::*, spec::*};
use vest_lib::primitives::btcvarint::VarInt;
use vest_lib::primitives::leb128::ULeb128;
use vest_lib::Never;
use vstd::prelude::*;
use Sum::Inl as L;
use Sum::Inr as R;
verus! {
// ============================================================
// Data Types
// ============================================================
# [doc = "data type for `anything`."]
# [derive (Debug, PartialEq, Eq, Clone, Copy)]
pub struct Anything {
pub x: u8,
}
# [verifier::ext_equal]
pub struct AnythingSpec<T0 = u8> {
pub x: T0,
}
pub type AnythingInner = u8;
impl DeepView for Anything {
type V = AnythingSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
AnythingSpec { x: self.x.deep_view() }
}
}
impl Anything {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().x == self.x.deep_view(),
{
reveal(<Anything as DeepView>::deep_view);
}
}
impl<T0> AnythingSpec<T0> {
# [verifier::opaque]
pub open spec fn from_structural(input: T0) -> Self {
let x = input;
Self { x }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> T0 {
let Self { x } = self;
x
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(AnythingSpec::from_structural);
reveal(AnythingSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: T0)
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(AnythingSpec::from_structural);
reveal(AnythingSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { x } => x,
},
{
reveal(AnythingSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct AnythingForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct AnythingReverse;
impl SpecMap for AnythingForward {
type Input = AnythingInner;
type Output = AnythingSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
AnythingSpec::from_structural(input)
}
}
impl SpecMap for AnythingReverse {
type Input = AnythingSpec;
type Output = AnythingInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `nested_dynamic_bytes`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct NestedDynamicBytes<'i> {
pub num: u16,
pub num_inner: u16,
pub xs: Vec<&'i [u8]>,
}
# [verifier::ext_equal]
pub struct NestedDynamicBytesSpec<T0 = u16, T1 = u16, T2 = Seq<Seq<u8>>> {
pub num: T0,
pub num_inner: T1,
pub xs: T2,
}
pub type NestedDynamicBytesInner = (u16, (u16, Seq<Seq<u8>>));
impl<'i> DeepView for NestedDynamicBytes<'i> {
type V = NestedDynamicBytesSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
NestedDynamicBytesSpec {
num: self.num.deep_view(),
num_inner: self.num_inner.deep_view(),
xs: self.xs.deep_view(),
}
}
}
impl<'i> NestedDynamicBytes<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().num == self.num.deep_view(),
self.deep_view().num_inner == self.num_inner.deep_view(),
self.deep_view().xs == self.xs.deep_view(),
{
reveal(<NestedDynamicBytes as DeepView>::deep_view);
}
}
impl<T0, T1, T2> NestedDynamicBytesSpec<T0, T1, T2> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, (T1, T2))) -> Self {
let (num, (num_inner, xs)) = input;
Self { num, num_inner, xs }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, (T1, T2)) {
let Self { num, num_inner, xs } = self;
(num, (num_inner, xs))
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(NestedDynamicBytesSpec::from_structural);
reveal(NestedDynamicBytesSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, (T1, T2)))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(NestedDynamicBytesSpec::from_structural);
reveal(NestedDynamicBytesSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { num, num_inner, xs } => (num, (num_inner, xs)),
},
{
reveal(NestedDynamicBytesSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct NestedDynamicBytesForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct NestedDynamicBytesReverse;
impl SpecMap for NestedDynamicBytesForward {
type Input = NestedDynamicBytesInner;
type Output = NestedDynamicBytesSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
NestedDynamicBytesSpec::from_structural(input)
}
}
impl SpecMap for NestedDynamicBytesReverse {
type Input = NestedDynamicBytesSpec;
type Output = NestedDynamicBytesInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `nested_fixed_bytes`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct NestedFixedBytes<'i> {
pub num: u16,
pub xs: Vec<&'i [u8]>,
}
# [verifier::ext_equal]
pub struct NestedFixedBytesSpec<T0 = u16, T1 = Seq<Seq<u8>>> {
pub num: T0,
pub xs: T1,
}
pub type NestedFixedBytesInner = (u16, Seq<Seq<u8>>);
impl<'i> DeepView for NestedFixedBytes<'i> {
type V = NestedFixedBytesSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
NestedFixedBytesSpec { num: self.num.deep_view(), xs: self.xs.deep_view() }
}
}
impl<'i> NestedFixedBytes<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().num == self.num.deep_view(),
self.deep_view().xs == self.xs.deep_view(),
{
reveal(<NestedFixedBytes as DeepView>::deep_view);
}
}
impl<T0, T1> NestedFixedBytesSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, T1)) -> Self {
let (num, xs) = input;
Self { num, xs }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, T1) {
let Self { num, xs } = self;
(num, xs)
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(NestedFixedBytesSpec::from_structural);
reveal(NestedFixedBytesSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, T1))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(NestedFixedBytesSpec::from_structural);
reveal(NestedFixedBytesSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { num, xs } => (num, xs),
},
{
reveal(NestedFixedBytesSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct NestedFixedBytesForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct NestedFixedBytesReverse;
impl SpecMap for NestedFixedBytesForward {
type Input = NestedFixedBytesInner;
type Output = NestedFixedBytesSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
NestedFixedBytesSpec::from_structural(input)
}
}
impl SpecMap for NestedFixedBytesReverse {
type Input = NestedFixedBytesSpec;
type Output = NestedFixedBytesInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `fixed_array_of_bytes`."]
pub type FixedArrayOfBytes<'i> = [&'i [u8]; 3];
pub type FixedArrayOfBytesSpec = Seq<Seq<u8>>;
# [doc = "data type for `vec_of_bytes`."]
pub type VecOfBytes<'i> = Vec<&'i [u8]>;
pub type VecOfBytesSpec = Seq<Seq<u8>>;
# [doc = "data type for `optional_bytes`."]
pub type OptionalBytes<'i> = Option<&'i [u8]>;
pub type OptionalBytesSpec = Option<Seq<u8>>;
# [doc = "data type for `tail_vec`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct TailVec {
pub xs: Vec<Anything>,
}
# [verifier::ext_equal]
pub struct TailVecSpec<T0 = Seq<AnythingSpec>> {
pub xs: T0,
}
pub type TailVecInner = Seq<AnythingSpec>;
impl DeepView for TailVec {
type V = TailVecSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
TailVecSpec { xs: self.xs.deep_view() }
}
}
impl TailVec {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().xs == self.xs.deep_view(),
{
reveal(<TailVec as DeepView>::deep_view);
}
}
impl<T0> TailVecSpec<T0> {
# [verifier::opaque]
pub open spec fn from_structural(input: T0) -> Self {
let xs = input;
Self { xs }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> T0 {
let Self { xs } = self;
xs
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(TailVecSpec::from_structural);
reveal(TailVecSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: T0)
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(TailVecSpec::from_structural);
reveal(TailVecSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { xs } => xs,
},
{
reveal(TailVecSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TailVecForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TailVecReverse;
impl SpecMap for TailVecForward {
type Input = TailVecInner;
type Output = TailVecSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
TailVecSpec::from_structural(input)
}
}
impl SpecMap for TailVecReverse {
type Input = TailVecSpec;
type Output = TailVecInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
// ============================================================
// Format Specifications
// ============================================================
# [doc = "named format combinator for `anything`."]
# [derive (Clone, Copy)]
pub struct AnythingFmt;
pub type AnythingFmtSpec = Named<Mapped<U8, BiMap<AnythingForward, AnythingReverse>>>;
impl AnythingFmt {
# [doc = "specification constructor for `anything`."]
pub open spec fn spec_inner() -> AnythingFmtSpec {
Named("anything", Mapped { inner: U8, mapper: BiMap(AnythingForward, AnythingReverse) })
}
}
# [doc = "named format combinator for `nested_dynamic_bytes`."]
# [derive (Clone, Copy)]
pub struct NestedDynamicBytesFmt;
pub type NestedDynamicBytesFmtSpec = Named<
Mapped<
Bind<U16Le, spec_fn(u16) -> Bind<U16Le, spec_fn(u16) -> RepeatN<Varied<u16>, u16>>>,
BiMap<NestedDynamicBytesForward, NestedDynamicBytesReverse>,
>,
>;
impl NestedDynamicBytesFmt {
# [doc = "specification constructor for `nested_dynamic_bytes`."]
pub open spec fn spec_inner() -> NestedDynamicBytesFmtSpec {
Named(
"nested_dynamic_bytes",
Mapped {
inner: Bind(
U16Le,
|num: u16| Bind(U16Le, |num_inner: u16| RepeatN(num, Varied(num_inner))),
),
mapper: BiMap(NestedDynamicBytesForward, NestedDynamicBytesReverse),
},
)
}
}
# [doc = "named format combinator for `nested_fixed_bytes`."]
# [derive (Clone, Copy)]
pub struct NestedFixedBytesFmt;
pub type NestedFixedBytesFmtSpec = Named<
Mapped<
Bind<U16Le, spec_fn(u16) -> RepeatN<Fixed<10>, u16>>,
BiMap<NestedFixedBytesForward, NestedFixedBytesReverse>,
>,
>;
impl NestedFixedBytesFmt {
# [doc = "specification constructor for `nested_fixed_bytes`."]
pub open spec fn spec_inner() -> NestedFixedBytesFmtSpec {
Named(
"nested_fixed_bytes",
Mapped {
inner: Bind(U16Le, |num: u16| RepeatN(num, Fixed::<10>)),
mapper: BiMap(NestedFixedBytesForward, NestedFixedBytesReverse),
},
)
}
}
# [doc = "named format combinator for `fixed_array_of_bytes`."]
# [derive (Clone, Copy)]
pub struct FixedArrayOfBytesFmt;
pub type FixedArrayOfBytesFmtSpec = Named<Array<3, Fixed<2>>>;
impl FixedArrayOfBytesFmt {
# [doc = "specification constructor for `fixed_array_of_bytes`."]
pub open spec fn spec_inner() -> FixedArrayOfBytesFmtSpec {
Named("fixed_array_of_bytes", Array::<3, _>(Fixed::<2>))
}
}
# [doc = "named format combinator for `vec_of_bytes`."]
# [derive (Clone, Copy)]
pub struct VecOfBytesFmt;
pub type VecOfBytesFmtSpec = Named<RepeatTillEnd<Fixed<2>>>;
impl VecOfBytesFmt {
# [doc = "specification constructor for `vec_of_bytes`."]
pub open spec fn spec_inner() -> VecOfBytesFmtSpec {
Named("vec_of_bytes", RepeatTillEnd(Fixed::<2>))
}
}
# [doc = "named format combinator for `optional_bytes`."]
# [derive (Clone, Copy)]
pub struct OptionalBytesFmt;
pub type OptionalBytesFmtSpec = Named<OptionalEnd<Fixed<2>>>;
impl OptionalBytesFmt {
# [doc = "specification constructor for `optional_bytes`."]
pub open spec fn spec_inner() -> OptionalBytesFmtSpec {
Named("optional_bytes", OptionalEnd(Fixed::<2>))
}
}
# [doc = "named format combinator for `tail_vec`."]
# [derive (Clone, Copy)]
pub struct TailVecFmt;
pub type TailVecFmtSpec = Named<
Mapped<AndThen<Tail, RepeatTillEnd<AnythingFmt>>, BiMap<TailVecForward, TailVecReverse>>,
>;
impl TailVecFmt {
# [doc = "specification constructor for `tail_vec`."]
pub open spec fn spec_inner() -> TailVecFmtSpec {
Named(
"tail_vec",
Mapped {
inner: AndThen(Tail, RepeatTillEnd(AnythingFmt)),
mapper: BiMap(TailVecForward, TailVecReverse),
},
)
}
}
// ============================================================
// Derived Parser, Serializer, Length, and Consistency Specifications
// ============================================================
mod derived_specs {
use super::*;
impl SpecParser for AnythingFmt {
type PVal = AnythingSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for AnythingFmt {
type Val = AnythingSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for AnythingFmt {
type SValue = AnythingSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for AnythingFmt {
type SVal = AnythingSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for AnythingFmt {
type T = AnythingSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for NestedDynamicBytesFmt {
type PVal = NestedDynamicBytesSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for NestedDynamicBytesFmt {
type Val = NestedDynamicBytesSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for NestedDynamicBytesFmt {
type SValue = NestedDynamicBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for NestedDynamicBytesFmt {
type SVal = NestedDynamicBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for NestedDynamicBytesFmt {
type T = NestedDynamicBytesSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for NestedFixedBytesFmt {
type PVal = NestedFixedBytesSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for NestedFixedBytesFmt {
type Val = NestedFixedBytesSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for NestedFixedBytesFmt {
type SValue = NestedFixedBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for NestedFixedBytesFmt {
type SVal = NestedFixedBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for NestedFixedBytesFmt {
type T = NestedFixedBytesSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for FixedArrayOfBytesFmt {
type PVal = FixedArrayOfBytesSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for FixedArrayOfBytesFmt {
type Val = FixedArrayOfBytesSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for FixedArrayOfBytesFmt {
type SValue = FixedArrayOfBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for FixedArrayOfBytesFmt {
type SVal = FixedArrayOfBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for FixedArrayOfBytesFmt {
type T = FixedArrayOfBytesSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for VecOfBytesFmt {
type PVal = VecOfBytesSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for VecOfBytesFmt {
type Val = VecOfBytesSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for VecOfBytesFmt {
type SValue = VecOfBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for VecOfBytesFmt {
type SVal = VecOfBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for VecOfBytesFmt {
type T = VecOfBytesSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for OptionalBytesFmt {
type PVal = OptionalBytesSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for OptionalBytesFmt {
type Val = OptionalBytesSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for OptionalBytesFmt {
type SValue = OptionalBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for OptionalBytesFmt {
type SVal = OptionalBytesSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for OptionalBytesFmt {
type T = OptionalBytesSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
impl SpecParser for TailVecFmt {
type PVal = TailVecSpec;
# [verifier::opaque]
open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)> {
Self::spec_inner().spec_parse(ibuf)
}
}
impl Consistency for TailVecFmt {
type Val = TailVecSpec;
open spec fn consistent(&self, v: Self::Val) -> bool {
Self::spec_inner().consistent(v)
}
}
impl SpecSerializerDps for TailVecFmt {
type SValue = TailVecSpec;
# [verifier::opaque]
open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8> {
Self::spec_inner().spec_serialize_dps(v, obuf)
}
}
impl SpecSerializer for TailVecFmt {
type SVal = TailVecSpec;
# [verifier::opaque]
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8> {
Self::spec_inner().spec_serialize(v)
}
}
impl SpecByteLen for TailVecFmt {
type T = TailVecSpec;
# [verifier::opaque]
open spec fn byte_len(&self, v: Self::T) -> nat {
Self::spec_inner().byte_len(v)
}
}
}
// ============================================================
// Proven Format Properties
// ============================================================
mod derived_proofs {
use super::*;
broadcast use {
vest_lib::combinators::disjoint::disjointness_lemmas,
AnythingSpec::lemma_from_into,
AnythingSpec::lemma_into_from,
NestedDynamicBytesSpec::lemma_from_into,
NestedDynamicBytesSpec::lemma_into_from,
NestedFixedBytesSpec::lemma_from_into,
NestedFixedBytesSpec::lemma_into_from,
TailVecSpec::lemma_from_into,
TailVecSpec::lemma_into_from,
};
impl SafeParser for AnythingFmt {
proof fn lemma_parse_safe(&self, ibuf: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
Self::spec_inner().lemma_parse_safe(ibuf);
}
}
impl Productive for AnythingFmt {
open spec fn productive_inv(&self) -> bool {
Self::spec_inner().productive_inv()
}
proof fn lemma_productive(&self, s: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
let fmt = Self::spec_inner();
assert(fmt.productive_inv());
fmt.lemma_productive(s);
}
}
impl SoundParser for AnythingFmt {
proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
reveal(<AnythingFmt as SpecByteLen>::byte_len);
let fmt = Self::spec_inner();
assert forall|input: AnythingInner| # [trigger]
fmt.1.inner.consistent(input) implies fmt.1.mapper.lossless(input) by {
AnythingSpec::lemma_into_from(input);
}
assert(fmt.sound_inv());
fmt.lemma_parse_sound_consumption(ibuf);
}
proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
reveal(<AnythingFmt as Consistency>::consistent);
let fmt = Self::spec_inner();
assert forall|input: AnythingInner| # [trigger]
fmt.1.inner.consistent(input) implies fmt.1.mapper.lossless(input) by {
AnythingSpec::lemma_into_from(input);
}
assert(fmt.sound_inv());
fmt.lemma_parse_sound_value(ibuf);
}
}
impl NonTailFmt for AnythingFmt {
proof fn lemma_serialize_dps_prepend(&self, v: Self::SValue, obuf: Seq<u8>) {
reveal(<AnythingFmt as SpecSerializerDps>::spec_serialize_dps);
let fmt = Self::spec_inner();
assert(fmt.serialize_dps_inv());
fmt.lemma_serialize_dps_prepend(v, obuf);
}
proof fn lemma_serialize_dps_len(&self, v: Self::SValue, obuf: Seq<u8>) {
reveal(<AnythingFmt as SpecSerializerDps>::spec_serialize_dps);
reveal(<AnythingFmt as SpecByteLen>::byte_len);
let fmt = Self::spec_inner();
assert(fmt.serialize_dps_inv());
fmt.lemma_serialize_dps_len(v, obuf);
}
}
impl GoodSerializer for AnythingFmt {
proof fn lemma_serialize_len(&self, v: Self::SVal) {
reveal(<AnythingFmt as SpecSerializer>::spec_serialize);
reveal(<AnythingFmt as SpecByteLen>::byte_len);
let fmt = Self::spec_inner();
assert(fmt.serialize_inv());
fmt.lemma_serialize_len(v);
}
}
impl SPRoundTripDps for AnythingFmt {
proof fn theorem_serialize_dps_parse_roundtrip(&self, v: Self::T, obuf: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
reveal(<AnythingFmt as SpecSerializerDps>::spec_serialize_dps);
reveal(<AnythingFmt as Consistency>::consistent);
reveal(<AnythingFmt as SpecByteLen>::byte_len);
let fmt = Self::spec_inner();
assert forall|output: AnythingSpec| # [trigger]
fmt.1.consistent(output) implies fmt.1.mapper.sound(output) by {
AnythingSpec::lemma_from_into(output);
}
assert(fmt.unambiguous());
fmt.theorem_serialize_dps_parse_roundtrip(v, obuf);
}
}
impl NonMalleable for AnythingFmt {
proof fn lemma_parse_non_malleable(&self, buf1: Seq<u8>, buf2: Seq<u8>) {
reveal(<AnythingFmt as SpecParser>::spec_parse);
let fmt = Self::spec_inner();
assert forall|input: AnythingInner| # [trigger]
fmt.1.inner.consistent(input) implies fmt.1.mapper.lossless(input) by {
AnythingSpec::lemma_into_from(input);
}