forked from pirapira/eth-isabelle
/
ElleAltSemantics.thy
6653 lines (5827 loc) · 249 KB
/
ElleAltSemantics.thy
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
theory ElleAltSemantics
imports Main "Valid4" "../../EvmFacts" "../../example/termination/ProgramList"
begin
(*
Alternate, inductive Elle semantics
Idea is that jumps nondeterministically go to _all_ applicable labels
*)
(* first we need a way to get the next childpath *)
(* this function assumes that this one is a genuine
childpath, it tries to find the next one.
*)
(* is this actually the behavior we want? *)
(* yes, if we implement "falling through" Seq nodes in the inductive
semantics *)
fun cp_next' :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow> childpath option" where
"cp_next' t p =
(case (rev p) of
[] \<Rightarrow> None
| final#rrest \<Rightarrow>
(case (ll_get_node t (rev ((final+1)#rrest))) of
Some _ \<Rightarrow> Some (rev ((final + 1)#rrest))
| None \<Rightarrow> cp_next' t (rev rrest)
))
"
(*
(* prevent simplification until we want it *)
definition cp_next :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow> childpath option" where
"cp_next = cp_next'"
*)
(* also have cp_next_list here? *)
(* this seems not quite right... *)
(* there are a lot of cases here, we can probably cut down *)
fun cp_next :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow> childpath option"
and cp_next_list :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll list \<Rightarrow> childpath \<Rightarrow> childpath option"
where
"cp_next (_, LSeq _ l) (cp) = cp_next_list l cp"
| "cp_next _ _ = None"
| "cp_next_list [] _ = None"
| "cp_next_list _ [] = None" (* corresponds to running off the end*)
(* idea: maintain a lookahead of 1. this is why we talk about both cases *)
(* do we need to be tacking on a 0 *)
| "cp_next_list ([h]) (0#cpt) =
(case cp_next h cpt of None \<Rightarrow> None
| Some res \<Rightarrow> Some (0#res))"
| "cp_next_list ([h]) ((Suc n)#cpt) = None"
| "cp_next_list (h1#h2#t) (0#cpt) =
(case cp_next h1 cpt of
Some cp' \<Rightarrow> Some (0#cp')
| None \<Rightarrow> Some [1])"
| "cp_next_list (h#h2#t) (Suc n # cpt) =
(case cp_next_list (h2#t) (n # cpt) of
Some (n'#cp') \<Rightarrow> Some (Suc n' # cp')
| _ \<Rightarrow> None)
"
(* this was an interesting experiment but probably not a useful primitive *)
inductive cp_nexti :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow> childpath \<Rightarrow> bool" where
"\<And> t cpp q e ld n . ll_get_node t cpp = Some (q, LSeq e ld) \<Longrightarrow>
n + 1 < length ld \<Longrightarrow>
cp_nexti t (cpp@[n]) (cpp@[n+1])"
| "\<And> t cpp q e ld n cpp' . ll_get_node t cpp = Some (q, LSeq e ld) \<Longrightarrow>
n + 1 = length ld \<Longrightarrow>
cp_nexti t cpp cpp' \<Longrightarrow>
cp_nexti t (cpp@[n]) cpp'"
(*
lemma ll_validl_split :
"! x1 x3 l2 . ((x1,x3), l1@l2) \<in> ll_validl_q \<longrightarrow>
(? x2 . ((x1, x2), l1) \<in> ll_validl_q \<and>
((x2, x3), l2) \<in> ll_validl_q)"
proof(induction l1)
case Nil
then show ?case
apply(auto)
apply(rule_tac x = x1 in exI)
apply(auto simp add:ll_valid_q_ll_validl_q.intros)
done
next
case (Cons a l1)
then show ?case
apply(auto)
apply(drule_tac ll_validl_q.cases) apply(auto)
apply(drule_tac x = n' in spec) apply(drule_tac x = n'' in spec)
apply(drule_tac x = l2 in spec) apply(auto)
apply(rule_tac x = x2 in exI) apply(auto simp add:ll_valid_q_ll_validl_q.intros)
done
qed
*)
(*
inductive cp_lasti :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow> bool" where
"
*)
value "cp_next ((0,0), LSeq () [((0,0), L () (Arith ADD)),
((0,0), L () (Arith ADD)),
((0,0), L () (Arith ADD)),
((0,0), LSeq () [
((0,0), L () (Arith ADD)),
((0,0), L () (Arith SUB))
]),
((0,0), L () (Arith ADD))
]) [3,1]"
value "cp_next ((0,0), LSeq () [((0,0), L () (Arith ADD)),
((0,0), L () (Arith ADD)),
((0,0), L () (Arith ADD)),
((0,0), LSeq () [
((0,0), L () (Arith ADD)),
((0,0), L () (Arith SUB))
]),
((0,0), L () (Arith ADD))
]) []"
(* TODO: state this sample lemma showing that we always return None
instead of a nil path *)
(* TODO we need tree induction here *)
lemma cp_next_nonnil' :
"(! cp cp' . cp_next (t :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) ll) cp = Some cp' \<longrightarrow>
(? cph' cpt' . cp' = cph' # cpt')) \<and>
(! cp cp' . cp_next_list (l :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) ll list) cp = Some cp' \<longrightarrow>
(? cph' cpt' . cp' = cph' # cpt'))
"
proof(induction rule:my_ll_induct)
case (1 q e i)
then show ?case by auto
next
case (2 q e idx)
then show ?case by auto
next
case (3 q e idx n)
then show ?case by auto
next
case (4 q e idx n)
then show ?case by auto
next
case (5 q e l)
then show ?case by auto
next
case 6
then show ?case by auto
next
case (7 h l)
then show ?case
apply(auto)
apply(case_tac cp, auto) apply(case_tac a, auto)
apply(case_tac l, auto) apply(split option.split_asm) apply(auto)
apply(split option.split_asm) apply(auto)
apply(case_tac l, auto) apply(split option.split_asm) apply(auto)
apply(case_tac x2, auto)
done
qed
lemma cp_next_nonnil2 [rule_format]:
"
(! cp cp' . cp_next_list (l :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) ll list) cp = Some cp' \<longrightarrow>
(? cph' cpt' . cp' = cph' # cpt'))
"
apply(insert cp_next_nonnil')
apply(fastforce)
done
(*
"(! t cp' . cp_next t cp = Some cp' \<longrightarrow>
(? cph' cpt' . cp' = cph' # cpt'))"
proof(induction cp)
case Nil
then show ?case
apply(auto)
apply(case_tac ba, auto) apply(case_tac x52, auto)
done
next
case (Cons a cp)
then show ?case
apply(auto)
apply(case_tac ba, auto) apply(case_tac x52, auto)
apply(
qed
*)
(* need more parameters *)
(* is initial childpath [] or [0]? *)
(* if it's a Seq, go to first child
if it's a jump, go to all targeted jump nodes
if it's any other node, interpret the node
and then go to cp_next *)
(*
have a constructor where if cp_next = None, then we are at the end of the tree
and so we just return (?)
we need to refactor this somehow, the naive approach is too verbose
one idea: what if we just have a separate function that checks if the
resultant cp_next is none?
*)
(* another way to simplify this: force us to enclose the entire thing in a Seq [...]
that doesn't have a label (e.g. only allows jumps in descendents) *)
definition bogus_prog :: program where
"bogus_prog = Evm.program.make (\<lambda> _ . Some (Pc JUMPDEST)) 0"
(* make this not use type parameters? *)
(* here is the old version that has type parameters *)
(* Key - here we need to make sure that we return InstructionToEnviroment
on the cases where we are stopping...
use an empty and bogus program*)
(*
i think we can't maintain parametricity here...
also - is returning the full ellest every time the right way to do this?
*)
(*
we need to avoid the PC overflowing spuriously, which is done by always resetting the
pc to 0
*)
(* we need a version of elle_alt_sem' that uses integer indices instead of childpaths to represent the program counter
this seems less nice than using childpaths directly though.
after all what if we just used the EVM program counter directly (to describe where to point)?
then the semantics are less convincing.
*)
(*
TODO we need a "finalize" notion that runs STOP (essentially)
this will get run in every case where there is no next
child path
*)
(*
what is going on with check_resources for stop
*)
(* change this so that it is just running "stop" instead
(otherwise it is going to do check_resources and other things *)
(* idea: if in a "continue" state, then run stop
otherwise leave it alone *)
(*
fun elle_stop :: "instruction_result \<Rightarrow> constant_ctx \<Rightarrow> instruction_result" where
"elle_stop (InstructionContinue v) cc = stop v cc"
| "elle_stop ir _ = ir"
*)
(* TODO use next_state instead, or we may actually
just have to reconstruct it. *)
(*
fun elle_stop :: "instruction_result \<Rightarrow> constant_ctx \<Rightarrow> network \<Rightarrow> instruction_result" where
"elle_stop (InstructionContinue v) cc net = instruction_sem v cc (Misc STOP) net"
| "elle_stop ir _ _ = ir"
*)
(* based on next_state *)
fun elle_stop :: "instruction_result \<Rightarrow> constant_ctx \<Rightarrow> network \<Rightarrow> instruction_result" where
"elle_stop (InstructionContinue v) cc net =
(if check_resources v cc(vctx_stack v) (Misc STOP) net then
instruction_sem v cc (Misc STOP) net
else
InstructionToEnvironment (ContractFail
((case inst_stack_numbers (Misc STOP) of
(consumed, produced) =>
(if (((int (List.length(vctx_stack v)) + produced) - consumed) \<le>( 1024 :: int)) then [] else [TooLongStack])
@ (if meter_gas (Misc STOP) v cc net \<le>(vctx_gas v) then [] else [OutOfGas])
)
))
v None)"
| "elle_stop ir _ _ = ir"
(*
if check_resources v c(vctx_stack v) i net then
instruction_sem v c i net
else
InstructionToEnvironment (ContractFail
((case inst_stack_numbers i of
(consumed, produced) =>
(if (((int (List.length(vctx_stack v)) + produced) - consumed) \<le>( 1024 :: int)) then [] else [TooLongStack])
@ (if meter_gas i v c net \<le>(vctx_gas v) then [] else [OutOfGas])
)
))
v None
*)
inductive elle_alt_sem :: "('a, 'b, 'c, 'd, 'e, 'f, 'g) ll \<Rightarrow> childpath \<Rightarrow>
constant_ctx \<Rightarrow> network \<Rightarrow>
instruction_result \<Rightarrow> instruction_result \<Rightarrow> bool" where
(* last node is an instruction *)
"\<And> t cp x e i cc net st st' st''.
ll_get_node t cp = Some (x, L e i) \<Longrightarrow>
cp_next t cp = None \<Longrightarrow>
elle_instD' i (clearprog' cc) net (clearpc' st) = st' \<Longrightarrow>
elle_stop (clearpc' st') (clearprog' cc) net = st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* instruction in the middle *)
| "\<And> t cp x e i cc net cp' st st' st''.
ll_get_node t cp = Some (x, L e i) \<Longrightarrow>
cp_next t cp = Some cp' \<Longrightarrow>
elle_instD' i (setprog' cc bogus_prog) net (clearpc' st) = st' \<Longrightarrow>
elle_alt_sem t cp' cc net st' st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* last node is a label *)
| "\<And> t cp x e d cc net st st' st''.
ll_get_node t cp = Some (x, LLab e d) \<Longrightarrow>
cp_next t cp = None \<Longrightarrow>
elle_labD' (clearprog' cc) net (clearpc' st) = st' \<Longrightarrow>
elle_stop (clearpc' st') (clearprog' cc) net = st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* label in the middle *)
| "\<And> t cp x e d cp' cc net st st'.
ll_get_node t cp = Some (x, LLab e d) \<Longrightarrow>
cp_next t cp = Some cp' \<Longrightarrow>
elle_labD' (setprog' cc bogus_prog) net (clearpc' st) = st' \<Longrightarrow>
elle_alt_sem t cp' cc net st' st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* jump - perhaps worth double checking *)
(* note that this and jmpI cases do not allow us to resolve jumps at the
root. this limitation doesn't really matter in practice as we can just
wrap in a Seq []. (or do we even need that now? ) *)
| "\<And> t cpre cj xj ej dj nj cl cc net st st' st''.
ll_get_node t (cpre@cj) = Some (xj, LJmp ej dj nj) \<Longrightarrow>
dj + 1 = length cj \<Longrightarrow>
ll_get_node t (cpre@cl) = Some (xl, LLab el dl) \<Longrightarrow>
dl + 1 = length cl \<Longrightarrow>
elle_jumpD' (setprog' cc bogus_prog) net (clearpc' st) = st' \<Longrightarrow>
elle_alt_sem t (cpre@cl) cc net st' st'' \<Longrightarrow>
elle_alt_sem t (cpre@cj) cc net st st''"
(* jmpI, jump taken *)
| "\<And> t cpre cj xj ej dj nj cl cc net st st' st''.
ll_get_node t (cpre@cj) = Some (xj, LJmpI ej dj nj) \<Longrightarrow>
dj + 1 = length cj \<Longrightarrow>
ll_get_node t (cpre@cl) = Some (xl, LLab el dl) \<Longrightarrow>
dl + 1 = length cl \<Longrightarrow>
elle_jumpiD' (setprog' cc bogus_prog) net (clearpc' st) = (True, st') \<Longrightarrow>
elle_alt_sem t (cpre@cl) cc net st' st'' \<Longrightarrow>
elle_alt_sem t (cpre@cj) cc net st st''"
(* jmpI, jump not taken, at end *)
| "\<And> t cp x e d n cc net st st' st''.
ll_get_node t cp = Some (x, LJmpI e d n) \<Longrightarrow>
cp_next t cp = None \<Longrightarrow>
elle_jumpiD' (setprog' cc bogus_prog) net (clearpc' st) = (False, st') \<Longrightarrow>
elle_stop (clearpc' st') (clearprog' cc) net = st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* jmpI, jump not taken, in middle *)
| "\<And> t cp x e d n cp' cc net st st'.
ll_get_node t cp = Some (x, LJmpI e d n) \<Longrightarrow>
cp_next t cp = Some cp' \<Longrightarrow>
elle_jumpiD' (setprog' cc bogus_prog) net (clearpc' st) = (False, st') \<Longrightarrow>
elle_alt_sem t cp' cc net st' st'' \<Longrightarrow>
elle_alt_sem t cp cc net st st''"
(* empty sequence, end *)
(* should this have the same semantics as STOP ? yes, i think so*)
| "\<And> t cp cc net x e st st'.
ll_get_node t cp = Some (x, LSeq e []) \<Longrightarrow>
cp_next t cp = None \<Longrightarrow>
elle_stop (clearpc' st) (clearprog' cc) net = st' \<Longrightarrow>
elle_alt_sem t cp cc net st st'"
(* empty sequence, in the middle *)
| "\<And> t cp x e cp' cc net z z'.
ll_get_node t cp = Some (x, LSeq e []) \<Longrightarrow>
cp_next t cp = Some cp' \<Longrightarrow>
elle_alt_sem t cp' cc net z z' \<Longrightarrow>
elle_alt_sem t cp cc net z z'"
(* end vs not end *)
(* nonempty sequence *)
| "\<And> t cp x e h rest cc net z z' .
ll_get_node t cp = Some (x, LSeq e (h#rest)) \<Longrightarrow>
elle_alt_sem t (cp@[0]) cc net z z' \<Longrightarrow>
elle_alt_sem t cp cc net z z'"
(*
look up childpath (minus last element) at root
if this is
*)
(* should go in valid4 *)
lemma validate_jump_targets_spec_jumpi' :
"
(! l . ll4_validate_jump_targets l t \<longrightarrow>
(! qj ej idxj sz kj . (t, (qj, LJmpI ej idxj sz), kj) \<in> ll3'_descend \<longrightarrow>
((\<exists> qr er ls ql el idxl . t = (qr, LSeq er ls) \<and> (t, (ql, LLab el idxl), er) \<in> ll3'_descend \<and>
idxj + 1 = length kj \<and> idxl + 1 = length er \<and> fst ql = ej) \<or>
(? qd ed ls k1 k2 . (t, (qd, LSeq ed ls), k1) \<in> ll3'_descend \<and>
((qd, LSeq ed ls), (qj, LJmpI ej idxj sz), k2) \<in> ll3'_descend \<and>
kj = k1 @ k2 \<and> idxj + 1 = length k2 \<and>
( ? ql el idxl kl . ((qd, LSeq ed ls), (ql, LLab el idxl), ed) \<in> ll3'_descend \<and>
idxl + 1 = length ed \<and> fst ql = ej)) \<or>
(? n . mynth l n = Some ej \<and> length kj + n = idxj)
))) \<and>
(* need to quantify over a prefix of the list here (i think) *)
(* we need to change kj = k1 @ k2, need to offset by list length
this also requires it being nonnil, of course *)
(! q e l pref . ll4_validate_jump_targets l (q, LSeq e (pref@ls)) \<longrightarrow>
(! qj ej idxj sz kjh kjt . ((q, LSeq e ls), (qj, LJmpI ej idxj sz), kjh#kjt) \<in> ll3'_descend \<longrightarrow>
((\<exists> qr ql el idxl . ((q, LSeq e (pref@ls)), (ql, LLab el idxl), e) \<in> ll3'_descend \<and>
idxj = length kjt \<and> idxl + 1 = length e \<and> fst ql = ej) \<or>
(? qd ed lsd k1 k2 . ((q, LSeq e (pref@ls)), (qd, LSeq ed lsd), k1) \<in> ll3'_descend \<and>
((qd, LSeq ed lsd), (qj, LJmpI ej idxj sz), k2) \<in> ll3'_descend \<and>
(kjh + length pref)#kjt = k1 @ k2 \<and> idxj + 1 = length k2 \<and>
( ? ql el idxl . ((qd, LSeq ed lsd), (ql, LLab el idxl), ed) \<in> ll3'_descend \<and>
idxl + 1 = length ed \<and> fst ql = ej)) \<or>
(? n . mynth l n = Some ej \<and> length (kjh#kjt) + n = idxj)
)))
"
proof(induction rule:my_ll_induct)
case (1 q e i)
then show ?case
apply(auto)
apply(drule_tac ll3_hasdesc, auto)
done
next
case (2 q e idx)
then show ?case
apply(auto)
apply(drule_tac ll3_hasdesc, auto)
done
next
case (3 q e idx n)
then show ?case
apply(auto)
apply(drule_tac ll3_hasdesc, auto)
done
next
case (4 q e idx n)
then show ?case
apply(auto)
apply(drule_tac ll3_hasdesc, auto)
done
next
case (5 q e l)
then show ?case
(*proof of 5, without prefix *)
apply(clarsimp)
apply(case_tac e, clarsimp)
(* now bogus *)
apply(drule_tac x = "fst q" in spec, rotate_tac -1)
apply(drule_tac x = "snd q" in spec, rotate_tac -1)
apply(drule_tac x = "[]" in spec, rotate_tac -1)
apply(drule_tac x = "la" in spec, rotate_tac -1)
apply(drule_tac x = "[]" in spec, rotate_tac -1) apply(auto)
apply(drule_tac x = "a" in spec, rotate_tac -1)
apply(drule_tac x = "b" in spec, rotate_tac -1)
apply(drule_tac x = "ej" in spec, rotate_tac -1)
apply(drule_tac x = "idxj" in spec, rotate_tac -1)
apply(drule_tac x = "sz" in spec, rotate_tac -1)
apply(frule_tac ll3_descend_nonnil, auto)
apply(drule_tac x = "hd" in spec, rotate_tac -1)
apply(drule_tac x = "tl" in spec, rotate_tac -1)
apply(auto)
apply(case_tac "ll_get_node_list l (aa#list)", auto)
apply(rename_tac boo, case_tac boo, auto)
apply(drule_tac x = "fst q" in spec, rotate_tac -1)
apply(drule_tac x = "snd q" in spec, rotate_tac -1)
apply(drule_tac x = "aa#list" in spec, rotate_tac -1)
apply(drule_tac x = "la" in spec, rotate_tac -1)
apply(drule_tac x = "[]" in spec, rotate_tac -1)
apply(auto)
apply(drule_tac x = "a" in spec, rotate_tac -1)
apply(drule_tac x = "b" in spec, rotate_tac -1)
apply(drule_tac x = "ej" in spec, rotate_tac -1)
apply(drule_tac x = "idxj" in spec, rotate_tac -1)
apply(drule_tac x = "sz" in spec, rotate_tac -1)
apply(frule_tac ll3_descend_nonnil, auto)
apply(drule_tac x = "hd" in spec, rotate_tac -1)
apply(drule_tac x = "tl" in spec, rotate_tac -1)
apply(auto)
apply(case_tac "ll_get_node_list l (aa#list)", auto)
apply(rename_tac boo, case_tac boo, auto)
apply(drule_tac x = "fst q" in spec, rotate_tac -1)
apply(drule_tac x = "snd q" in spec, rotate_tac -1)
apply(drule_tac x = "aa#list" in spec, rotate_tac -1)
apply(drule_tac x = "la" in spec, rotate_tac -1)
apply(drule_tac x = "[]" in spec, rotate_tac -1)
apply(auto)
apply(drule_tac x = "a" in spec, rotate_tac -1)
apply(drule_tac x = "b" in spec, rotate_tac -1)
apply(drule_tac x = "ej" in spec, rotate_tac -1)
apply(drule_tac x = "idxj" in spec, rotate_tac -1)
apply(drule_tac x = "sz" in spec, rotate_tac -1)
apply(frule_tac ll3_descend_nonnil, auto)
apply(drule_tac x = "hd" in spec, rotate_tac -1)
apply(drule_tac x = "tl" in spec, rotate_tac -1)
apply(auto)
apply(drule_tac q = q and e = "aa#list" in ll_descend_eq_l2r_list)
(* first, prove the two descendents are equal (determinism)
then, easy contradiction*)
apply(subgoal_tac "ej = ab \<and> el = x21 \<and> bb = ba")
apply(drule_tac x = bb in spec, rotate_tac -1)
apply(drule_tac x = el in spec, rotate_tac -1)
apply(drule_tac x = "length list" in spec, rotate_tac -1)
apply(auto)
done
next
case 6
then show ?case
apply(clarsimp)
apply(drule_tac ll3_hasdesc2, auto)
done
next
case (7 h l)
then show ?case
apply(clarsimp)
apply(case_tac e, auto)
apply(case_tac kjh, auto)
apply(drule_tac x = "None#la" in spec, auto) apply(rotate_tac -1)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(case_tac kjt, auto)
apply(case_tac "mynth (None # la) idxj", auto)
apply(case_tac idxj, auto)
apply(drule_tac ll_descend_eq_l2r)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x =ba in spec, rotate_tac -1)
apply(drule_tac x = ej in spec, rotate_tac -1)
apply(drule_tac x = idxj in spec, rotate_tac -1)
apply(drule_tac x = sz in spec, rotate_tac -1)
apply(drule_tac x = "ab#list" in spec, rotate_tac -1)
apply(auto)
apply(rule_tac x = ac in exI)
apply(rule_tac x = bb in exI)
apply(rule_tac x = er in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "[length pref]" in exI)
apply(auto)
apply(auto simp add:ll3'_descend.intros)
(* next, length pref cons ... *)
apply(rule_tac x = ac in exI)
apply(rule_tac x = bb in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "length pref#k1" in exI)
apply(auto)
apply(subgoal_tac "(((a, b), llt.LSeq [] (pref @ h # l)),
((ac, bb), llt.LSeq ed ls), (0 + length pref) # k1)
\<in> ll3'_descend")
apply(rule_tac[2] a = a and b = b in ll_descend_prefix)
apply(auto)
apply(rule_tac ll_descend_eq_l2r, auto)
apply(case_tac h, auto)
apply(drule_tac k = k1 in ll_descend_eq_r2l) apply(auto)
apply(case_tac n, auto)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(rotate_tac 1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = "[]" in spec, rotate_tac -1)
apply(drule_tac x = la in spec, rotate_tac -1)
apply(drule_tac x = "pref@[h]" in spec, rotate_tac -1) apply(auto)
apply(drule_tac q = "(0,0)" and e = "[]" in ll_descend_eq_l2r_list)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x = ba in spec, rotate_tac -1)
apply(drule_tac x = ej in spec, rotate_tac -1)
apply(drule_tac x = idxj in spec, rotate_tac -1)
apply(drule_tac x = sz in spec, rotate_tac -1)
apply(drule_tac x = nat in spec, rotate_tac -1)
apply(drule_tac x = kjt in spec, rotate_tac -1)
apply(auto)
apply(rule_tac x = ab in exI)
apply(rule_tac x = bb in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = lsd in exI)
apply(rule_tac x = k1 in exI) apply(auto)
apply(drule_tac k = k1 in ll3'_descend_relabelq) apply(auto)
apply(case_tac "ll_get_node_list (pref @ h # l) (ab # list)", auto)
apply(rename_tac boo, case_tac boo, auto)
apply(case_tac kjh, auto)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(drule_tac x = "Some ac # la" in spec, auto) apply(rotate_tac -1)
apply(case_tac kjt, auto)
apply(case_tac "mynth (Some ac # la) idxj", auto)
apply(case_tac idxj, auto)
apply(drule_tac ll_descend_eq_l2r)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x = ba in spec, rotate_tac -1)
apply(drule_tac x = ej in spec, rotate_tac -1)
apply(drule_tac x = idxj in spec, rotate_tac -1)
apply(drule_tac x = sz in spec, rotate_tac -1)
apply(drule_tac x = "ad#lista" in spec, rotate_tac -1)
apply(auto)
apply(rule_tac x = ae in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = er in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "[length pref]" in exI) apply(auto)
apply(subgoal_tac "(((a, b),
llt.LSeq (ab # list)
(pref @ ((ae, bc), llt.LSeq er ls) # l)),
((ae, bc), llt.LSeq er ls), [0 + length pref])
\<in> ll3'_descend")
apply(rule_tac [2] a = a and b = b in ll_descend_prefix) apply(auto)
apply(auto simp add:ll3'_descend.intros)
apply(rule_tac x = ae in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "length pref # k1" in exI) apply(auto)
apply(subgoal_tac "(((a, b), llt.LSeq (ab # list) (pref @ h # l)),
((ae, bc), llt.LSeq ed ls), (0 + length pref) # k1)
\<in> ll3'_descend")
apply(rule_tac [2] a = a and b = b in ll_descend_prefix) apply(auto)
apply(rule_tac ll_descend_eq_l2r, auto)
apply(case_tac h, auto)
apply(drule_tac k = k1 in ll_descend_eq_r2l)
apply(auto)
apply(case_tac n, auto)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(rotate_tac 1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = "ab#list" in spec, rotate_tac -1)
apply(drule_tac x = "la" in spec, rotate_tac -1)
apply(drule_tac x = "pref @ [h]" in spec, rotate_tac -1) apply(auto)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x = ba in spec, rotate_tac -1)
apply(drule_tac x = ej in spec, rotate_tac -1)
apply(drule_tac x = idxj in spec, rotate_tac -1)
apply(drule_tac x = sz in spec, rotate_tac -1)
apply(drule_tac x = nat in spec, rotate_tac -1)
apply(drule_tac x = kjt in spec, rotate_tac -1)
apply(drule_tac q = "(0,0)" and e = "(ab # list)" and kh = "nat" in ll_descend_eq_l2r_list)
apply(auto)
apply(rule_tac x = ad in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = lsd in exI)
apply(rule_tac x = k1 in exI)
apply(auto)
apply(rule_tac ll3'_descend_relabelq) apply(auto)
apply(case_tac "ll_get_node_list (pref @ h # l) (ab # list)", auto)
apply(rename_tac boo, case_tac boo, auto)
apply(case_tac kjh, auto)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(drule_tac x = "Some ac # la" in spec, auto) apply(rotate_tac -1)
apply(case_tac kjt, auto)
apply(case_tac "mynth (Some ac # la) idxj", auto)
apply(case_tac idxj, auto)
apply(rotate_tac -4)
apply(drule_tac x = bb in spec, rotate_tac -1)
apply(drule_tac x = x21 in spec, rotate_tac -1)
apply(drule_tac x = "length list" in spec, rotate_tac -1)
apply(drule_tac q = "(a, b)" and e = "ab#list" in ll_descend_eq_l2r_list) apply(auto)
apply(drule_tac ll_descend_eq_l2r)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x = ba in spec, rotate_tac -1)
apply(drule_tac x = ej in spec, rotate_tac -1)
apply(drule_tac x = idxj in spec, rotate_tac -1)
apply(drule_tac x = sz in spec, rotate_tac -1)
apply(drule_tac x = "ad#lista" in spec, rotate_tac -1)
apply(auto)
apply(rule_tac x = ae in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = er in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "[length pref]" in exI)
apply(auto)
apply(subgoal_tac "(((a, b), llt.LSeq (ab # list) (pref @ ((ae, bc), llt.LSeq er ls) # l)),
((ae, bc), llt.LSeq er ls), [0 + length pref])
\<in> ll3'_descend")
apply(rule_tac[2] ll_descend_prefix) apply(auto)
apply(rule_tac ll_descend_eq_l2r, auto)
apply(rule_tac x = ae in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = ls in exI)
apply(rule_tac x = "length pref#k1" in exI) apply(auto)
apply(subgoal_tac "Suc idxl = length ed \<Longrightarrow>
(((a, b), llt.LSeq (ab # list) (pref @ h # l)), ((ae, bc), llt.LSeq ed ls),
(0 +length pref) # k1)
\<in> ll3'_descend")
apply(rule_tac [2] ll_descend_prefix) apply(auto)
apply(rule_tac ll_descend_eq_l2r, auto)
apply(case_tac h) apply(auto)
apply(drule_tac k = k1 in ll_descend_eq_r2l) apply(auto)
apply(case_tac n, auto)
apply(rotate_tac 2)
apply(drule_tac x = bb in spec, rotate_tac -1)
apply(drule_tac x = x21 in spec, rotate_tac -1)
apply(drule_tac x = "length list" in spec, rotate_tac -1)
apply(drule_tac e = "ab#list" and q = "(a,b)" in ll_descend_eq_l2r_list)
apply(auto)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(rotate_tac 1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = 0 in spec, rotate_tac -1)
apply(drule_tac x = "ab#list" in spec, rotate_tac -1)
apply(drule_tac x = "la" in spec, rotate_tac -1)
apply(drule_tac x = "pref @ [h]" in spec, rotate_tac -1) apply(auto)
apply(drule_tac x = aa in spec, rotate_tac -1)
apply(drule_tac x = ba in spec, rotate_tac -1)
apply(drule_tac x = "ej" in spec, rotate_tac -1)
apply(drule_tac x = "idxj" in spec, rotate_tac -1)
apply(drule_tac x = "sz" in spec, rotate_tac -1)
apply(drule_tac x = "nat" in spec, rotate_tac -1)
apply(drule_tac x = "kjt" in spec, rotate_tac -1)
apply(drule_tac l = l and q = "(0,0)" and e = "ab#list" in ll_descend_eq_l2r_list)
apply(auto)
apply(rotate_tac -1)
apply(frule_tac ll_descend_eq_r2l, auto)
apply(drule_tac q' = "(a, b)" in ll3'_descend_relabelq) apply(auto)
apply(rotate_tac 1)
apply(drule_tac x = bc in spec, rotate_tac -1)
apply(drule_tac x = el in spec, rotate_tac -1)
apply(drule_tac x = "length list" in spec, rotate_tac -1)
apply(auto)
apply(rule_tac x = ad in exI)
apply(rule_tac x = bc in exI)
apply(rule_tac x = ed in exI)
apply(rule_tac x = lsd in exI)
apply(rule_tac x = k1 in exI)
apply(auto)
apply(rule_tac ll3'_descend_relabelq)
apply(auto)
done
qed
lemma validate_jump_targets_spec_jumpi [rule_format] :
"
(! l . ll4_validate_jump_targets l t \<longrightarrow>
(! qj ej idxj sz kj . (t, (qj, LJmpI ej idxj sz), kj) \<in> ll3'_descend \<longrightarrow>
((\<exists> qr er ls ql el idxl . t = (qr, LSeq er ls) \<and> (t, (ql, LLab el idxl), er) \<in> ll3'_descend \<and>
idxj + 1 = length kj \<and> idxl + 1 = length er \<and> fst ql = ej) \<or>
(? qd ed ls k1 k2 . (t, (qd, LSeq ed ls), k1) \<in> ll3'_descend \<and>
((qd, LSeq ed ls), (qj, LJmpI ej idxj sz), k2) \<in> ll3'_descend \<and>
kj = k1 @ k2 \<and> idxj + 1 = length k2 \<and>
( ? ql el idxl kl . ((qd, LSeq ed ls), (ql, LLab el idxl), ed) \<in> ll3'_descend \<and>
idxl + 1 = length ed \<and> fst ql = ej)) \<or>
(? n . mynth l n = Some ej \<and> length kj + n = idxj)
)))
"
apply(insert validate_jump_targets_spec_jumpi')
apply(auto)
done
(* need to take into account the fact that PC may be updated *)
lemma elle_alt_sem_halted :
"elle_alt_sem t cp cc net st st' \<Longrightarrow>
(! x y z . st = InstructionToEnvironment x y z \<longrightarrow>
st' = InstructionToEnvironment x (y \<lparr> vctx_pc := 0 \<rparr>) (z)
)"
proof(induction rule: elle_alt_sem.induct)
case (1 t cp x e i cc net st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (2 t cp x e i cc net cp' st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (3 t cp x e d cc net st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (4 st'' t cp x e d cp' cc net st st')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (5 xl el dl t cpre cj xj ej dj nj cl cc net st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (6 xl el dl t cpre cj xj ej dj nj cl cc net st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (7 t cp x e d n cc net st st' st'')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (8 st'' t cp x e d n cp' cc net st st')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (9 t cp cc net x e st st')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (10 t cp x e cp' cc net z z')
then show ?case
apply(auto simp add:clearpc'_def)
done
next
case (11 t cp x e h rest cc net z z')
then show ?case
apply(auto simp add:clearpc'_def)
done
qed
(*
*)
fun clearprog_cctx :: "constant_ctx \<Rightarrow> constant_ctx" where
"clearprog_cctx e =
(e \<lparr> cctx_program := empty_program \<rparr>)"
(* TODO: be able to load at an arbitrary position (not just 0)? *)
(* this one seems to have problems with reduction, so I'm not using it *)
fun ll4_load_cctx :: "constant_ctx \<Rightarrow> ll4 \<Rightarrow> constant_ctx" where
"ll4_load_cctx cc t =
(cc \<lparr> cctx_program :=
Evm.program_of_lst (codegen' t) ProgramInAvl.program_content_of_lst
\<rparr>)"
(* based on ProgramList.program_list_of_lst *)
(* idea: here, we validate the STACK sizes *)
(* TODO: separate out the validation phase *)
fun program_list_of_lst_validate :: "inst list \<Rightarrow> inst list option" where
" program_list_of_lst_validate [] = Some []"
|" program_list_of_lst_validate (Stack (PUSH_N bytes) # rest) =
(if length bytes \<le> 0 then None
else (if length bytes > 32 then None
else (case program_list_of_lst_validate rest of
None \<Rightarrow> None
| Some rest' \<Rightarrow>
Some ([Stack (PUSH_N bytes)] @
map(\<lambda>x. Unknown x) bytes @ rest'))))"
|" program_list_of_lst_validate (i # rest) =
(case program_list_of_lst_validate rest of None \<Rightarrow> None | Some rest' \<Rightarrow> Some (i#rest'))"
(* TODO: will codegen' work correctly on the output of this? *)
(* seeing if the list version is easier to work with *)
(* this one doesn't seem to quite be what we want *)
(*
fun ll4_load_lst_map_cctx :: "constant_ctx \<Rightarrow> ll4 \<Rightarrow> constant_ctx" where
"ll4_load_lst_map_cctx cc t =
(cc \<lparr> cctx_program := Evm.program_of_lst (codegen' t) (\<lambda> il i . program_map_of_lst 0 il (nat i)) \<rparr>)"
*)
fun ll4_load_lst_cctx :: "constant_ctx \<Rightarrow> ll4 \<Rightarrow> constant_ctx" where
"ll4_load_lst_cctx cc t =
(cc \<lparr> cctx_program :=
Evm.program.make (\<lambda> i . index (program_list_of_lst (codegen' t)) (nat i))
(length (program_list_of_lst (codegen' t)))\<rparr>)"
(* codegen check checks to make sure stack instructions match their length *)
(* load_lst_validate makes sure there are no pushes <1 or >32 bytes *)
fun ll4_load_lst_validate :: "constant_ctx \<Rightarrow> ll4 \<Rightarrow> constant_ctx option" where
"ll4_load_lst_validate cc t =
(case codegen'_check t of None \<Rightarrow> None
| Some tc \<Rightarrow>
(case program_list_of_lst_validate tc of None \<Rightarrow> None
| Some l \<Rightarrow> Some (cc \<lparr> cctx_program :=
Evm.program.make (\<lambda> i . index l (nat i))
(length l) \<rparr>)))"
lemma program_list_of_lst_validate_split [rule_format] :
"(! b c . program_list_of_lst_validate (a @ b) = Some c \<longrightarrow>
(? a' . program_list_of_lst_validate a = Some a' \<and>
(? b' . program_list_of_lst_validate b = Some b' \<and>
c = a' @ b')))"
proof(induction a)
case Nil
then show ?case
apply(auto)
done
next
case (Cons a b)
then show ?case
apply(auto)
apply(case_tac a, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(case_tac x10, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(case_tac x2, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
apply(simp split:Option.option.split_asm Option.option.split, auto)
done
qed
fun setpc_ir :: "instruction_result \<Rightarrow> nat \<Rightarrow> instruction_result" where
"setpc_ir ir n =
irmap (\<lambda> v . v \<lparr> vctx_pc := (int n) \<rparr>) ir"
(* this is the basic idea of the theorem statement
the only thing we need to do is specify the precise
relationship between states - i.e. relationship between the cp that the
semantics is starting from and the pc that the program starts from *)
(*
additional assumption - we need to be valid3', and our first element of the
qvalidity has to be 0
*)
(* program_sem_t appears to be way too slow to execute - perhaps better
to switch back... *)
(* prove this holds for any non-continuing final state
(problem - will we need to make this hold inductively for non-final states?)
(will we have a problem with the hardcoded zero start? maybe we need to
subtract it from the final pc)
*)
(*
lemma elle_alt_correct :
"elle_alt_sem ((0, sz), (t :: ll4t)) elle_interp cp (ir, cc, net) (ir', cc', net') \<Longrightarrow>
((0, sz), t) \<in> ll_valid3' \<Longrightarrow>
ll4_validate_jump_targets [] ((0,sz),t) \<Longrightarrow>
program_sem_t (ll4_load_cctx cc ((0,sz),t)) net ir = ir2' \<Longrightarrow>
setpc_ir ir' 0 = setpc_ir ir2' 0
"
*)
(* Should we use "erreq", which throws away the details of the error *)
(* perhaps the issue is that we are sort of implicitly destructing on
the three-tuple in this inductive statement *)
(* est should probably be a record
fst \<rightarrow> instruction result
fst . snd \<rightarrow> cctx
snd . snd \<rightarrow> net
*)
(* need new predicates: isi2e and iscont *)
fun isi2e :: "instruction_result \<Rightarrow> bool" where
"isi2e (InstructionToEnvironment _ _ _) = True"
| "isi2e _ = False"
definition iscont :: "instruction_result \<Rightarrow> bool" where
"iscont i = (\<not> (isi2e i) )"
(* from examples/termination/RunList *)
(*
theorem program_content_first [simp] :
"program_map_of_lst 0 (a # lst) 0 = Some a"
apply(cases a)
apply(auto)
apply(subst program_list_content_eq4)
apply(cases "get_stack a")
apply(auto)
done
*)
(* need a couple lemmas about program_map_of_lst *)
(* will it suffice to only consider computations that end in a successful result?
this seems sketchy, but I guess the idea is "computation suffixes"
*)
lemma qvalid_less' :
"(((a, (t :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) llt)) \<in> ll_valid_q) \<longrightarrow> fst a \<le> snd a) \<and>
((((a1, a2), (l:: ('a, 'b, 'c, 'd, 'e, 'f, 'g) ll list)) \<in> ll_validl_q \<longrightarrow> a1 \<le> a2))
"
apply(induction rule: ll_valid_q_ll_validl_q.induct, auto)
done
lemma qvalid_less1 :
"((a, (t :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) llt)) \<in> ll_valid_q) \<Longrightarrow> fst a \<le> snd a"
apply(insert qvalid_less') apply(fastforce)
done
lemma qvalid_less2 :
"(x, (l :: ('a, 'b, 'c, 'd, 'e, 'f, 'g) ll list)) \<in> ll_validl_q \<Longrightarrow> fst x \<le> snd x"
apply(insert qvalid_less') apply(case_tac x)
apply(fastforce)
done
(* we need to rule out invalid (too long/ too short)
stack instructions *)