Theory Fun5
section "Proof of Relative Security for fun5"
theory Fun5
imports "../Instance_IMP/Instance_Secret_IMem"
"Relative_Security.Unwinding"
begin
subsection "Function definition and Boilerplate"
no_notation bot (‹⊥›)
consts NN :: nat
consts SS :: nat
lemma NN: "int NN ≥ 0" and SS: "int SS≥0" by auto
definition aa1 :: "avname" where "aa1 = ''a1''"
definition aa2 :: "avname" where "aa2 = ''a2''"
definition vv :: "avname" where "vv = ''v''"
definition xx :: "avname" where "xx = ''x''"
definition tt :: "avname" where "tt = ''y''"
definition temp :: "avname" where "temp = ''temp''"
lemmas vvars_defs = aa1_def aa2_def vv_def xx_def tt_def temp_def
lemma vvars_dff[simp]:
"aa1 ≠ aa2" "aa1 ≠ vv" "aa1 ≠ xx" "aa1 ≠ temp" "aa1 ≠ tt"
"aa2 ≠ aa1" "aa2 ≠ vv" "aa2 ≠ xx" "aa2 ≠ temp" "aa2 ≠ tt"
"vv ≠ aa1" "vv ≠ aa2" "vv ≠ xx" "vv ≠ temp" "vv ≠ tt"
"xx ≠ aa1" "xx ≠ aa2" "xx ≠ vv" "xx ≠ temp" "xx ≠ tt"
"tt ≠ aa1" "tt ≠ aa2" "tt ≠ vv" "tt ≠ temp" "tt ≠ xx"
"temp ≠ aa1" "temp ≠ aa2" "temp ≠ vv" "temp ≠ xx" "temp ≠ tt"
unfolding vvars_defs by auto
consts size_aa1 :: nat
consts size_aa2 :: nat
fun initAvstore :: "avstore ⇒ bool" where
"initAvstore (Avstore as) = (as aa1 = (0, size_aa1) ∧ as aa2 = (size_aa1, size_aa2))"
fun istate ::"state ⇒ bool" where
"istate s = (initAvstore (getAvstore s))"
definition "prog ≡
[
Start ,
tt ::= (N 0),
xx ::= (N 1),
IfJump (Not (Eq (V xx) (N 0))) 4 11 ,
Input U xx ,
IfJump (Less (V xx) (N NN)) 6 10 ,
vv ::= VA aa1 (V xx) ,
Fence ,
tt ::= (VA aa2 (Times (V vv) (N SS))) ,
Output U (V tt) ,
Jump 3,
Output U (N 0)
]"
definition "PC ≡ {0..11}"
definition "beforeWhile = {0,1,2}"
definition "inWhile = {3..11}"
definition "startOfWhileThen = 4"
definition "startOfIfThen = 6"
definition "inThenIfBeforeFence = {6,7}"
definition "startOfElseBranch = 10"
definition "inElseIf = {10,3,4,11}"
definition "whileElse = 11"
fun leftWhileSpec where
"leftWhileSpec cfg cfg' =
(pcOf cfg = whileElse ∧
pcOf cfg' = startOfWhileThen)"
fun rightWhileSpec where
"rightWhileSpec cfg cfg' =
(pcOf cfg = startOfWhileThen ∧
pcOf cfg' = whileElse)"
fun whileSpeculation where
"whileSpeculation cfg cfg' =
(leftWhileSpec cfg cfg' ∨
rightWhileSpec cfg cfg')"
lemmas whileSpec_def = whileSpeculation.simps
startOfWhileThen_def
whileElse_def
lemmas whileSpec_defs = whileSpec_def
leftWhileSpec.simps
rightWhileSpec.simps
lemma cases_12: "(i::pcounter) = 0 ∨ i = 1 ∨ i = 2 ∨ i = 3 ∨ i = 4 ∨ i = 5 ∨
i = 6 ∨ i = 7 ∨ i = 8 ∨ i = 9 ∨ i = 10 ∨ i = 11 ∨ i = 12 ∨ i > 12"
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)
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)
subgoal for i apply(cases i, simp_all)
subgoal for i apply(cases i, simp_all)
. . . . . . . . . . . . .
lemma xx_0_cases: "vs xx = 0 ∨ vs xx ≠ 0" by auto
lemma xx_NN_cases: "vs xx < int NN ∨ vs xx ≥ int NN" by auto
lemma is_IfJump_pcOf[simp]:
"pcOf cfg < 12 ⟹ is_IfJump (prog ! (pcOf cfg)) ⟷ pcOf cfg = 3 ∨ pcOf cfg = 5"
apply(cases cfg) subgoal for pc s using cases_12[of "pcOf cfg "]
by (auto simp: prog_def) .
lemma is_IfJump_pc[simp]:
"pc < 12 ⟹ is_IfJump (prog ! pc) ⟷ pc = 3 ∨ pc = 5"
using cases_12[of pc]
by (auto simp: prog_def)
lemma eq_Fence_pc[simp]:
"pc < 12 ⟹ prog ! pc = Fence ⟷ pc = 7"
using cases_12[of pc]
by (auto simp: prog_def)
lemma output1[simp]:
"prog ! 9 = Output U (V tt)" by(simp add: prog_def)
lemma output2[simp]:
"prog ! 11 = Output U (N 0)" by(simp add: prog_def)
lemma is_if[simp]:"is_IfJump (prog ! 3)" by(simp add: prog_def)
lemma is_nif1[simp]:"¬is_IfJump (prog ! 6)" by(simp add: prog_def)
lemma is_nif2[simp]:"¬is_IfJump (prog ! 7)" by(simp add: prog_def)
lemma is_nin1[simp]:"¬ is_getInput (prog ! 6)" by(simp add: prog_def)
lemma is_nout1[simp]:"¬ is_Output (prog ! 6)" by(simp add: prog_def)
lemma is_nin2[simp]:"¬ is_getInput (prog ! 10)" by(simp add: prog_def)
lemma is_nout2[simp]:"¬ is_Output (prog ! 10)" by(simp add: prog_def)
lemma fence[simp]:"prog ! 7 = Fence" by(simp add: prog_def)
lemma nfence[simp]:"prog ! 6 ≠ Fence" by(simp add: prog_def)
consts mispred :: "predState ⇒ pcounter list ⇒ bool"
fun resolve :: "predState ⇒ pcounter list ⇒ bool" where
"resolve p pc =
(if (set pc = {4,11} ∨ (6 ∈ set pc ∧ (4 ∈ set pc ∨ 11 ∈ set pc)))
then True else False)"
lemma resolve_63: "¬resolve p [6,3]" by auto
lemma resolve_64: "resolve p [6,4]" by auto
lemma resolve_611: "resolve p [6,11]" by auto
lemma resolve_106: "¬resolve p [10,6]" by auto
consts update :: "predState ⇒ pcounter list ⇒ predState"
consts initPstate :: predState