-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbitcoin.rs
More file actions
4984 lines (4277 loc) · 167 KB
/
Copy pathbitcoin.rs
File metadata and controls
4984 lines (4277 loc) · 167 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 `block`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct Block<'i> {
pub version: u32,
pub prev_block: &'i [u8],
pub merkle_root: &'i [u8],
pub timestamp: u32,
pub bits: u32,
pub nonce: u32,
pub tx_count: u64,
pub txs: Vec<Tx<'i>>,
}
# [verifier::ext_equal]
pub struct BlockSpec<
T0 = u32,
T1 = Seq<u8>,
T2 = Seq<u8>,
T3 = u32,
T4 = u32,
T5 = u32,
T6 = u64,
T7 = Seq<TxSpec>,
> {
pub version: T0,
pub prev_block: T1,
pub merkle_root: T2,
pub timestamp: T3,
pub bits: T4,
pub nonce: T5,
pub tx_count: T6,
pub txs: T7,
}
pub type BlockInner = (u32, (Seq<u8>, (Seq<u8>, (u32, (u32, (u32, (u64, Seq<TxSpec>)))))));
impl<'i> DeepView for Block<'i> {
type V = BlockSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
BlockSpec {
version: self.version.deep_view(),
prev_block: self.prev_block.deep_view(),
merkle_root: self.merkle_root.deep_view(),
timestamp: self.timestamp.deep_view(),
bits: self.bits.deep_view(),
nonce: self.nonce.deep_view(),
tx_count: self.tx_count.deep_view(),
txs: self.txs.deep_view(),
}
}
}
impl<'i> Block<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().version == self.version.deep_view(),
self.deep_view().prev_block == self.prev_block.deep_view(),
self.deep_view().merkle_root == self.merkle_root.deep_view(),
self.deep_view().timestamp == self.timestamp.deep_view(),
self.deep_view().bits == self.bits.deep_view(),
self.deep_view().nonce == self.nonce.deep_view(),
self.deep_view().tx_count == self.tx_count.deep_view(),
self.deep_view().txs == self.txs.deep_view(),
{
reveal(<Block as DeepView>::deep_view);
}
}
impl<T0, T1, T2, T3, T4, T5, T6, T7> BlockSpec<T0, T1, T2, T3, T4, T5, T6, T7> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, (T1, (T2, (T3, (T4, (T5, (T6, T7)))))))) -> Self {
let (version, (prev_block, (merkle_root, (timestamp, (bits, (nonce, (tx_count, txs))))))) =
input;
Self { version, prev_block, merkle_root, timestamp, bits, nonce, tx_count, txs }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, (T1, (T2, (T3, (T4, (T5, (T6, T7))))))) {
let Self { version, prev_block, merkle_root, timestamp, bits, nonce, tx_count, txs } = self;
(version, (prev_block, (merkle_root, (timestamp, (bits, (nonce, (tx_count, txs)))))))
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(BlockSpec::from_structural);
reveal(BlockSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, (T1, (T2, (T3, (T4, (T5, (T6, T7))))))))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(BlockSpec::from_structural);
reveal(BlockSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self {
version,
prev_block,
merkle_root,
timestamp,
bits,
nonce,
tx_count,
txs,
} => (
version,
(prev_block, (merkle_root, (timestamp, (bits, (nonce, (tx_count, txs)))))),
),
},
{
reveal(BlockSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct BlockForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct BlockReverse;
impl SpecMap for BlockForward {
type Input = BlockInner;
type Output = BlockSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
BlockSpec::from_structural(input)
}
}
impl SpecMap for BlockReverse {
type Input = BlockSpec;
type Output = BlockInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `tx`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct Tx<'i> {
pub version: u32,
pub txin_count: u64,
pub rem: TxRem<'i>,
}
# [verifier::ext_equal]
pub struct TxSpec<T0 = u32, T1 = u64, T2 = TxRemSpec> {
pub version: T0,
pub txin_count: T1,
pub rem: T2,
}
pub type TxInner = (u32, (u64, TxRemSpec));
impl<'i> DeepView for Tx<'i> {
type V = TxSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
TxSpec {
version: self.version.deep_view(),
txin_count: self.txin_count.deep_view(),
rem: self.rem.deep_view(),
}
}
}
impl<'i> Tx<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().version == self.version.deep_view(),
self.deep_view().txin_count == self.txin_count.deep_view(),
self.deep_view().rem == self.rem.deep_view(),
{
reveal(<Tx as DeepView>::deep_view);
}
}
impl<T0, T1, T2> TxSpec<T0, T1, T2> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, (T1, T2))) -> Self {
let (version, (txin_count, rem)) = input;
Self { version, txin_count, rem }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, (T1, T2)) {
let Self { version, txin_count, rem } = self;
(version, (txin_count, rem))
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(TxSpec::from_structural);
reveal(TxSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, (T1, T2)))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(TxSpec::from_structural);
reveal(TxSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { version, txin_count, rem } => (version, (txin_count, rem)),
},
{
reveal(TxSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxReverse;
impl SpecMap for TxForward {
type Input = TxInner;
type Output = TxSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
TxSpec::from_structural(input)
}
}
impl SpecMap for TxReverse {
type Input = TxSpec;
type Output = TxInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `tx_segwit`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct TxSegwit<'i> {
pub flag: u8,
pub txin_count: u64,
pub txins: Vec<Txin<'i>>,
pub txout_count: u64,
pub txouts: Vec<Txout<'i>>,
pub witness: Vec<Witness<'i>>,
pub lock_time: LockTime,
}
# [verifier::ext_equal]
pub struct TxSegwitSpec<
T0 = u8,
T1 = u64,
T2 = Seq<TxinSpec>,
T3 = u64,
T4 = Seq<TxoutSpec>,
T5 = Seq<WitnessSpec>,
T6 = LockTimeSpec,
> {
pub flag: T0,
pub txin_count: T1,
pub txins: T2,
pub txout_count: T3,
pub txouts: T4,
pub witness: T5,
pub lock_time: T6,
}
pub type TxSegwitInner = (
u8,
(u64, (Seq<TxinSpec>, (u64, (Seq<TxoutSpec>, (Seq<WitnessSpec>, LockTimeSpec))))),
);
impl<'i> DeepView for TxSegwit<'i> {
type V = TxSegwitSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
TxSegwitSpec {
flag: self.flag.deep_view(),
txin_count: self.txin_count.deep_view(),
txins: self.txins.deep_view(),
txout_count: self.txout_count.deep_view(),
txouts: self.txouts.deep_view(),
witness: self.witness.deep_view(),
lock_time: self.lock_time.deep_view(),
}
}
}
impl<'i> TxSegwit<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().flag == self.flag.deep_view(),
self.deep_view().txin_count == self.txin_count.deep_view(),
self.deep_view().txins == self.txins.deep_view(),
self.deep_view().txout_count == self.txout_count.deep_view(),
self.deep_view().txouts == self.txouts.deep_view(),
self.deep_view().witness == self.witness.deep_view(),
self.deep_view().lock_time == self.lock_time.deep_view(),
{
reveal(<TxSegwit as DeepView>::deep_view);
}
}
impl<T0, T1, T2, T3, T4, T5, T6> TxSegwitSpec<T0, T1, T2, T3, T4, T5, T6> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, (T1, (T2, (T3, (T4, (T5, T6))))))) -> Self {
let (flag, (txin_count, (txins, (txout_count, (txouts, (witness, lock_time)))))) = input;
Self { flag, txin_count, txins, txout_count, txouts, witness, lock_time }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, (T1, (T2, (T3, (T4, (T5, T6)))))) {
let Self { flag, txin_count, txins, txout_count, txouts, witness, lock_time } = self;
(flag, (txin_count, (txins, (txout_count, (txouts, (witness, lock_time))))))
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(TxSegwitSpec::from_structural);
reveal(TxSegwitSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, (T1, (T2, (T3, (T4, (T5, T6)))))))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(TxSegwitSpec::from_structural);
reveal(TxSegwitSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { flag, txin_count, txins, txout_count, txouts, witness, lock_time } => (
flag,
(txin_count, (txins, (txout_count, (txouts, (witness, lock_time))))),
),
},
{
reveal(TxSegwitSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxSegwitForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxSegwitReverse;
impl SpecMap for TxSegwitForward {
type Input = TxSegwitInner;
type Output = TxSegwitSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
TxSegwitSpec::from_structural(input)
}
}
impl SpecMap for TxSegwitReverse {
type Input = TxSegwitSpec;
type Output = TxSegwitInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `witness`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct Witness<'i> {
pub count: u64,
pub data: Vec<WitnessComponent<'i>>,
}
# [verifier::ext_equal]
pub struct WitnessSpec<T0 = u64, T1 = Seq<WitnessComponentSpec>> {
pub count: T0,
pub data: T1,
}
pub type WitnessInner = (u64, Seq<WitnessComponentSpec>);
impl<'i> DeepView for Witness<'i> {
type V = WitnessSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
WitnessSpec { count: self.count.deep_view(), data: self.data.deep_view() }
}
}
impl<'i> Witness<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().count == self.count.deep_view(),
self.deep_view().data == self.data.deep_view(),
{
reveal(<Witness as DeepView>::deep_view);
}
}
impl<T0, T1> WitnessSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, T1)) -> Self {
let (count, data) = input;
Self { count, data }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, T1) {
let Self { count, data } = self;
(count, data)
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(WitnessSpec::from_structural);
reveal(WitnessSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, T1))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(WitnessSpec::from_structural);
reveal(WitnessSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { count, data } => (count, data),
},
{
reveal(WitnessSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct WitnessForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct WitnessReverse;
impl SpecMap for WitnessForward {
type Input = WitnessInner;
type Output = WitnessSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
WitnessSpec::from_structural(input)
}
}
impl SpecMap for WitnessReverse {
type Input = WitnessSpec;
type Output = WitnessInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `witness_component`."]
# [derive (Debug, PartialEq, Eq, Clone, Copy)]
pub struct WitnessComponent<'i> {
pub l: u64,
pub data: &'i [u8],
}
# [verifier::ext_equal]
pub struct WitnessComponentSpec<T0 = u64, T1 = Seq<u8>> {
pub l: T0,
pub data: T1,
}
pub type WitnessComponentInner = (u64, Seq<u8>);
impl<'i> DeepView for WitnessComponent<'i> {
type V = WitnessComponentSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
WitnessComponentSpec { l: self.l.deep_view(), data: self.data.deep_view() }
}
}
impl<'i> WitnessComponent<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().l == self.l.deep_view(),
self.deep_view().data == self.data.deep_view(),
{
reveal(<WitnessComponent as DeepView>::deep_view);
}
}
impl<T0, T1> WitnessComponentSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, T1)) -> Self {
let (l, data) = input;
Self { l, data }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, T1) {
let Self { l, data } = self;
(l, data)
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(WitnessComponentSpec::from_structural);
reveal(WitnessComponentSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, T1))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(WitnessComponentSpec::from_structural);
reveal(WitnessComponentSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { l, data } => (l, data),
},
{
reveal(WitnessComponentSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct WitnessComponentForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct WitnessComponentReverse;
impl SpecMap for WitnessComponentForward {
type Input = WitnessComponentInner;
type Output = WitnessComponentSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
WitnessComponentSpec::from_structural(input)
}
}
impl SpecMap for WitnessComponentReverse {
type Input = WitnessComponentSpec;
type Output = WitnessComponentInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `tx_nonsegwit`."]
# [derive (Debug, PartialEq, Eq, Clone)]
pub struct TxNonsegwit<'i> {
pub txins: Vec<Txin<'i>>,
pub txout_count: u64,
pub txouts: Vec<Txout<'i>>,
pub lock_time: LockTime,
}
# [verifier::ext_equal]
pub struct TxNonsegwitSpec<T0 = Seq<TxinSpec>, T1 = u64, T2 = Seq<TxoutSpec>, T3 = LockTimeSpec> {
pub txins: T0,
pub txout_count: T1,
pub txouts: T2,
pub lock_time: T3,
}
pub type TxNonsegwitInner = (Seq<TxinSpec>, (u64, (Seq<TxoutSpec>, LockTimeSpec)));
impl<'i> DeepView for TxNonsegwit<'i> {
type V = TxNonsegwitSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
TxNonsegwitSpec {
txins: self.txins.deep_view(),
txout_count: self.txout_count.deep_view(),
txouts: self.txouts.deep_view(),
lock_time: self.lock_time.deep_view(),
}
}
}
impl<'i> TxNonsegwit<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().txins == self.txins.deep_view(),
self.deep_view().txout_count == self.txout_count.deep_view(),
self.deep_view().txouts == self.txouts.deep_view(),
self.deep_view().lock_time == self.lock_time.deep_view(),
{
reveal(<TxNonsegwit as DeepView>::deep_view);
}
}
impl<T0, T1, T2, T3> TxNonsegwitSpec<T0, T1, T2, T3> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, (T1, (T2, T3)))) -> Self {
let (txins, (txout_count, (txouts, lock_time))) = input;
Self { txins, txout_count, txouts, lock_time }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, (T1, (T2, T3))) {
let Self { txins, txout_count, txouts, lock_time } = self;
(txins, (txout_count, (txouts, lock_time)))
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(TxNonsegwitSpec::from_structural);
reveal(TxNonsegwitSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, (T1, (T2, T3))))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(TxNonsegwitSpec::from_structural);
reveal(TxNonsegwitSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { txins, txout_count, txouts, lock_time } => (
txins,
(txout_count, (txouts, lock_time)),
),
},
{
reveal(TxNonsegwitSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxNonsegwitForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxNonsegwitReverse;
impl SpecMap for TxNonsegwitForward {
type Input = TxNonsegwitInner;
type Output = TxNonsegwitSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
TxNonsegwitSpec::from_structural(input)
}
}
impl SpecMap for TxNonsegwitReverse {
type Input = TxNonsegwitSpec;
type Output = TxNonsegwitInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `lock_time`."]
# [derive (Debug, PartialEq, Eq, Clone, Copy)]
pub enum LockTime {
BlockNo(u32),
Timestamp(u32),
}
# [verifier::ext_equal]
pub enum LockTimeSpec<T0 = u32, T1 = u32> {
BlockNo(T0),
Timestamp(T1),
}
pub type LockTimeInner = Sum<u32, u32>;
impl DeepView for LockTime {
type V = LockTimeSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
match self {
LockTime::BlockNo(v) => LockTimeSpec::BlockNo(v.deep_view()),
LockTime::Timestamp(v) => LockTimeSpec::Timestamp(v.deep_view()),
}
}
}
impl LockTime {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view() == match self {
LockTime::BlockNo(v) => LockTimeSpec::BlockNo(v.deep_view()),
LockTime::Timestamp(v) => LockTimeSpec::Timestamp(v.deep_view()),
},
{
reveal(<LockTime as DeepView>::deep_view);
}
}
impl<T0, T1> LockTimeSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: Sum<T0, T1>) -> Self {
match input {
L(value) => Self::BlockNo(value),
R(value) => Self::Timestamp(value),
}
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> Sum<T0, T1> {
match self {
Self::BlockNo(value) => L(value),
Self::Timestamp(value) => R(value),
}
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(LockTimeSpec::from_structural);
reveal(LockTimeSpec::into_structural);
match self {
Self::BlockNo(_) => {},
Self::Timestamp(_) => {},
}
}
pub broadcast proof fn lemma_into_from(input: Sum<T0, T1>)
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(LockTimeSpec::from_structural);
reveal(LockTimeSpec::into_structural);
match input {
L(_) => {},
R(_) => {},
}
}
pub proof fn lemma_into_structural_variant(self)
ensures
Self::into_structural(self) == match self {
Self::BlockNo(value) => L(value),
Self::Timestamp(value) => R(value),
},
{
reveal(LockTimeSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct LockTimeForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct LockTimeReverse;
impl SpecMap for LockTimeForward {
type Input = LockTimeInner;
type Output = LockTimeSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
LockTimeSpec::from_structural(input)
}
}
impl SpecMap for LockTimeReverse {
type Input = LockTimeSpec;
type Output = LockTimeInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `txout`."]
# [derive (Debug, PartialEq, Eq, Clone, Copy)]
pub struct Txout<'i> {
pub value: u64,
pub script_pubkey: Script<'i>,
}
# [verifier::ext_equal]
pub struct TxoutSpec<T0 = u64, T1 = ScriptSpec> {
pub value: T0,
pub script_pubkey: T1,
}
pub type TxoutInner = (u64, ScriptSpec);
impl<'i> DeepView for Txout<'i> {
type V = TxoutSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
TxoutSpec { value: self.value.deep_view(), script_pubkey: self.script_pubkey.deep_view() }
}
}
impl<'i> Txout<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().value == self.value.deep_view(),
self.deep_view().script_pubkey == self.script_pubkey.deep_view(),
{
reveal(<Txout as DeepView>::deep_view);
}
}
impl<T0, T1> TxoutSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, T1)) -> Self {
let (value, script_pubkey) = input;
Self { value, script_pubkey }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, T1) {
let Self { value, script_pubkey } = self;
(value, script_pubkey)
}
pub broadcast proof fn lemma_from_into(self)
ensures
# [trigger] Self::from_structural(Self::into_structural(self)) == self,
{
reveal(TxoutSpec::from_structural);
reveal(TxoutSpec::into_structural);
}
pub broadcast proof fn lemma_into_from(input: (T0, T1))
ensures
# [trigger] Self::into_structural(Self::from_structural(input)) == input,
{
reveal(TxoutSpec::from_structural);
reveal(TxoutSpec::into_structural);
}
pub proof fn lemma_into_structural_fields(self)
ensures
Self::into_structural(self) == match self {
Self { value, script_pubkey } => (value, script_pubkey),
},
{
reveal(TxoutSpec::into_structural);
}
}
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxoutForward;
# [derive (Clone, Copy)]
# [doc (hidden)]
pub struct TxoutReverse;
impl SpecMap for TxoutForward {
type Input = TxoutInner;
type Output = TxoutSpec;
open spec fn spec_map(&self, input: Self::Input) -> Self::Output {
TxoutSpec::from_structural(input)
}
}
impl SpecMap for TxoutReverse {
type Input = TxoutSpec;
type Output = TxoutInner;
open spec fn spec_map(&self, value: Self::Input) -> Self::Output {
value.into_structural()
}
}
# [doc = "data type for `script`."]
# [derive (Debug, PartialEq, Eq, Clone, Copy)]
pub struct Script<'i> {
pub l: u64,
pub data: &'i [u8],
}
# [verifier::ext_equal]
pub struct ScriptSpec<T0 = u64, T1 = Seq<u8>> {
pub l: T0,
pub data: T1,
}
pub type ScriptInner = (u64, Seq<u8>);
impl<'i> DeepView for Script<'i> {
type V = ScriptSpec;
# [verifier::opaque]
open spec fn deep_view(&self) -> Self::V {
ScriptSpec { l: self.l.deep_view(), data: self.data.deep_view() }
}
}
impl<'i> Script<'i> {
pub proof fn lemma_deep_view_fields(&self)
ensures
self.deep_view().l == self.l.deep_view(),
self.deep_view().data == self.data.deep_view(),
{
reveal(<Script as DeepView>::deep_view);
}
}
impl<T0, T1> ScriptSpec<T0, T1> {
# [verifier::opaque]
pub open spec fn from_structural(input: (T0, T1)) -> Self {
let (l, data) = input;
Self { l, data }
}
# [verifier::opaque]
pub open spec fn into_structural(self) -> (T0, T1) {
let Self { l, data } = self;
(l, data)