Theory Fun1
section "Disproof of Relative Security for fun1"
theory Fun1
imports "../Instance_IMP/Instance_Secret_IMem"
"Secret_Directed_Unwinding.SD_Unwinding_fin"
begin
subsection "Function definition and Boilerplate"
no_notation bot (‹⊥›)
consts NN :: nat
consts input :: int
definition aa1 :: "avname" where "aa1 = ''a1''"
definition aa2 :: "avname" where "aa2 = ''a2''"
definition vv :: "avname" where "vv = ''v''"
definition xx :: "avname" where "xx = ''i''"
definition tt :: "avname" where "tt = ''tt''"
lemma NN_suc[simp]:"nat (NN + 1) = Suc (nat NN)"
by force
lemma NN:"NN≥0" by auto
lemmas vvars_defs = aa1_def aa2_def vv_def xx_def tt_def
lemma vvars_dff[simp]:
"aa1 ≠ aa2" "aa1 ≠ vv" "aa1 ≠ xx" "aa1 ≠ tt"
"aa2 ≠ aa1" "aa2 ≠ vv" "aa2 ≠ xx" "aa2 ≠ tt"
"vv ≠ aa1" "vv ≠ aa2" "vv ≠ xx" "vv ≠ tt"
"xx ≠ aa1" "xx ≠ aa2" "xx ≠ vv" "xx ≠ tt"
"tt ≠ aa1" "tt ≠ aa2" "tt ≠ vv" "tt ≠ xx"
unfolding vvars_defs by auto
consts size_aa1 :: nat
consts size_aa2 :: nat
definition "s_add = {a. a ≠ nat NN+1}"
fun vs⇩0::"char list ⇒ int" where
"vs⇩0 x = 0"
lemma vs0[simp]:"(λx. 0) = vs⇩0" unfolding vs⇩0.simps by simp
fun as:: "char list ⇒ nat × nat" where
"as a = (if a = aa1 then (0, nat NN)
else (if a = aa2 then (nat NN, nat size_aa2)
else (nat size_aa2,0)))"
definition "avst' ≡ (Avstore as)"
lemmas avst_defs = avst'_def as.simps
lemma avstore_loc[simp]:"Avstore (λa. if a = aa1 then (0, nat NN) else if a = aa2 then (nat NN, nat size_aa2) else (nat size_aa2, 0)) =
avst'"
unfolding avst_defs by auto
abbreviation "read_add ≡ {a. a ≠ (nat NN + 1)}"
fun initVstore :: "vstore ⇒ bool" where
"initVstore (Vstore vst) = (vst = vs⇩0)"
fun initAvstore :: "avstore ⇒ bool" where
"initAvstore avst = (avst = avst')"
fun initHeap::"(nat ⇒ int) ⇒ bool" where
"initHeap h = (∀x∈read_add. h x = 0)"
lemma initAvstore_0[intro]:"initAvstore avst' ⟹ array_base aa1 avst' = 0"
unfolding avst_defs array_base_def
by (smt (verit, del_insts) avstore.case fstI)
fun istate ::"state ⇒ bool" where
"istate s =
(initVstore (getVstore s) ∧
initAvstore (getAvstore s) ∧
initHeap (getHheap s))"
definition "prog ≡
[
Start ,
Input U xx ,
tt ::= (N 0),
IfJump (Less (V xx) (N NN)) 4 5,
tt ::= (VA aa2 (Times (VA aa1 (V xx)) (N 512))) ,
Output U (V tt)
]"
lemma cases_5: "(i::pcounter) = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨ i = 5 ∨ i > 5"
apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
. . . . . .
lemma xx_NN_cases: "vs xx < (int NN) ∨ vs xx ≥ (int NN)" by auto
lemma is_If_pcOf[simp]:
"pcOf cfg < 6 ⟹ is_IfJump (prog ! (pcOf cfg)) ⟷ pcOf cfg = 3"
apply(cases cfg) subgoal for pc s using cases_5[of "pcOf cfg "]
apply (auto simp: prog_def) . .
lemma is_If_pc[simp]:
"pc < 6 ⟹ is_IfJump (prog ! pc) ⟷ pc = 3"
using cases_5[of pc]
by (auto simp: prog_def)
lemma eq_Fence_pc[simp]:
"pc < 6 ⟹ prog ! pc ≠ Fence"
using cases_5[of pc]
by (auto simp: prog_def)
fun mispred :: "predState ⇒ pcounter list ⇒ bool" where
"mispred p pc = (if pc = [3] then True else False)"
fun resolve :: "predState ⇒ pcounter list ⇒ bool" where
"resolve p pc = (if pc = [5,5] then True else False)"
consts update :: "predState ⇒ pcounter list ⇒ predState"
consts pstate⇩0 :: predState