Theory Fun6
section "Proof of Relative Security for fun6"
theory Fun6
imports "../Instance_IMP/Instance_Secret_IMem_Inp"
"Relative_Security.Unwinding"
begin
subsection "Function definition and Boilerplate"
no_notation bot ("⊥")
consts NN :: nat
lemma NN: "NN ≥ 0" by auto
definition aa1 :: "avname" where "aa1 = ''a1''"
definition aa2 :: "avname" where "aa2 = ''a2''"
definition vv :: "vname" where "vv = ''v''"
definition tt :: "vname" where "tt = ''y''"
lemmas vvars_defs = aa1_def aa2_def vv_def xx_def tt_def yy_def ffile_def
lemma vvars_dff[simp]:
"aa1 ≠ aa2" "aa1 ≠ vv" "aa1 ≠ xx" "aa1 ≠ yy" "aa1 ≠ tt" "aa1 ≠ ffile"
"aa2 ≠ aa1" "aa2 ≠ vv" "aa2 ≠ xx" "aa2 ≠ yy" "aa2 ≠ tt" "aa2 ≠ ffile"
"vv ≠ aa1" "vv ≠ aa2" "vv ≠ xx" "vv ≠ yy" "vv ≠ tt" "vv ≠ ffile"
"xx ≠ aa1" "xx ≠ aa2" "xx ≠ vv" "xx ≠ yy" "xx ≠ tt" "xx ≠ ffile"
"tt ≠ aa1" "tt ≠ aa2" "tt ≠ vv" "tt ≠ yy" "tt ≠ xx" "tt ≠ ffile"
"yy ≠ aa1" "yy ≠ aa2" "yy ≠ vv" "yy ≠ xx" "yy ≠ tt" "yy ≠ ffile"
"ffile ≠ aa1" "ffile ≠ aa2" "ffile ≠ vv" "ffile ≠ xx" "ffile ≠ tt" "ffile ≠ yy"
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 13 ,
Input U xx ,
Input T yy ,
IfJump (Less (V xx) (N NN)) 7 12 ,
vv ::= VA aa1 (V xx) ,
writeSecretOnFile,
Fence ,
tt ::= (VA aa2 (Times (V vv) (N 512))) ,
Output U (V tt) ,
Jump 3,
Output U (N 0)
]"
definition "PC ≡ {0..13}"
definition "beforeWhile = {0,1,2}"
definition "afterWhile = {3..13}"
definition "startOfWhileThen = 4"
definition "startOfIfThen = 7"
definition "inThenIfBeforeOutput = {7,8}"
definition "startOfElseBranch = 12"
definition "inElseIf = {12,3,4,13}"
definition "whileElse = 13"
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_14: "(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 = 13 ∨ i = 14 ∨ i > 14"
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)
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_If_pcOf[simp]:
"pcOf cfg < 14 ⟹ is_IfJump (prog ! (pcOf cfg)) ⟷ pcOf cfg = 3 ∨ pcOf cfg = 6"
apply(cases cfg) using cases_14[of "pcOf cfg"] by (auto simp: prog_def)
lemma is_If_pc[simp]:
"pc < 14 ⟹ is_IfJump (prog ! pc) ⟷ pc = 3 ∨ pc = 6"
using cases_14[of pc] by (auto simp: prog_def)
lemma eq_Fence_pc[simp]:
"pc < 14 ⟹ prog ! pc = Fence ⟷ pc = 9"
using cases_14[of pc] by (auto simp: prog_def)
lemma output1[simp]:"prog ! 11 = Output U (V tt)" by(simp add: prog_def)
lemma output2[simp]:"prog ! 13 = 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 ! 7)" by(simp add: prog_def)
lemma is_nif2[simp]:"¬is_IfJump (prog ! 8)" by(simp add: prog_def)
lemma getInput_not6[simp]:"¬ is_getInput (prog ! 6)" by(simp add: prog_def)
lemma Output_not6[simp]:"¬ is_Output (prog ! 6)" by(simp add: prog_def)
lemma getInput_not7[simp]:"¬ is_getInput (prog ! 7)" by(simp add: prog_def)
lemma Output_not7[simp]:"¬ is_Output (prog ! 7)" by(simp add: prog_def)
lemma getInput_not8[simp]:"¬ is_getInput (prog ! 8)" by(simp add: prog_def)
lemma Output_not8[simp]:"is_Output (prog ! 8)" by(simp add: prog_def)
lemma is_nif[simp]:"¬ is_IfJump (prog ! 9)" by(simp add: prog_def)
lemma getInput_not10[simp]:"¬ is_getInput (prog ! 10)" by(simp add: prog_def)
lemma Output_not10[simp]:"¬ is_Output (prog ! 10)" by(simp add: prog_def)
lemma getInput_not12[simp]:"¬ is_getInput (prog ! 12)" by(simp add: prog_def)
lemma Output_not12[simp]:"¬ is_Output (prog ! 12)" by(simp add: prog_def)
lemma fence[simp]:"prog ! 9 = Fence" by(simp add: prog_def)
lemma nfence[simp]:"prog ! 7 ≠ 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,13} ∨ (7 ∈ set pc ∧ (4 ∈ set pc ∨ 13 ∈ set pc)) ∨ pc = [12,8])
then True else False)"
lemma resolve_73: "¬resolve p [7,3]" by auto
lemma resolve_74: "resolve p [7,4]" by auto
lemma resolve_713: "resolve p [7,13]" by auto
lemma resolve_127: "¬resolve p [12,7]" by auto
lemma resolve_129: "¬resolve p [12,9]" by auto
consts update :: "predState ⇒ pcounter list ⇒ predState"
consts initPstate :: predState