-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvyperTestScript.sml
1741 lines (1511 loc) · 45.9 KB
/
vyperTestScript.sml
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
open HolKernel boolLib bossLib Parse intLib wordsLib cv_transLib;
open numeralTheory arithmeticTheory finite_mapTheory;
open vyperAstTheory vyperInterpreterTheory vyperSmallStepTheory;
val () = new_theory "vyperTest";
Definition test_if_control_flow_ast_def:
test_if_control_flow_ast = [
def "foo" [] uint256
[
AnnAssign "a" uint256 (li 1);
If (Name "a" == li 1)
[
Assign (BaseTarget (NameTarget "a")) (li 2)
]
[
Assign (BaseTarget (NameTarget "a")) (li 3)
];
Return (SOME (Name "a" + li 42))
]
]
End
val () = cv_trans_deep_embedding EVAL test_if_control_flow_ast_def;
val pair_case_rand = TypeBase.case_rand_of``:'a # 'b``
val contract_addr = “42w: address”
val sender_addr = “1001w: address”
Definition call_foo_tx_def:
call_foo_tx = call_txn ^sender_addr ^contract_addr "foo" [] 0
End
Definition call_bar_tx_def:
call_bar_tx = call_txn ^sender_addr ^contract_addr "bar" [] 0
End
Theorem call_foo_tx_target[simp]:
call_foo_tx.target = 42w ∧
call_bar_tx.target = 42w
Proof
rw[call_foo_tx_def, call_bar_tx_def]
QED
val () = cv_trans_deep_embedding EVAL call_foo_tx_def;
val () = cv_trans_deep_embedding EVAL call_bar_tx_def;
Definition deploy_tx_def:
deploy_tx = call_txn ^sender_addr ^contract_addr "__init__" [] 0
End
val () = cv_trans_deep_embedding EVAL deploy_tx_def;
Definition load_and_call_foo_def:
load_and_call_foo ts =
case load_contract initial_machine_state deploy_tx ts
of INL am => FST $ call_external am call_foo_tx
| INR msg => INR msg
End
val () = cv_auto_trans load_and_call_foo_def;
Definition call_transactions_def:
call_transactions am [] = ([], am) ∧
call_transactions am (t::ts) =
let (r, am) = call_external am t in
let (rs, am) = call_transactions am ts in
(r::rs, am)
End
val () = cv_auto_trans call_transactions_def;
Theorem test_if_control_flow:
load_and_call_foo test_if_control_flow_ast
= INL (IntV 44)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_for_control_flow_ast_def:
test_for_control_flow_ast = [
def "foo" [] uint256
[
AnnAssign "a" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2; li 3]);
AnnAssign "counter" uint256 (li 0);
For "i" uint256 (Array (Name "a")) 10
[ AugAssign (NameTarget "counter") Add (Name "i") ];
Return (SOME (Name "counter"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_for_control_flow_ast_def;
Theorem test_for_control_flow:
load_and_call_foo test_for_control_flow_ast
= INL (IntV 6)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_array_assign_ast_def:
test_array_assign_ast = [
def "foo" [] uint256
[
AnnAssign "bar" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2]);
Assign (BaseTarget (SubscriptTarget (NameTarget "bar") (li 0)))
(li 3);
Return (SOME (Subscript (Name "bar") (li 0) +
Subscript (Name "bar") (li 1) +
li 42))
]
]
End
val () = cv_trans_deep_embedding EVAL test_array_assign_ast_def;
Theorem test_array_assign:
load_and_call_foo test_array_assign_ast
= INL (IntV 47)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_storage_array_assign_ast_def:
test_storage_array_assign_ast = [
privar "a" (DynArray uint256 10);
def "foo" [] uint256 [
AssignSelf "a" (DynArlit 10 [li 1; li 2]);
Assign (BaseTarget
(SubscriptTarget (TopLevelNameTarget "a")
(li 0)))
(li 3);
Return (SOME (Subscript (TopLevelName "a") (li 0) +
Subscript (TopLevelName "a") (li 1)))
]
]
End
val () = cv_trans_deep_embedding EVAL test_storage_array_assign_ast_def;
Theorem test_storage_array_assign:
load_and_call_foo test_storage_array_assign_ast
= INL (IntV 5)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_internal_call_ast_def:
test_internal_call_ast = [
itl_def "bar" [] uint256 [
AnnAssign "a" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2; li 3]);
AnnAssign "counter" uint256 (li 0);
For "i" uint256 (Array (Name "a")) 10 [
AugAssign (NameTarget "counter") Add (Name "i")
];
Return (SOME (Name "counter"))
];
def "foo" [] uint256 [
AnnAssign "a" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2; li 3]);
AnnAssign "counter" uint256 (li 0);
For "i" uint256 (Array (Name "a")) 10 [
AugAssign (NameTarget "counter") Add (Name "i")
];
Return (SOME (Name "counter" + call "bar" []))
]
]
End
val () = cv_trans_deep_embedding EVAL test_internal_call_ast_def;
Theorem test_internal_call:
load_and_call_foo test_internal_call_ast
= INL (IntV 12)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_internal_call_without_return_ast_def:
test_internal_call_without_return_ast = [
privar "a" uint256;
itl_def "bar" [] NoneT [
AssignSelf "a" (li 42)
];
def "foo" [] uint256 [
Expr (call "bar" []);
Return (SOME (TopLevelName "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_internal_call_without_return_ast_def;
Theorem test_internal_call_without_return:
load_and_call_foo test_internal_call_without_return_ast
= INL (IntV 42)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_internal_call_with_args_ast_def:
test_internal_call_with_args_ast = [
itl_def "baz" [("a", uint256)] uint256 [
Return (SOME (Name "a"))
];
itl_def "bar" [("a", uint256)] uint256 [
Return (SOME (Name "a" + call "baz" [li 3]))
];
def "foo" [] uint256 [
AnnAssign "a" uint256 (li 1);
Return (SOME (Name "a" + call "bar" [li 2]))
]
]
End
val () = cv_trans_deep_embedding EVAL test_internal_call_with_args_ast_def;
Theorem test_internal_call_with_args:
load_and_call_foo test_internal_call_with_args_ast
= INL (IntV 6)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_internal_call_with_args2_ast_def:
test_internal_call_with_args2_ast = [
itl_def "baz" [("a", uint256)] uint256 [
Return (SOME (Name "a"))
];
itl_def "bar" [("a", uint256)] uint256 [
Return (SOME (call "baz" [li 3] + Name "a"))
];
def "foo" [] uint256 [
AnnAssign "a" uint256 (li 1);
Return (SOME (call "bar" [li 2] + Name "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_internal_call_with_args2_ast_def;
Theorem test_internal_call_with_args2:
load_and_call_foo test_internal_call_with_args2_ast
= INL (IntV 6)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_storage_variables_ast_def:
test_storage_variables_ast = [
privar "d" uint256;
def "foo" [] uint256 [
AnnAssign "a" uint256 (li 1);
AssignSelf "d" (Name "a");
If (Name "a" == li 1)
[Assign (BaseTarget (NameTarget "a")) (li 2)]
[Assign (BaseTarget (NameTarget "a")) (li 3)];
Return (SOME (TopLevelName "d" + li 42))
]
]
End
val () = cv_trans_deep_embedding EVAL test_storage_variables_ast_def;
Theorem test_storage_variables:
load_and_call_foo test_storage_variables_ast
= INL (IntV 43)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_storage_variables2_ast_def:
test_storage_variables2_ast = [
privar "d" uint256;
privar "k" uint256;
def "foo" [] uint256 [
AssignSelf "k" (li 1);
AssignSelf "d" (TopLevelName "k");
AugAssign (TopLevelNameTarget "d") Add (TopLevelName "k");
Return (SOME (TopLevelName "d" + TopLevelName "k"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_storage_variables2_ast_def;
Theorem test_storage_variables2:
load_and_call_foo test_storage_variables2_ast
= INL (IntV 3)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_storage_variables3_ast_def:
test_storage_variables3_ast = [
privar "d" uint256;
itl_def "bar" [] NoneT [
AnnAssign "a" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2; li 3]);
For "i" uint256 (Array (Name "a")) 10 [
AugAssign (TopLevelNameTarget "d") Add (Name "i")
]
];
def "foo" [] uint256 [
AnnAssign "a" (DynArray uint256 10)
(DynArlit 10 [li 1; li 2; li 3]);
AnnAssign "counter" uint256 (li 0);
For "i" uint256 (Array (Name "a")) 10 [
AugAssign (TopLevelNameTarget "d") Add (Name "i")
];
Expr (call "bar" []);
Return (SOME (TopLevelName "d"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_storage_variables3_ast_def;
Theorem test_storage_variables3:
load_and_call_foo test_storage_variables3_ast
= INL (IntV 12)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_statefulness_of_storage_ast_def:
test_statefulness_of_storage_ast = [
privar "d" uint256;
def "foo" [] uint256 [
AugAssign (TopLevelNameTarget "d") Add (li 1);
Return (SOME (TopLevelName "d"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_statefulness_of_storage_ast_def;
Theorem test_statefulness_of_storage:
case load_contract initial_machine_state deploy_tx
test_statefulness_of_storage_ast
of INR msg => F
| INL ms =>
let (r1, ms) = call_external ms call_foo_tx in
let (r2, ms) = call_external ms call_foo_tx in
let (r3, ms) = call_external ms call_foo_tx in
let (r4, ms) = call_external ms call_foo_tx in
let (r5, ms) = call_external ms call_foo_tx in
r1 = INL (IntV 1) ∧
r2 = INL (IntV 2) ∧
r3 = INL (IntV 3) ∧
r4 = INL (IntV 4) ∧
r5 = INL (IntV 5)
Proof
CONV_TAC cv_eval
QED
Definition test_statefulness_of_storage2_ast_def:
test_statefulness_of_storage2_ast = [
privar "d" uint256;
def "foo" [] uint256 [
AugAssign (TopLevelNameTarget "d") Add (li 1);
Return (SOME (TopLevelName "d"))
];
def "bar" [] uint256 [
AugAssign (TopLevelNameTarget "d") Add (li 1);
Return (SOME (TopLevelName "d"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_statefulness_of_storage2_ast_def;
Theorem test_statefulness_of_storage2:
case load_contract initial_machine_state deploy_tx
test_statefulness_of_storage2_ast
of INR msg => F
| INL ms =>
let (f1, ms) = call_external ms call_foo_tx in
let (b1, ms) = call_external ms call_bar_tx in
let (f2, ms) = call_external ms call_foo_tx in
let (b2, ms) = call_external ms call_bar_tx in
let (f3, ms) = call_external ms call_foo_tx in
let (b3, ms) = call_external ms call_bar_tx in
let (f4, ms) = call_external ms call_foo_tx in
let (b4, ms) = call_external ms call_bar_tx in
let (f5, ms) = call_external ms call_foo_tx in
let (b5, ms) = call_external ms call_bar_tx in
f1 = INL (IntV (0 * 2 + 1)) ∧
f2 = INL (IntV (1 * 2 + 1)) ∧
f3 = INL (IntV (2 * 2 + 1)) ∧
f4 = INL (IntV (3 * 2 + 1)) ∧
f5 = INL (IntV (4 * 2 + 1)) ∧
b1 = INL (IntV (0 * 2 + 2)) ∧
b2 = INL (IntV (1 * 2 + 2)) ∧
b3 = INL (IntV (2 * 2 + 2)) ∧
b4 = INL (IntV (3 * 2 + 2)) ∧
b5 = INL (IntV (4 * 2 + 2))
Proof
CONV_TAC cv_eval
QED
Definition test_statefulness_of_tstorage_ast_def:
test_statefulness_of_tstorage_ast = [
VariableDecl Private Transient "d" uint256;
(* omitted: interface Bar *)
def "foo" [] uint256 [
AugAssign (TopLevelNameTarget "d") Add (li 1);
Return (SOME (Call (ExtCall "bar") [self]))
];
def "bar" [] uint256 [
AugAssign (TopLevelNameTarget "d") Add (li 1);
Return (SOME (self_ "d"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_statefulness_of_tstorage_ast_def;
(* needs ExtCall
Theorem test_statefulness_of_tstorage:
(case load_contract initial_machine_state deploy_tx
test_statefulness_of_tstorage_ast of
INL am =>
FST $ call_transactions am
[call_foo_tx; call_foo_tx; call_foo_tx]
| _ => [])
= [INL (IntV 2); INL (IntV 2); INL (IntV 2)]
Proof
CONV_TAC $ LAND_CONV cv_eval
QED
*)
Definition test_tstorage_variables0_ast_def:
test_tstorage_variables0_ast = [
VariableDecl Private Transient "d" uint256;
VariableDecl Private Transient "k" uint256;
def "foo" [] uint256 [
AssignSelf "k" (li 1);
AssignSelf "d" (TopLevelName "k");
AugAssign (TopLevelNameTarget "d") Add (TopLevelName "k");
Return (SOME (TopLevelName "d" + TopLevelName "k"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_tstorage_variables0_ast_def;
Theorem test_tstorage_variables0:
load_and_call_foo test_tstorage_variables0_ast
= INL (IntV 3)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_tstorage_variables2_ast_def:
test_tstorage_variables2_ast = [
VariableDecl Private Transient "d" uint256;
VariableDecl Private Transient "k" uint256;
def "foo" [] uint256 [
If (TopLevelName "k" == li 0) [
AssignSelf "k" (li 1)
] [];
AssignSelf "d" (TopLevelName "k");
AugAssign (TopLevelNameTarget "d") Add (TopLevelName "k");
Return (SOME (TopLevelName "d" + TopLevelName "k"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_tstorage_variables2_ast_def;
Theorem test_tstorage_variables2:
load_and_call_foo test_tstorage_variables2_ast
= INL (IntV 3)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_default_storage_values_ast_def:
test_default_storage_values_ast = [
StructDecl "S" [("a", uint256)];
privar "a" uint256;
privar "b" uint256;
privar "c" (DynArray uint256 10);
privar "d" (StructT "S");
privar "e" (BaseT (BytesT (Dynamic 10)));
privar "f" (BaseT (StringT 10));
def "foo" [] uint256 [
Assert (TopLevelName "a" == li 0) "";
Assert (TopLevelName "b" == li 0) "";
Assert (len (TopLevelName "c") == li 0) "";
Assert (Attribute (TopLevelName "d") "a" == li 0) "";
Assert (len (TopLevelName "e") == li 0) "";
Assert (len (TopLevelName "f") == li 0) "";
Return (SOME (li 1))
]
]
End
val () = cv_trans_deep_embedding EVAL test_default_storage_values_ast_def;
Theorem test_default_storage_values:
load_and_call_foo test_default_storage_values_ast
= INL (IntV 1)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_range_builtin_ast_def:
test_range_builtin_ast = [
privar "a" uint256;
def "foo" [] uint256 [
For "i" uint256 (Range (li 0) (li 10)) 10 [
AugAssign (TopLevelNameTarget "a") Add (Name "i")
];
Return (SOME (TopLevelName "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_range_builtin_ast_def;
Theorem test_range_builtin:
load_and_call_foo test_range_builtin_ast
= INL (IntV &(SUM (COUNT_LIST 10)))
Proof
CONV_TAC (LAND_CONV cv_eval)
\\ EVAL_TAC
QED
Definition test_range_builtin2_ast_def:
test_range_builtin2_ast = [
privar "a" uint256;
def "foo" [] uint256 [
AnnAssign "k" uint256 (li 5);
For "i" uint256 (Range (li 0) (Name "k")) 5 [
AugAssign (TopLevelNameTarget "a") Add (Name "i")
];
Return (SOME (TopLevelName "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_range_builtin2_ast_def;
Theorem test_range_builtin2:
load_and_call_foo test_range_builtin2_ast
= INL (IntV &(SUM (COUNT_LIST 5)))
Proof
CONV_TAC (LAND_CONV cv_eval)
\\ EVAL_TAC
QED
Definition test_range_builtin3_ast_def:
test_range_builtin3_ast = [
privar "a" uint256;
def "foo" [] uint256 [
For "i" uint256 (Range (li 1) (li 5)) (5 - 1) [
AugAssign (TopLevelNameTarget "a") Add (Name "i")
];
Return (SOME (TopLevelName "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_range_builtin3_ast_def;
Theorem test_range_builtin3:
load_and_call_foo test_range_builtin3_ast
= INL (IntV &(SUM (MAP ((+) 1) (COUNT_LIST (5 - 1)))))
Proof
CONV_TAC (LAND_CONV cv_eval)
\\ EVAL_TAC
QED
Definition test_range_builtin4_ast_def:
test_range_builtin4_ast = [
privar "a" uint256;
def "foo" [] uint256 [
AnnAssign "k" uint256 (li 1);
For "i" uint256 (Range (Name "k") (li 5)) 4 [
AugAssign (TopLevelNameTarget "a") Add (Name "i")
];
Return (SOME (TopLevelName "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_range_builtin4_ast_def;
Theorem test_range_builtin4:
load_and_call_foo test_range_builtin4_ast
= INL (IntV &(SUM (MAP ((+) 1) (COUNT_LIST (5 - 1)))))
Proof
CONV_TAC (LAND_CONV cv_eval)
\\ EVAL_TAC
QED
Definition test_len_builtin_ast_def:
test_len_builtin_ast = [
def "foo" [] uint256 [
AnnAssign "a" (DynArray uint256 3)
(DynArlit 3 [li 1; li 2; li 3]);
Return (SOME (len (Name "a")))
]
]
End
val () = cv_trans_deep_embedding EVAL test_len_builtin_ast_def;
Theorem test_len_builtin:
load_and_call_foo test_len_builtin_ast
= INL (IntV 3)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_len_builtin2_ast_def:
test_len_builtin2_ast = [
privar "d" (DynArray uint256 3);
def "foo" [] uint256 [
Return (SOME (len (TopLevelName "d")))
]
]
End
val () = cv_trans_deep_embedding EVAL test_len_builtin2_ast_def;
Theorem test_len_builtin2:
load_and_call_foo test_len_builtin2_ast
= INL (IntV 0)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_len_builtin3_ast_def:
test_len_builtin3_ast = [
privar "s" (BaseT (StringT 10));
def "foo" [] uint256 [
AssignSelf "s" (Literal (StringL 10 "hello"));
Return (SOME (len (TopLevelName "s")))
]
]
End
val () = cv_trans_deep_embedding EVAL test_len_builtin3_ast_def;
Theorem test_len_builtin3:
load_and_call_foo test_len_builtin3_ast
= INL (IntV 5)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
Definition test_len_builtin4_ast_def:
test_len_builtin4_ast = [
privar "s" (BaseT (BytesT (Dynamic 10)));
def "foo" [] uint256 [
AssignSelf "s"
(Literal (BytesL (Dynamic 10)
^(rhs $ concl $ EVAL “MAP (n2w o ORD) "hello" : word8 list”)));
Return (SOME (len (TopLevelName "s")))
]
]
End
val () = cv_trans_deep_embedding EVAL test_len_builtin4_ast_def;
Theorem test_len_builtin4:
load_and_call_foo test_len_builtin4_ast
= INL (IntV 5)
Proof
CONV_TAC(LAND_CONV cv_eval) \\ rw[]
QED
(* TODO: test abi_encode *)
(* TODO: test self call *)
(* TODO: test default arg value *)
Definition test_external_func_arg_ast_def:
test_external_func_arg_ast = [
def "foo" [("a", uint256)] uint256 [
Return (SOME (Name "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_external_func_arg_ast_def;
Theorem test_external_func_arg:
case load_contract initial_machine_state deploy_tx
test_external_func_arg_ast
of INR _ => F
| INL ms =>
FST $ call_external ms
$ call_txn ^sender_addr ^contract_addr "foo" [IntV 42] 0
= INL (IntV 42)
Proof
CONV_TAC cv_eval
QED
Definition test_external_func_arg2_ast_def:
test_external_func_arg2_ast = [
def "foo"
[("a", DynArray uint256 10); ("s", BaseT (StringT 100))]
(TupleT [DynArray uint256 10; BaseT (StringT 100)]) [
Return (SOME (ArrayLit (Fixed 2) [Name "a"; Name "s"]))
]
]
End
val () = cv_trans_deep_embedding EVAL test_external_func_arg2_ast_def;
Theorem test_external_func_arg2:
a = ArrayV (Dynamic 10) [IntV 1; IntV 2; IntV 3] ∧
s = StringV 100 "hello"
⇒
(case load_contract initial_machine_state deploy_tx
test_external_func_arg2_ast
of INR msg => INR msg
| INL ms =>
FST $ call_external ms
$ call_txn ^sender_addr ^contract_addr "foo" [a; s] 0)
= INL $ ArrayV (Fixed 2) [a; s]
Proof
rw[]
\\ CONV_TAC $ cv_eval
QED
Definition test_external_func_arg3_ast_def:
test_external_func_arg3_ast =
let dynarray_t = DynArray (DynArray uint256 10) 10 in [
def "foo" [("a", DynArray uint256 10);
("s", BaseT (StringT 100));
("b", dynarray_t)]
(TupleT [DynArray uint256 10; BaseT (StringT 100); dynarray_t]) [
Return $ SOME $ ArrayLit (Fixed 3) [Name "a"; Name "s"; Name "b"]
]
]
End
val () = cv_trans_deep_embedding EVAL test_external_func_arg3_ast_def;
Theorem test_external_func_arg3:
complex_array = ArrayV (Dynamic 10) [
ArrayV (Dynamic 10) [IntV 4; IntV 5; IntV 6];
ArrayV (Dynamic 10) [IntV 7; IntV 8; IntV 9; IntV 10; IntV 11];
ArrayV (Dynamic 10) [];
ArrayV (Dynamic 10) [IntV 12]] ∧
a = ArrayV (Dynamic 10) [IntV 1; IntV 2; IntV 3] ∧
s = StringV 100 "hello"
⇒
(case load_contract initial_machine_state deploy_tx
test_external_func_arg3_ast
of INR msg => INR msg
| INL ms =>
FST $ call_external ms
$ call_txn ^sender_addr ^contract_addr "foo" [a; s; complex_array] 0)
= INL $ ArrayV (Fixed 3) [a; s; complex_array]
Proof
rw[]
\\ CONV_TAC $ cv_eval
QED
Definition test_external_func_arg4_ast_def:
test_external_func_arg4_ast =
let tuple_t = TupleT [BaseT(StringT 93);
DynArray (DynArray uint256 10) 10] in [
def "foo" [("a", DynArray uint256 10);
("s", BaseT (StringT 100));
("b", tuple_t)]
(TupleT [DynArray uint256 10; BaseT(StringT 100); tuple_t]) [
Return $ SOME $ ArrayLit (Fixed 3) [Name "a"; Name "s"; Name "b"]
]
]
End
val () = cv_trans_deep_embedding EVAL test_external_func_arg4_ast_def;
Theorem test_external_func_arg4:
complex_array = ArrayV (Dynamic 10) [
ArrayV (Dynamic 10) [IntV 4; IntV 5; IntV 6];
ArrayV (Dynamic 10) [IntV 7; IntV 8; IntV 9; IntV 10; IntV 11];
ArrayV (Dynamic 10) [];
ArrayV (Dynamic 10) [IntV 12]] ∧
complex_tuple = ArrayV (Fixed 2) [StringV 93 "apollo"; complex_array] ∧
a = ArrayV (Dynamic 10) [IntV 1; IntV 2; IntV 3] ∧
s = StringV 100 "hello"
⇒
(case load_contract initial_machine_state deploy_tx
test_external_func_arg4_ast
of INR msg => INR msg
| INL ms =>
FST $ call_external ms
$ call_txn ^sender_addr ^contract_addr "foo" [a; s; complex_tuple] 0)
= INL $ ArrayV (Fixed 3) [a; s; complex_tuple]
Proof
rw[]
\\ CONV_TAC $ cv_eval
QED
Definition test_empty_builtin_ast_def:
test_empty_builtin_ast = [
def "foo" [] uint256 [
Return (SOME (TypeBuiltin Empty uint256))
]
]
End
val () = cv_trans_deep_embedding EVAL test_empty_builtin_ast_def;
Theorem test_empty_builtin:
load_and_call_foo test_empty_builtin_ast
= INL (IntV 0)
Proof
CONV_TAC cv_eval
QED
Definition test_empty_builtin2_ast_def:
test_empty_builtin2_ast = [
def "foo" [] uint256 [
Return (SOME (TypeBuiltin Empty (BaseT (StringT 56))))
]
]
End
val () = cv_trans_deep_embedding EVAL test_empty_builtin2_ast_def;
Theorem test_empty_builtin2:
load_and_call_foo test_empty_builtin2_ast
= INL (StringV 56 "")
Proof
CONV_TAC cv_eval
QED
Definition test_empty_builtin3_ast_def:
test_empty_builtin3_ast = [
def "foo" [] uint256 [
Return (SOME (TypeBuiltin Empty (ArrayT (BaseT (StringT 32)) (Dynamic 10))))
]
]
End
val () = cv_trans_deep_embedding EVAL test_empty_builtin3_ast_def;
Theorem test_empty_builtin3:
load_and_call_foo test_empty_builtin3_ast
= INL (ArrayV (Dynamic 10) [])
Proof
CONV_TAC cv_eval
QED
(* TODO raw_call tests *)
(* TODO static call tests *)
(* TODO abi encode tests *)
(* TODO interface call tests *)
Definition test_struct_ast_def:
test_struct_ast = [
StructDecl "S" [
("a", uint256);
("b", uint256)
];
def "foo" [] uint256 [
AnnAssign "s" (StructT "S")
(StructLit "S" [("a", li 1); ("b", li 2)]);
Return (SOME (Attribute (Name "s") "a"))
]
]
End
val () = cv_trans_deep_embedding EVAL test_struct_ast_def;
Theorem test_struct:
load_and_call_foo test_struct_ast
= INL (IntV 1)
Proof
CONV_TAC cv_eval
QED
Definition test_struct2_ast_def:
test_struct2_ast = [
StructDecl "S" [
("a", uint256);
("b", uint256)
];
StructDecl "T" [
("s", StructT "S");
("c", uint256)
];
def "foo" [] uint256 [
AnnAssign "s" (StructT "S")
(StructLit "S" [("a", li 1); ("b", li 2)]);
AnnAssign "t" (StructT "T")
(StructLit "T" [("s", Name "s"); ("c", li 3)]);
Return (SOME $
(Attribute (Attribute (Name "t") "s") "a") +
(Attribute (Attribute (Name "t") "s") "b") +
(Attribute (Name "t") "c")
)
]
]
End
val () = cv_trans_deep_embedding EVAL test_struct2_ast_def;
Theorem test_struct2:
load_and_call_foo test_struct2_ast
= INL (IntV 6)
Proof
CONV_TAC cv_eval
QED
Definition test_struct3_ast_def:
test_struct3_ast = [
StructDecl "S" [
("a", uint256);
("b", uint256)
];
privar "d" (DynArray (StructT "S") 3);
def "foo" [] uint256 [
AssignSelf "d" $
DynArlit 3 [
StructLit "S" [("a", li 0); ("b", li 1)];
StructLit "S" [("a", li 2); ("b", li 3)];
StructLit "S" [("a", li 4); ("b", li 5)]
];
AnnAssign "acc" uint256 (li 0);
For "s" (StructT "S") (Array (TopLevelName "d")) 3 [
AugAssign (NameTarget "acc") Add $
Attribute (Name "s") "a" +
Attribute (Name "s") "b"
];
Return $ SOME $ Name "acc"
]
]
End
val () = cv_trans_deep_embedding EVAL test_struct3_ast_def;
Theorem test_struct3:
load_and_call_foo test_struct3_ast
= INL (IntV $ 1 + 2 + 3 + 4 + 5)
Proof
CONV_TAC cv_eval
QED
Definition test_struct4_ast_def:
test_struct4_ast = [
StructDecl "S" [
("a", uint256);
("b", uint256)
];
privar "s" (StructT "S");
def "foo" [] uint256 [
AssignSelf "s" $
StructLit "S" [("a", li 1); ("b", li 2)];
Assign (BaseTarget (AttributeTarget (TopLevelNameTarget "s") "a")) (li 3);
Return $ SOME $ Attribute (self_ "s") "a" + Attribute (self_ "s") "b"
]
]
End
val () = cv_trans_deep_embedding EVAL test_struct4_ast_def;
Theorem test_struct4:
load_and_call_foo test_struct4_ast
= INL (IntV $ 3 + 2)
Proof
CONV_TAC cv_eval
QED
Definition test_tstorage_clearing_ast_def:
test_tstorage_clearing_ast = [
VariableDecl Private Transient "t" uint256;
def "foo" [] uint256 [
AssignSelf "t" (li 42);
Return $ SOME (self_ "t")
];
def "bar" [] uint256 [
Return $ SOME (self_ "t")
]
]
End
val () = cv_trans_deep_embedding EVAL test_tstorage_clearing_ast_def;
Theorem test_tstorage_clearing:
(case load_contract initial_machine_state deploy_tx
test_tstorage_clearing_ast of