dassarthak18/phi3.5-fstar-lora
Text Generation
•
Updated
messages
listlengths 2
2
|
|---|
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Type0\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule FStar.Stubs.Tactics.Types\n\nopen FStar.Stubs.Reflection.Types\ninclude FStar.Stubs.Tactics.Common\ninclude FStar.Stubs.TypeChecker.Core\n\nassume new type goal\nassume new type proofstate\n\n(* Returns the active goals *)\nval goals_of : proofstate -> list goal\n(* Returns the goals marked for SMT *)\nval smt_goals_of : proofstate -> list goal\n\n(* Inspecting a goal *)\nval goal_env : goal -> env\nval goal_type : goal -> typ\nval goal_witness : goal -> term\nval is_guard : goal -> bool (* A bit of helper info: did this goal come from a VC guard? *)\n\nval get_label : goal -> string\nval set_label : string -> goal -> goal\n\n(* Tracing *)\nval incr_depth : proofstate -> proofstate\nval decr_depth : proofstate -> proofstate\n(* [tracepoint] always returns true. We do not use unit to prevent\nerasure. *)\nval tracepoint : proofstate -> b:bool{b == true}\nval set_proofstate_range : proofstate -> FStar.Range.range -> proofstate\n\ntype direction =\n | TopDown\n | BottomUp\n\ntype ctrl_flag =\n | Continue\n | Skip\n | Abort\n\ntype guard_policy =\n | Goal // Add guards as (normal) goals\n | SMT // Add guards as SMT goals\n | SMTSync // Send guards to SMT immediately, will *log* errors (not raise) if anything fails\n | Force // Force guards without SMT\n | Drop // Drop guards, clearly unsound! careful!\n\n(* Typing reflection *)\nval non_informative_token (g:env) (t:typ) : Type0\nval subtyping_token (g:env) (t0 t1:typ) : Type0\nval equiv_token (g:env) (t0 t1:typ) : Type0\nval typing_token (g:env) (e:term) (c:tot_or_ghost & typ) : Type0\n\n(* Must be inline, this definition is not there in src/FStar.Tactics.Types *)\n\nPartial implementation:\nlet issues =\n \n"
},
{
"role": "assistant",
"content": "list FStar.Issue.issue"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Type0\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen Vale.X64.CPU_Features_s\nopen FStar.HyperStack.ST\nmodule B = LowStar.Buffer\nmodule HS = FStar.HyperStack\nopen Vale.Curve25519.Fast_defs\nopen FStar.Mul\n\nunfold\nlet u256 = b:B.buffer UInt64.t{B.length b == 4}\nunfold\nlet u512 = b:B.buffer UInt64.t{B.length b == 8}\n\nPartial implementation:\nlet u1024 =\n \n"
},
{
"role": "assistant",
"content": "b: B.buffer UInt64.t {B.length b == 16}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Type0\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen Vale.X64.CPU_Features_s\nopen FStar.HyperStack.ST\nmodule B = LowStar.Buffer\nmodule HS = FStar.HyperStack\nopen Vale.Curve25519.Fast_defs\nopen FStar.Mul\n\nPartial implementation:\nlet u256 =\n \n"
},
{
"role": "assistant",
"content": "b: B.buffer UInt64.t {B.length b == 4}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Type0\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen Vale.X64.CPU_Features_s\nopen FStar.HyperStack.ST\nmodule B = LowStar.Buffer\nmodule HS = FStar.HyperStack\nopen Vale.Curve25519.Fast_defs\nopen FStar.Mul\n\nunfold\nlet u256 = b:B.buffer UInt64.t{B.length b == 4}\n\nPartial implementation:\nlet u512 =\n \n"
},
{
"role": "assistant",
"content": "b: B.buffer UInt64.t {B.length b == 8}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: d_sub: Pulse.Typing.st_sub g c1 c2\n -> Prims.dtuple2 FStar.Stubs.Reflection.Types.term\n (fun t ->\n FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)\n t\n (Pulse.Elaborate.Core.simple_arr (Pulse.Elaborate.Pure.elab_comp c1)\n (Pulse.Elaborate.Pure.elab_comp c2)))\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nlet elab_sub (c1 c2:comp_st) (e:R.term) =\n let ty = elab_term (comp_res c1) in\n let u = comp_u c1 in\n let pre1 = elab_term (comp_pre c1) in\n let pre2 = elab_term (comp_pre c2) in\n let post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\n let post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\n if C_ST? c1\n then mk_sub_stt u ty pre1 pre2 post1 post2 e\n else if C_STAtomic? c1\n then let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e\n\n\nlet elab_bind #g #x #c1 #c2 #c\n (bc:bind_comp g x c1 c2 c)\n (e1 e2:R.term)\n : R.term\n = let t1 = elab_term (comp_res c1) in\n let t2 = elab_term (comp_res c2) in\n match c1 with\n | C_ST _ ->\n mk_bind_stt\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STGhost _ ->\n mk_bind_ghost\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STAtomic inames obs1 _ ->\n let C_STAtomic _ obs2 _ = c2 in \n mk_bind_atomic\n (comp_u c1)\n (comp_u c2)\n (elab_observability obs1)\n (elab_observability obs2)\n (elab_term (comp_inames c1))\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n \nlet elab_lift #g #c1 #c2 (d:lift_comp g c1 c2) (e:R.term)\n : Tot R.term\n = match d with\n | Lift_STAtomic_ST _ _ ->\n let t = elab_term (comp_res c1) in\n mk_lift_atomic_stt\n (comp_u c1)\n (elab_term (comp_res c1))\n t\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\n | Lift_Observability _ c o2 ->\n let t = elab_term (comp_res c1) in\n mk_lift_observability\n (comp_u c1)\n (elab_observability (C_STAtomic?.obs c))\n (elab_observability o2)\n (elab_term (comp_inames c1))\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n \n | Lift_Ghost_Neutral _ _ (| reveal_a, reveal_a_typing |) ->\n let t = elab_term (comp_res c1) in\n mk_lift_ghost_neutral\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n (elab_term reveal_a)\n\n | Lift_Neutral_Ghost _ c ->\n let t = elab_term (comp_res c1) in\n mk_lift_neutral_ghost\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\nlet intro_pure_tm (p:term) =\n let open Pulse.Reflection.Util in\n wtag (Some STT_Ghost) \n (Tm_STApp\n { head =\n tm_pureapp (tm_fvar (as_fv (mk_pulse_lib_core_lid \"intro_pure\")))\n None\n p;\n arg_qual = None;\n arg = tm_fstar (`()) Range.range_0 })\n\nlet simple_arr (t1 t2 : R.term) : R.term =\n let b = R.pack_binder {\n sort = t1;\n ppname = Sealed.seal \"x\";\n qual = R.Q_Explicit;\n attrs = [] } in\n R.pack_ln (R.Tv_Arrow b (R.pack_comp (R.C_Total t2)))\n\nPartial implementation:\nlet elab_st_sub (#g: env) (#c1 #c2: comp) (d_sub: st_sub g c1 c2)\n : Tot (t: R.term & RT.tot_typing (elab_env g) t (simple_arr (elab_comp c1) (elab_comp c2))) =\n \n"
},
{
"role": "assistant",
"content": "RU.magic_s \"elab_st_sub\""
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n g: Pulse.Typing.Env.env ->\n p: Pulse.Syntax.Base.term ->\n typing: Pulse.Typing.tot_typing g p Pulse.Typing.tm_prop\n -> FStar.Tactics.Effect.Tac (Pulse.Typing.prop_validity g p)\nEffect: FStar.Tactics.Effect.Tac\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Checker.IntroPure\n\nopen Pulse.Syntax\nopen Pulse.Typing\nopen Pulse.Checker.Base\nopen Pulse.Checker.Prover\n\nmodule T = FStar.Tactics.V2\nmodule P = Pulse.Syntax.Printer\n\nlet check_prop (g:env) (p:term) \n : T.Tac (p:term & tot_typing g p tm_prop) =\n \n let p0 = p in\n let (| p, p_typing |) = Pulse.Checker.Pure.check_vprop g (tm_pure p) in\n match p.t with\n | Tm_Pure pp ->\n let prop_typing = Pulse.Typing.Metatheory.pure_typing_inversion #_ #pp p_typing in\n (| pp, prop_typing |)\n | _ ->\n fail g None\n (Printf.sprintf \"Impossible: check_intro_pure: checking a pure vprop %s returned a non-pure vprop %s,\\\n please file a bug-report\"\n (P.term_to_string (tm_pure p0))\n (P.term_to_string p))\n\nPartial implementation:\nlet check_prop_validity (g: env) (p: term) (typing: tot_typing g p tm_prop)\n : T.Tac (prop_validity g p) =\n \n"
},
{
"role": "assistant",
"content": "Pulse.Checker.Pure.check_prop_validity g p typing"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n b: LowStar.Buffer.buffer FStar.UInt64.t {LowStar.Monotonic.Buffer.length b == 4} ->\n h: FStar.Monotonic.HyperStack.mem\n -> Prims.GTot Prims.nat\nEffect: Prims.GTot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen Vale.X64.CPU_Features_s\nopen FStar.HyperStack.ST\nmodule B = LowStar.Buffer\nmodule HS = FStar.HyperStack\nopen Vale.Curve25519.Fast_defs\nopen FStar.Mul\n\nunfold\nlet u256 = b:B.buffer UInt64.t{B.length b == 4}\nunfold\nlet u512 = b:B.buffer UInt64.t{B.length b == 8}\nunfold\nlet u1024 = b:B.buffer UInt64.t{B.length b == 16}\n\nPartial implementation:\nlet as_nat (b: B.buffer UInt64.t {B.length b == 4}) (h: HS.mem) : GTot nat =\n \n"
},
{
"role": "assistant",
"content": "let s = B.as_seq h b in\nlet s0 = UInt64.v (Seq.index s 0) in\nlet s1 = UInt64.v (Seq.index s 1) in\nlet s2 = UInt64.v (Seq.index s 2) in\nlet s3 = UInt64.v (Seq.index s 3) in\npow2_four s0 s1 s2 s3"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.Base.normal Vale.Stdcalls.X64.Aes.lowstar_key128_t\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Stdcalls.X64.Aes\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\nmodule UV = LowStar.BufferView.Up\nopen Vale.Def.Types_s\n\nopen Vale.Interop.Base\nmodule IX64 = Vale.Interop.X64\nmodule VSig = Vale.AsLowStar.ValeSig\nmodule LSig = Vale.AsLowStar.LowStarSig\nmodule ME = Vale.X64.Memory\nmodule V = Vale.X64.Decls\nmodule IA = Vale.Interop.Assumptions\nmodule W = Vale.AsLowStar.Wrapper\nopen Vale.X64.MemoryAdapters\nmodule VS = Vale.X64.State\nmodule MS = Vale.X64.Machine_s\n\nlet lowstar_key128 : lowstar_key128_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 4);\n IX64.wrap_weak_stdcall\n code_key128\n dom\n (W.mk_prediction code_key128 dom [] (key128_lemma code_key128 IA.win))\n\nPartial implementation:\nlet aes128_key_expansion =\n \n"
},
{
"role": "assistant",
"content": "as_normal_t #lowstar_key128_t lowstar_key128"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.Base.normal Vale.Stdcalls.X64.Aes.lowstar_key256_t\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Stdcalls.X64.Aes\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\nmodule UV = LowStar.BufferView.Up\nopen Vale.Def.Types_s\n\nopen Vale.Interop.Base\nmodule IX64 = Vale.Interop.X64\nmodule VSig = Vale.AsLowStar.ValeSig\nmodule LSig = Vale.AsLowStar.LowStarSig\nmodule ME = Vale.X64.Memory\nmodule V = Vale.X64.Decls\nmodule IA = Vale.Interop.Assumptions\nmodule W = Vale.AsLowStar.Wrapper\nopen Vale.X64.MemoryAdapters\nmodule VS = Vale.X64.State\nmodule MS = Vale.X64.Machine_s\n\nlet lowstar_key128 : lowstar_key128_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 4);\n IX64.wrap_weak_stdcall\n code_key128\n dom\n (W.mk_prediction code_key128 dom [] (key128_lemma code_key128 IA.win))\n\nlet aes128_key_expansion //: normal lowstar_key128_t\n = as_normal_t #lowstar_key128_t lowstar_key128\n\nlet lowstar_key256 : lowstar_key256_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 4);\n IX64.wrap_weak_stdcall\n code_key256\n dom\n (W.mk_prediction code_key256 dom [] (key256_lemma code_key256 IA.win))\n\nPartial implementation:\nlet aes256_key_expansion =\n \n"
},
{
"role": "assistant",
"content": "as_normal_t #lowstar_key256_t lowstar_key256"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: l1: IfcRulesReify.label -> l2: IfcRulesReify.label -> Prims.bool\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nPartial implementation:\nlet ( < ) l1 l2 =\n \n"
},
{
"role": "assistant",
"content": "match l1, l2 with\n| Low, High -> true\n| _, _ -> false"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: l1: IfcRulesReify.label -> l2: IfcRulesReify.label -> Prims.bool\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nPartial implementation:\nlet ( <= ) l1 l2 =\n \n"
},
{
"role": "assistant",
"content": "match l1, l2 with\n| High, Low -> false\n| _, _ -> true"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: env: IfcRulesReify.label_fun -> e: WhileReify.exp -> l: IfcRulesReify.label -> Type0\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n\nPartial implementation:\nlet ni_exp (env: label_fun) (e: exp) (l: label) : Tot Type0 =\n \n"
},
{
"role": "assistant",
"content": "forall (h: rel heap).\n (low_equiv env h /\\ Low? l) ==>\n (let vr = reify (interpret_exp_st e) (R?.r h) in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: l1: IfcRulesReify.label -> l2: IfcRulesReify.label -> IfcRulesReify.label\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nPartial implementation:\nlet join l1 l2 =\n \n"
},
{
"role": "assistant",
"content": "match l1, l2 with\n| Low, Low -> Low\n| _, _ -> High"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: l1: IfcRulesReify.label -> l2: IfcRulesReify.label -> IfcRulesReify.label\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nPartial implementation:\nlet meet l1 l2 =\n \n"
},
{
"role": "assistant",
"content": "match l1, l2 with\n| High, High -> High\n| _, _ -> Low"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n c: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap\n -> Type0\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nPartial implementation:\nlet ni_com' (env: label_fun) (c: com) (l: label) (h0: rel heap) : Tot Type0 =\n \n"
},
{
"role": "assistant",
"content": "let R h0l h0r = h0 in\nmatch interpret_com h0l c with\n| Some h1l ->\n (match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True)\n| _ -> True"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: env: IfcRulesReify.label_fun -> c: WhileReify.com -> l: IfcRulesReify.label -> Type0\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nPartial implementation:\nlet ni_com (env: label_fun) (c: com) (l: label) : Tot Type0 =\n \n"
},
{
"role": "assistant",
"content": "(forall (h0: rel heap). ni_com' env c l h0) /\\ (forall (h0: heap). inv_com' env c l h0)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n c: Pulse.Syntax.Base.comp_st ->\n frame: Pulse.Syntax.Base.term ->\n e: FStar.Stubs.Reflection.Types.term\n -> FStar.Stubs.Reflection.Types.term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nPartial implementation:\nlet elab_frame (c: comp_st) (frame: term) (e: R.term) =\n \n"
},
{
"role": "assistant",
"content": "let u = comp_u c in\nlet ty = elab_term (comp_res c) in\nlet pre = elab_term (comp_pre c) in\nlet post = elab_term (comp_post c) in\nif C_ST? c\nthen mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\nelse\n if C_STAtomic? c\n then\n let opened = elab_term (comp_inames c) in\n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n bc: Pulse.Typing.bind_comp g x c1 c2 c ->\n e1: FStar.Stubs.Reflection.Types.term ->\n e2: FStar.Stubs.Reflection.Types.term\n -> FStar.Stubs.Reflection.Types.term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nlet elab_sub (c1 c2:comp_st) (e:R.term) =\n let ty = elab_term (comp_res c1) in\n let u = comp_u c1 in\n let pre1 = elab_term (comp_pre c1) in\n let pre2 = elab_term (comp_pre c2) in\n let post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\n let post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\n if C_ST? c1\n then mk_sub_stt u ty pre1 pre2 post1 post2 e\n else if C_STAtomic? c1\n then let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e\n\nPartial implementation:\nlet elab_bind #g #x #c1 #c2 #c (bc: bind_comp g x c1 c2 c) (e1: R.term) (e2: R.term) : R.term =\n \n"
},
{
"role": "assistant",
"content": "let t1 = elab_term (comp_res c1) in\nlet t2 = elab_term (comp_res c2) in\nmatch c1 with\n| C_ST _ ->\n mk_bind_stt (comp_u c1)\n (comp_u c2)\n t1\n t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1\n e2\n| C_STGhost _ ->\n mk_bind_ghost (comp_u c1)\n (comp_u c2)\n t1\n t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1\n e2\n| C_STAtomic inames obs1 _ ->\n let C_STAtomic _ obs2 _ = c2 in\n mk_bind_atomic (comp_u c1) (comp_u c2) (elab_observability obs1) (elab_observability obs2)\n (elab_term (comp_inames c1)) t1 t2 (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2))) e1 e2"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: d: Pulse.Typing.lift_comp g c1 c2 -> e: FStar.Stubs.Reflection.Types.term\n -> FStar.Stubs.Reflection.Types.term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nlet elab_sub (c1 c2:comp_st) (e:R.term) =\n let ty = elab_term (comp_res c1) in\n let u = comp_u c1 in\n let pre1 = elab_term (comp_pre c1) in\n let pre2 = elab_term (comp_pre c2) in\n let post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\n let post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\n if C_ST? c1\n then mk_sub_stt u ty pre1 pre2 post1 post2 e\n else if C_STAtomic? c1\n then let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e\n\n\nlet elab_bind #g #x #c1 #c2 #c\n (bc:bind_comp g x c1 c2 c)\n (e1 e2:R.term)\n : R.term\n = let t1 = elab_term (comp_res c1) in\n let t2 = elab_term (comp_res c2) in\n match c1 with\n | C_ST _ ->\n mk_bind_stt\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STGhost _ ->\n mk_bind_ghost\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STAtomic inames obs1 _ ->\n let C_STAtomic _ obs2 _ = c2 in \n mk_bind_atomic\n (comp_u c1)\n (comp_u c2)\n (elab_observability obs1)\n (elab_observability obs2)\n (elab_term (comp_inames c1))\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n\nPartial implementation:\nlet elab_lift #g #c1 #c2 (d: lift_comp g c1 c2) (e: R.term) : Tot R.term =\n \n"
},
{
"role": "assistant",
"content": "match d with\n| Lift_STAtomic_ST _ _ ->\n let t = elab_term (comp_res c1) in\n mk_lift_atomic_stt (comp_u c1)\n (elab_term (comp_res c1))\n t\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n| Lift_Observability _ c o2 ->\n let t = elab_term (comp_res c1) in\n mk_lift_observability (comp_u c1)\n (elab_observability (C_STAtomic?.obs c))\n (elab_observability o2)\n (elab_term (comp_inames c1))\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n| Lift_Ghost_Neutral _ _ (| reveal_a , reveal_a_typing |) ->\n let t = elab_term (comp_res c1) in\n mk_lift_ghost_neutral (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n (elab_term reveal_a)\n| Lift_Neutral_Ghost _ c ->\n let t = elab_term (comp_res c1) in\n mk_lift_neutral_ghost (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term\n -> FStar.Stubs.Reflection.Types.term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nlet elab_sub (c1 c2:comp_st) (e:R.term) =\n let ty = elab_term (comp_res c1) in\n let u = comp_u c1 in\n let pre1 = elab_term (comp_pre c1) in\n let pre2 = elab_term (comp_pre c2) in\n let post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\n let post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\n if C_ST? c1\n then mk_sub_stt u ty pre1 pre2 post1 post2 e\n else if C_STAtomic? c1\n then let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e\n\n\nlet elab_bind #g #x #c1 #c2 #c\n (bc:bind_comp g x c1 c2 c)\n (e1 e2:R.term)\n : R.term\n = let t1 = elab_term (comp_res c1) in\n let t2 = elab_term (comp_res c2) in\n match c1 with\n | C_ST _ ->\n mk_bind_stt\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STGhost _ ->\n mk_bind_ghost\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STAtomic inames obs1 _ ->\n let C_STAtomic _ obs2 _ = c2 in \n mk_bind_atomic\n (comp_u c1)\n (comp_u c2)\n (elab_observability obs1)\n (elab_observability obs2)\n (elab_term (comp_inames c1))\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n \nlet elab_lift #g #c1 #c2 (d:lift_comp g c1 c2) (e:R.term)\n : Tot R.term\n = match d with\n | Lift_STAtomic_ST _ _ ->\n let t = elab_term (comp_res c1) in\n mk_lift_atomic_stt\n (comp_u c1)\n (elab_term (comp_res c1))\n t\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\n | Lift_Observability _ c o2 ->\n let t = elab_term (comp_res c1) in\n mk_lift_observability\n (comp_u c1)\n (elab_observability (C_STAtomic?.obs c))\n (elab_observability o2)\n (elab_term (comp_inames c1))\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n \n | Lift_Ghost_Neutral _ _ (| reveal_a, reveal_a_typing |) ->\n let t = elab_term (comp_res c1) in\n mk_lift_ghost_neutral\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n (elab_term reveal_a)\n\n | Lift_Neutral_Ghost _ c ->\n let t = elab_term (comp_res c1) in\n mk_lift_neutral_ghost\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\nlet intro_pure_tm (p:term) =\n let open Pulse.Reflection.Util in\n wtag (Some STT_Ghost) \n (Tm_STApp\n { head =\n tm_pureapp (tm_fvar (as_fv (mk_pulse_lib_core_lid \"intro_pure\")))\n None\n p;\n arg_qual = None;\n arg = tm_fstar (`()) Range.range_0 })\n\nPartial implementation:\nlet simple_arr (t1 t2: R.term) : R.term =\n \n"
},
{
"role": "assistant",
"content": "let b = R.pack_binder ({ sort = t1; ppname = Sealed.seal \"x\"; qual = R.Q_Explicit; attrs = [] }) in\nR.pack_ln (R.Tv_Arrow b (R.pack_comp (R.C_Total t2)))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Stdcalls.X64.Aes.lowstar_key128_t\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Stdcalls.X64.Aes\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\nmodule UV = LowStar.BufferView.Up\nopen Vale.Def.Types_s\n\nopen Vale.Interop.Base\nmodule IX64 = Vale.Interop.X64\nmodule VSig = Vale.AsLowStar.ValeSig\nmodule LSig = Vale.AsLowStar.LowStarSig\nmodule ME = Vale.X64.Memory\nmodule V = Vale.X64.Decls\nmodule IA = Vale.Interop.Assumptions\nmodule W = Vale.AsLowStar.Wrapper\nopen Vale.X64.MemoryAdapters\nmodule VS = Vale.X64.State\nmodule MS = Vale.X64.Machine_s\n\nPartial implementation:\nlet lowstar_key128:lowstar_key128_t =\n \n"
},
{
"role": "assistant",
"content": "assert_norm (List.length dom + List.length ([] <: list arg) <= 4);\nIX64.wrap_weak_stdcall code_key128\n dom\n (W.mk_prediction code_key128 dom [] (key128_lemma code_key128 IA.win))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n c1: Pulse.Syntax.Base.comp_st ->\n c2: Pulse.Syntax.Base.comp_st ->\n e: FStar.Stubs.Reflection.Types.term\n -> FStar.Stubs.Reflection.Types.term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nPartial implementation:\nlet elab_sub (c1 c2: comp_st) (e: R.term) =\n \n"
},
{
"role": "assistant",
"content": "let ty = elab_term (comp_res c1) in\nlet u = comp_u c1 in\nlet pre1 = elab_term (comp_pre c1) in\nlet pre2 = elab_term (comp_pre c2) in\nlet post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\nlet post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\nif C_ST? c1\nthen mk_sub_stt u ty pre1 pre2 post1 post2 e\nelse\n if C_STAtomic? c1\n then\n let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n c: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: FStar.DM4F.Heap.IntStoreFixed.heap\n -> Type0\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n\nPartial implementation:\nlet inv_com' (env: label_fun) (c: com) (l: label) (h0: heap) : Tot Type0 =\n \n"
},
{
"role": "assistant",
"content": "match interpret_com h0 c with\n| None -> True\n| Some h1 -> forall (i: id). env i < l ==> index h0 i = index h1 i"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.st_term\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Elaborate.Core\nmodule RT = FStar.Reflection.Typing\nmodule R = FStar.Reflection.V2\nmodule L = FStar.List.Tot\nmodule T = FStar.Tactics.V2\nopen FStar.List.Tot\nopen Pulse.Syntax\nopen Pulse.Elaborate.Pure\nopen Pulse.Typing\nmodule RU = Pulse.RuntimeUtils\nopen Pulse.Reflection.Util\n\nlet elab_frame (c:comp_st) (frame:term) (e:R.term) =\n let u = comp_u c in\n let ty = elab_term (comp_res c) in\n let pre = elab_term (comp_pre c) in\n let post = elab_term (comp_post c) in\n if C_ST? c\n then mk_frame_stt u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else if C_STAtomic? c\n then let opened = elab_term (comp_inames c) in \n mk_frame_stt_atomic u ty opened pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n else mk_frame_stt_ghost u ty pre (mk_abs ty R.Q_Explicit post) (elab_term frame) e\n\nlet elab_sub (c1 c2:comp_st) (e:R.term) =\n let ty = elab_term (comp_res c1) in\n let u = comp_u c1 in\n let pre1 = elab_term (comp_pre c1) in\n let pre2 = elab_term (comp_pre c2) in\n let post1 = mk_abs ty R.Q_Explicit (elab_term (comp_post c1)) in\n let post2 = mk_abs ty R.Q_Explicit (elab_term (comp_post c2)) in\n if C_ST? c1\n then mk_sub_stt u ty pre1 pre2 post1 post2 e\n else if C_STAtomic? c1\n then let opened = elab_term (comp_inames c1) in\n mk_sub_stt_atomic u ty opened pre1 pre2 post1 post2 e\n else mk_sub_stt_ghost u ty pre1 pre2 post1 post2 e\n\n\nlet elab_bind #g #x #c1 #c2 #c\n (bc:bind_comp g x c1 c2 c)\n (e1 e2:R.term)\n : R.term\n = let t1 = elab_term (comp_res c1) in\n let t2 = elab_term (comp_res c2) in\n match c1 with\n | C_ST _ ->\n mk_bind_stt\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STGhost _ ->\n mk_bind_ghost\n (comp_u c1)\n (comp_u c2)\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n | C_STAtomic inames obs1 _ ->\n let C_STAtomic _ obs2 _ = c2 in \n mk_bind_atomic\n (comp_u c1)\n (comp_u c2)\n (elab_observability obs1)\n (elab_observability obs2)\n (elab_term (comp_inames c1))\n t1 t2\n (elab_term (comp_pre c1))\n (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1)))\n (mk_abs t2 R.Q_Explicit (elab_term (comp_post c2)))\n e1 e2\n \nlet elab_lift #g #c1 #c2 (d:lift_comp g c1 c2) (e:R.term)\n : Tot R.term\n = match d with\n | Lift_STAtomic_ST _ _ ->\n let t = elab_term (comp_res c1) in\n mk_lift_atomic_stt\n (comp_u c1)\n (elab_term (comp_res c1))\n t\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\n | Lift_Observability _ c o2 ->\n let t = elab_term (comp_res c1) in\n mk_lift_observability\n (comp_u c1)\n (elab_observability (C_STAtomic?.obs c))\n (elab_observability o2)\n (elab_term (comp_inames c1))\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n \n | Lift_Ghost_Neutral _ _ (| reveal_a, reveal_a_typing |) ->\n let t = elab_term (comp_res c1) in\n mk_lift_ghost_neutral\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n (elab_term reveal_a)\n\n | Lift_Neutral_Ghost _ c ->\n let t = elab_term (comp_res c1) in\n mk_lift_neutral_ghost\n (comp_u c1)\n t\n (elab_term (comp_pre c1))\n (mk_abs t R.Q_Explicit (elab_term (comp_post c1)))\n e\n\nPartial implementation:\nlet intro_pure_tm (p: term) =\n \n"
},
{
"role": "assistant",
"content": "let open Pulse.Reflection.Util in\nwtag (Some STT_Ghost)\n (Tm_STApp\n ({\n head = tm_pureapp (tm_fvar (as_fv (mk_pulse_lib_core_lid \"intro_pure\"))) None p;\n arg_qual = None;\n arg = tm_fstar (`()) Range.range_0\n }))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n r: FStar.DM4F.Heap.IntStoreFixed.id ->\n h0: FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma (ensures IfcRulesReify.inv_com' env (WhileReify.Assign r e) (env r) h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nPartial implementation:\nlet assign_inv_com' (env: label_fun) (e: exp) (r: id) (h0: heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0) =\n \n"
},
{
"role": "assistant",
"content": "let v = reify (interpret_exp_st e) h0 in\nmatch reify (interpret_com_st (Assign r e) h0) h0 with\n| None, h1 -> ()\n| Some (), h1 -> assert (h1 == upd h0 r v)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: env: IfcRulesReify.label_fun -> e: WhileReify.exp -> r: FStar.DM4F.Heap.IntStoreFixed.id\n -> FStar.Pervasives.Lemma (requires IfcRulesReify.ni_exp env e (env r))\n (ensures IfcRulesReify.ni_com env (WhileReify.Assign r e) (env r))\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n\nPartial implementation:\nlet assign_com env e r =\n \n"
},
{
"role": "assistant",
"content": "forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r))));\nforall_intro (assign_inv_com' env e r)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n r: FStar.DM4F.Heap.IntStoreFixed.id ->\n ne: Prims.squash (IfcRulesReify.ni_exp env e (env r)) ->\n h0: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma (ensures IfcRulesReify.ni_com' env (WhileReify.Assign r e) (env r) h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nPartial implementation:\nlet assign_inv_com0\n (env: label_fun)\n (e: exp)\n (r: id)\n (ne: squash (ni_exp env e (env r)))\n (h0: rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0) =\n \n"
},
{
"role": "assistant",
"content": "FStar.Squash.give_proof ne;\nlet vr = reify (interpret_exp_st e) (R?.r h0) in\nlet vl = reify (interpret_exp_st e) (R?.l h0) in\nmatch reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n| Some (), h1l ->\n (match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ())\n| None, _ -> ()"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Stdcalls.X64.Aes.lowstar_key256_t\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Stdcalls.X64.Aes\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\nmodule UV = LowStar.BufferView.Up\nopen Vale.Def.Types_s\n\nopen Vale.Interop.Base\nmodule IX64 = Vale.Interop.X64\nmodule VSig = Vale.AsLowStar.ValeSig\nmodule LSig = Vale.AsLowStar.LowStarSig\nmodule ME = Vale.X64.Memory\nmodule V = Vale.X64.Decls\nmodule IA = Vale.Interop.Assumptions\nmodule W = Vale.AsLowStar.Wrapper\nopen Vale.X64.MemoryAdapters\nmodule VS = Vale.X64.State\nmodule MS = Vale.X64.Machine_s\n\nlet lowstar_key128 : lowstar_key128_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 4);\n IX64.wrap_weak_stdcall\n code_key128\n dom\n (W.mk_prediction code_key128 dom [] (key128_lemma code_key128 IA.win))\n\nlet aes128_key_expansion //: normal lowstar_key128_t\n = as_normal_t #lowstar_key128_t lowstar_key128\n\nPartial implementation:\nlet lowstar_key256:lowstar_key256_t =\n \n"
},
{
"role": "assistant",
"content": "assert_norm (List.length dom + List.length ([] <: list arg) <= 4);\nIX64.wrap_weak_stdcall code_key256\n dom\n (W.mk_prediction code_key256 dom [] (key256_lemma code_key256 IA.win))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: env: IfcRulesReify.label_fun -> c1: WhileReify.com -> c2: WhileReify.com -> l: IfcRulesReify.label\n -> FStar.Pervasives.Lemma\n (requires IfcRulesReify.ni_com env c1 l /\\ IfcRulesReify.ni_com env c2 l)\n (ensures IfcRulesReify.ni_com env (WhileReify.Seq c1 c2) l)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n\nPartial implementation:\nlet seq_com env c1 c2 l =\n \n"
},
{
"role": "assistant",
"content": "forall_intro (fun (h0: rel heap) -> seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0));\nforall_intro (fun (h0: heap) -> seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0)\n )"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n c1: WhileReify.com ->\n c2: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma\n (requires IfcRulesReify.ni_com env c1 l /\\ IfcRulesReify.ni_com env c2 l)\n (ensures IfcRulesReify.inv_com' env (WhileReify.Seq c1 c2) l h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n\nPartial implementation:\nlet seq_inv_com' env c1 c2 l h0 =\n \n"
},
{
"role": "assistant",
"content": "match reify (interpret_com_st c1 h0) h0 with\n| None, _ -> seq_nil1 c1 c2 h0\n| Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n ct: WhileReify.com ->\n cf: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma\n (requires\n IfcRulesReify.ni_exp env e l /\\ IfcRulesReify.ni_com env ct l /\\\n IfcRulesReify.ni_com env cf l)\n (ensures IfcRulesReify.inv_com' env (WhileReify.If e ct cf) l h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com env (Seq c1 c2) l))\nlet seq_com env c1 c2 l =\n forall_intro\n (fun (h0:rel heap) ->\n seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0))\n\n(* Typing rule for conditional commands\n\n env |- e : l env,pc:l |- ct env,pc:l |- cf\n ----------------------------------------------\n env,pc:l |- if e <> 0 then ct else cf\n*)\n\n(* let project_inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Lemma (requires (ni_com env c l)) (ensures (inv_com' env c l h0)) = () *)\n\nval cond_inv_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n\nPartial implementation:\nlet cond_inv_com' env e ct cf l h0 =\n \n"
},
{
"role": "assistant",
"content": "let v = reify (interpret_exp_st e) h0 in\nif v = 0\nthen assert (inv_com' env cf l h0 ==> inv_com' env (If e ct cf) l h0)\nelse assert (inv_com' env ct l h0 ==> inv_com' env (If e ct cf) l h0)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n g: Pulse.Typing.Env.env ->\n pre: Pulse.Syntax.Base.term ->\n pre_typing: Pulse.Typing.tot_typing g pre Pulse.Syntax.Base.tm_vprop ->\n post_hint: Pulse.Typing.post_hint_opt g ->\n res_ppname: Pulse.Syntax.Base.ppname ->\n t: Pulse.Syntax.Base.st_term{Tm_IntroPure? (Mkst_term?.term t)}\n -> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g pre post_hint)\nEffect: FStar.Tactics.Effect.Tac\n\nContext:\n(*\n Copyright 2023 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\n\nmodule Pulse.Checker.IntroPure\n\nopen Pulse.Syntax\nopen Pulse.Typing\nopen Pulse.Checker.Base\nopen Pulse.Checker.Prover\n\nmodule T = FStar.Tactics.V2\nmodule P = Pulse.Syntax.Printer\n\nlet check_prop (g:env) (p:term) \n : T.Tac (p:term & tot_typing g p tm_prop) =\n \n let p0 = p in\n let (| p, p_typing |) = Pulse.Checker.Pure.check_vprop g (tm_pure p) in\n match p.t with\n | Tm_Pure pp ->\n let prop_typing = Pulse.Typing.Metatheory.pure_typing_inversion #_ #pp p_typing in\n (| pp, prop_typing |)\n | _ ->\n fail g None\n (Printf.sprintf \"Impossible: check_intro_pure: checking a pure vprop %s returned a non-pure vprop %s,\\\n please file a bug-report\"\n (P.term_to_string (tm_pure p0))\n (P.term_to_string p))\n\nlet check_prop_validity (g:env) (p:term) (typing:tot_typing g p tm_prop): T.Tac (prop_validity g p) =\n Pulse.Checker.Pure.check_prop_validity g p typing\n\nPartial implementation:\nlet check\n (g: env)\n (pre: term)\n (pre_typing: tot_typing g pre tm_vprop)\n (post_hint: post_hint_opt g)\n (res_ppname: ppname)\n (t: st_term{Tm_IntroPure? t.term})\n : T.Tac (checker_result_t g pre post_hint) =\n \n"
},
{
"role": "assistant",
"content": "let g = Pulse.Typing.Env.push_context g \"check_intro_pure\" t.range in\nlet Tm_IntroPure { p = p } = t.term in\nlet (| p , p_typing |) = check_prop g p in\nlet pv = check_prop_validity g p p_typing in\nlet st_typing = T_IntroPure _ _ p_typing pv in\nprove_post_hint (try_frame_pre pre_typing\n (match_comp_res_with_post_hint st_typing post_hint)\n res_ppname)\n post_hint\n t.range"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n st: Hacl.Spec.SHA2.Vec.state_spec a m ->\n j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->\n i: Prims.nat{i < 8 * Spec.Hash.Definitions.word_length a}\n -> FStar.Pervasives.Lemma\n (ensures\n (let l = Hacl.Spec.SHA2.Vec.lanes a m in\n let ind = 8 * j + i / Spec.Hash.Definitions.word_length a in\n FStar.Seq.Base.index (Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec.transpose_state st).[ ind / l\n ])\n (ind % l) ==\n FStar.Seq.Base.index (Hacl.Spec.SHA2.Vec.state_spec_v st).[ j ]\n (i / Spec.Hash.Definitions.word_length a)))\nEffect: FStar.Pervasives.Lemma\n\nContext:\nmodule Hacl.Spec.SHA2.Lemmas\n\nopen FStar.Mul\nopen Lib.IntTypes\nopen Lib.Sequence\nopen Lib.IntVector\nopen Lib.IntVector.Transpose\n\nopen Spec.Hash.Definitions\nopen Hacl.Spec.SHA2.Vec\n\n\n#set-options \"--z3rlimit 50 --fuel 0 --ifuel 1\"\n\nval transpose_ws4_lemma_ij:\n #a:sha2_alg\n -> #m:m_spec{lanes a m == 4} // lanes a m * lanes a m = 16\n -> ws:ws_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 16} ->\n Lemma\n (let l = lanes a m in\n (vec_v (transpose_ws4 ws).[i]).[j] == (vec_v ws.[i / l * l + j]).[i % l])\n\nlet transpose_ws4_lemma_ij #a #m ws j i =\n let l = lanes a m in\n let i_sub = i / l in\n let j_sub = i % l in\n assert (i_sub * l + j_sub == i);\n\n let vs = sub ws (i_sub * l) l in\n eq_intro (sub (transpose_ws4 ws) (i_sub * l) l) (transpose4x4_lseq vs);\n //assert ((transpose_ws4 ws).[i] == (sub (transpose_ws4 ws) (i_sub * l) l).[j_sub]);\n //assert ((transpose_ws4 ws).[i] == (transpose4x4_lseq vs).[j_sub]);\n assert ((vec_v (transpose_ws4 ws).[i]).[j] == (vec_v (transpose4x4_lseq vs).[j_sub]).[j]);\n transpose4x4_lemma vs;\n assert ((vec_v (transpose_ws4 ws).[i]).[j] == (vec_v vs.[j]).[j_sub]);\n assert ((vec_v (transpose_ws4 ws).[i]).[j] == (vec_v ws.[i_sub * l + j]).[j_sub])\n\n\nval transpose_ws8_lemma_ij:\n #a:sha2_alg\n -> #m:m_spec{lanes a m == 8}\n -> ws:ws_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 16} ->\n Lemma\n (let l = lanes a m in\n (vec_v (transpose_ws8 ws).[i]).[j] == (vec_v ws.[i / l * l + j]).[i % l])\n\nlet transpose_ws8_lemma_ij #a #m ws j i =\n let l = lanes a m in\n let i_sub = i / l in\n let j_sub = i % l in\n assert (i_sub * l + j_sub == i);\n\n let vs = sub ws (i_sub * l) l in\n eq_intro (sub (transpose_ws8 ws) (i_sub * l) l) (transpose8x8_lseq vs);\n assert ((vec_v (transpose_ws8 ws).[i]).[j] == (vec_v (transpose8x8_lseq vs).[j_sub]).[j]);\n transpose8x8_lemma vs;\n assert ((vec_v (transpose_ws8 ws).[i]).[j] == (vec_v ws.[i_sub * lanes a m + j]).[j_sub])\n\n\nval transpose_ws_lemma_ij:\n #a:sha2_alg\n -> #m:m_spec{is_supported a m}\n -> ws:ws_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 16} ->\n Lemma\n (let l = lanes a m in\n ((ws_spec_v (transpose_ws ws)).[j]).[i] == (vec_v ws.[i / l * l + j]).[i % l])\n\nlet transpose_ws_lemma_ij #a #m ws j i =\n assert (((ws_spec_v (transpose_ws ws)).[j]).[i] == (vec_v (transpose_ws ws).[i]).[j]);\n match lanes a m with\n | 1 -> ()\n | 4 -> transpose_ws4_lemma_ij #a #m ws j i\n | 8 -> transpose_ws8_lemma_ij #a #m ws j i\n\n\nval transpose_state4_lemma:\n #a:sha2_alg\n -> #m:m_spec{lanes a m == 4}\n -> st:state_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 8 * word_length a} ->\n Lemma\n (let l = lanes a m in\n let ind = 8 * j + i / word_length a in\n Seq.index (vec_v (transpose_state st).[ind / l]) (ind % l) ==\n Seq.index (state_spec_v st).[j] (i / word_length a))\n\nlet transpose_state4_lemma #a #m st j i =\n let r0 = transpose4x4_lseq (sub st 0 4) in\n transpose4x4_lemma (sub st 0 4);\n let r1 = transpose4x4_lseq (sub st 4 4) in\n transpose4x4_lemma (sub st 4 4)\n\n\nval transpose_state8_lemma:\n #a:sha2_alg\n -> #m:m_spec{lanes a m == 8}\n -> st:state_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 8 * word_length a} ->\n Lemma\n (let l = lanes a m in\n let ind = 8 * j + i / word_length a in\n Seq.index (vec_v (transpose_state8 st).[ind / l]) (ind % l) ==\n Seq.index (state_spec_v st).[j] (i / word_length a))\n\nlet transpose_state8_lemma #a #m st j i =\n let l = lanes a m in\n let ind = 8 * j + i / word_length a in\n let r0 = transpose8x8_lseq st in\n transpose8x8_lemma st\n\n\nval transpose_state_lemma_ij:\n #a:sha2_alg\n -> #m:m_spec{is_supported a m}\n -> st:state_spec a m\n -> j:nat{j < lanes a m}\n -> i:nat{i < 8 * word_length a} ->\n Lemma\n (let l = lanes a m in\n let ind = 8 * j + i / word_length a in\n (Seq.index (vec_v (transpose_state st).[ind / l])) (ind % l) ==\n (Seq.index (state_spec_v st).[j] (i / word_length a)))\n\nPartial implementation:\nlet transpose_state_lemma_ij #a #m st j i =\n \n"
},
{
"role": "assistant",
"content": "match lanes a m with\n| 1 -> ()\n| 4 -> transpose_state4_lemma #a #m st j i\n| 8 -> transpose_state8_lemma #a #m st j i"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n ct: WhileReify.com ->\n cf: WhileReify.com ->\n l: IfcRulesReify.label\n -> FStar.Pervasives.Lemma\n (requires\n IfcRulesReify.ni_exp env e l /\\ IfcRulesReify.ni_com env ct l /\\\n IfcRulesReify.ni_com env cf l) (ensures IfcRulesReify.ni_com env (WhileReify.If e ct cf) l)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com env (Seq c1 c2) l))\nlet seq_com env c1 c2 l =\n forall_intro\n (fun (h0:rel heap) ->\n seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0))\n\n(* Typing rule for conditional commands\n\n env |- e : l env,pc:l |- ct env,pc:l |- cf\n ----------------------------------------------\n env,pc:l |- if e <> 0 then ct else cf\n*)\n\n(* let project_inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Lemma (requires (ni_com env c l)) (ensures (inv_com' env c l h0)) = () *)\n\nval cond_inv_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (inv_com' env (If e ct cf) l h0))\nlet cond_inv_com' env e ct cf l h0 =\n let v = reify (interpret_exp_st e) h0 in\n if v = 0\n then assert (inv_com' env cf l h0 ==> inv_com' env (If e ct cf) l h0)\n else assert (inv_com' env ct l h0 ==> inv_com' env (If e ct cf) l h0)\n\n (* Works too but takes 20s more *)\n (* let c = if v = 0 then cf else ct in *)\n (* match reify (interpret_com_st c h0) h0 with *)\n (* | None, _ -> () *)\n (* | Some (), h1 -> () *)\n#reset-options \"--max_fuel 1\"\nlet interpret_cond (e:exp) (ct:com) (cf:com) (h:heap)\n : Lemma (let v = reify (interpret_exp_st e) h in\n let c = if v = 0 then cf else ct in\n (reify (interpret_com_st (If e ct cf) h) h ==\n reify (interpret_com_st c h) h))\n = ()\n\n\nval cond_ni_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:rel heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (ni_com' env (If e ct cf) l h0))\nlet cond_ni_com' env e ct cf l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else\n let R h0l h0r = h0 in\n let vl = reify (interpret_exp_st e) h0l in\n let vr = reify (interpret_exp_st e) h0r in\n if Low? l\n then begin\n assert (vl == vr) ;\n let c = if vl = 0 then cf else ct in\n assert (ni_com env c l) ;\n let cif = If e ct cf in\n //NS:05/15 ... this 2 should be trivial to prove.\n // Why do they require a lemma?\n interpret_cond e ct cf h0l;\n interpret_cond e ct cf h0r;\n use_ni_com env c l (R h0l h0r)\n end\n else (* h0 and h1 are low_equiv since cl and cr cannot write at low cells *)\n match reify (interpret_com_st (If e ct cf) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (If e ct cf) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n cond_inv_com' env e ct cf l h0l ;\n cond_inv_com' env e ct cf l h0r ;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))\n\n#set-options \"--z3rlimit 5\"\n\nval cond_com : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n\nPartial implementation:\nlet cond_com env e ct cf l =\n \n"
},
{
"role": "assistant",
"content": "forall_intro (fun (h0: rel heap) ->\n cond_ni_com' env e ct cf l h0 <: Lemma (ni_com' env (If e ct cf) l h0));\nforall_intro (fun (h0: heap) ->\n cond_inv_com' env e ct cf l h0 <: Lemma (inv_com' env (If e ct cf) l h0))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n c: WhileReify.com ->\n v: WhileReify.metric ->\n l: IfcRulesReify.label\n -> FStar.Pervasives.Lemma (requires IfcRulesReify.ni_exp env e l /\\ IfcRulesReify.ni_com env c l)\n (ensures IfcRulesReify.ni_com env (WhileReify.While e c v) l)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com env (Seq c1 c2) l))\nlet seq_com env c1 c2 l =\n forall_intro\n (fun (h0:rel heap) ->\n seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0))\n\n(* Typing rule for conditional commands\n\n env |- e : l env,pc:l |- ct env,pc:l |- cf\n ----------------------------------------------\n env,pc:l |- if e <> 0 then ct else cf\n*)\n\n(* let project_inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Lemma (requires (ni_com env c l)) (ensures (inv_com' env c l h0)) = () *)\n\nval cond_inv_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (inv_com' env (If e ct cf) l h0))\nlet cond_inv_com' env e ct cf l h0 =\n let v = reify (interpret_exp_st e) h0 in\n if v = 0\n then assert (inv_com' env cf l h0 ==> inv_com' env (If e ct cf) l h0)\n else assert (inv_com' env ct l h0 ==> inv_com' env (If e ct cf) l h0)\n\n (* Works too but takes 20s more *)\n (* let c = if v = 0 then cf else ct in *)\n (* match reify (interpret_com_st c h0) h0 with *)\n (* | None, _ -> () *)\n (* | Some (), h1 -> () *)\n#reset-options \"--max_fuel 1\"\nlet interpret_cond (e:exp) (ct:com) (cf:com) (h:heap)\n : Lemma (let v = reify (interpret_exp_st e) h in\n let c = if v = 0 then cf else ct in\n (reify (interpret_com_st (If e ct cf) h) h ==\n reify (interpret_com_st c h) h))\n = ()\n\n\nval cond_ni_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:rel heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (ni_com' env (If e ct cf) l h0))\nlet cond_ni_com' env e ct cf l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else\n let R h0l h0r = h0 in\n let vl = reify (interpret_exp_st e) h0l in\n let vr = reify (interpret_exp_st e) h0r in\n if Low? l\n then begin\n assert (vl == vr) ;\n let c = if vl = 0 then cf else ct in\n assert (ni_com env c l) ;\n let cif = If e ct cf in\n //NS:05/15 ... this 2 should be trivial to prove.\n // Why do they require a lemma?\n interpret_cond e ct cf h0l;\n interpret_cond e ct cf h0r;\n use_ni_com env c l (R h0l h0r)\n end\n else (* h0 and h1 are low_equiv since cl and cr cannot write at low cells *)\n match reify (interpret_com_st (If e ct cf) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (If e ct cf) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n cond_inv_com' env e ct cf l h0l ;\n cond_inv_com' env e ct cf l h0r ;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))\n\n#set-options \"--z3rlimit 5\"\n\nval cond_com : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (ni_com env (If e ct cf) l))\nlet cond_com env e ct cf l =\n forall_intro\n (fun (h0:rel heap) ->\n cond_ni_com' env e ct cf l h0 <: Lemma (ni_com' env (If e ct cf) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n cond_inv_com' env e ct cf l h0 <: Lemma (inv_com' env (If e ct cf) l h0))\n\n\n(* Typing rule for Skip\n\n -------------------\n env,pc:High |- skip\n*)\n\nval skip_com : env:label_fun ->\n Lemma (ni_com env Skip High)\nlet skip_com _ = ()\n\n(* While rule for commands\n\n env |- e : l env,pc:l |- c\n -----------------------------------\n env,pc:l |- while (e <> 0) do c\n*)\n\n\nval while_inv_com'\n : env:label_fun ->\n e:exp ->\n c:com ->\n v:metric ->\n l:label ->\n h0:heap ->\n Lemma\n (requires (ni_exp env e l /\\ ni_com env c l))\n (ensures (inv_com' env (While e c v) l h0))\n (decreases (decr_while h0 (While e c v)))\n\n#reset-options \"--z3rlimit 40\"\n\nlet interpret_while_nil e c v h\n : Lemma (requires (reify (interpret_exp_st e) h <> 0 /\\\n fst (reify (interpret_com_st c h) h) == None))\n (ensures (interpret_com h (While e c v) == None))\n = ()\n\nlet interpret_while_loops (e:exp) (c:com) (v:metric) (h:heap)\n : Lemma (requires (reify (interpret_exp_st e) h <> 0 /\\\n (match reify (interpret_com_st c h) h with\n | None, _ -> True\n | Some _, h' ->\n interpret_exp' h' v >= interpret_exp' h v)))\n (ensures (interpret_com h (While e c v) == None))\n = ()\n\nlet rec while_inv_com' env e c v l h0 =\n let v0 = reify (interpret_exp_st e) h0 in\n if v0 = 0 then assert (interpret_com h0 (While e c v) == Some h0)\n else\n let m0 = interpret_exp' h0 v in\n match reify (interpret_com_st c h0) h0 with\n | None, _ -> interpret_while_nil e c v h0\n | Some (), h2 ->\n let m1 = interpret_exp' h2 v in\n if m0 > m1\n then begin\n assert (decr_while h2 (While e c v) << decr_while h0 (While e c v)) ;\n while_inv_com' env e c v l h2\n end\n else interpret_while_loops e c v h0\n\nval while_ni_com'_low_equiv_high : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l /\\ low_equiv env h0 /\\ High? l))\n (ensures (ni_com' env (While e c v) l h0))\nlet while_ni_com'_low_equiv_high env e c v l h0 =\n (* h0 and h1 are low_equiv since cl and cr cannot write at low cells *)\n let R h0l h0r = h0 in\n match reify (interpret_com_st (While e c v) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (While e c v) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n while_inv_com' env e c v l h0l ;\n while_inv_com' env e c v l h0r ;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))\n\nval while_ni_com'_low_equiv_low : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l /\\ low_equiv env h0 /\\ Low? l))\n (ensures (ni_com' env (While e c v) l h0))\n (decreases (decr_while (R?.l h0) (While e c v) + decr_while (R?.r h0) (While e c v)))\nlet rec while_ni_com'_low_equiv_low env e c v l h0 =\n let R h0l h0r = h0 in\n let v0l = reify (interpret_exp_st e) h0l in\n let v0r = reify (interpret_exp_st e) h0r in\n assert (v0l == v0r) ;\n if v0l = 0 then begin\n assert (interpret_com h0l (While e c v) == Some h0l);\n assert (interpret_com h0r (While e c v) == Some h0r)\n end\n else\n let m0l = interpret_exp' h0l v in\n let m0r = interpret_exp' h0r v in\n match reify (interpret_com_st c h0l) h0l with\n | None, _ -> interpret_while_nil e c v h0l\n | Some (), h2l ->\n match reify (interpret_com_st c h0r) h0r with\n | None, _ -> interpret_while_nil e c v h0r\n | Some (), h2r ->\n let m1l = interpret_exp' h2l v in\n let m1r = interpret_exp' h2r v in\n if m0l > m1l\n then if m0r > m1r\n then begin\n assert (decr_while h2l (While e c v) << decr_while h0l (While e c v)) ;\n while_ni_com'_low_equiv_low env e c v l (R h2l h2r)\n end\n else interpret_while_loops e c v h0r\n else interpret_while_loops e c v h0l\n\nval while_ni_com' : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l))\n (ensures (ni_com' env (While e c v) l h0))\n#set-options \"--max_fuel 1 --max_ifuel 1 --z3rlimit 50\"\nlet while_ni_com' env e c v l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else if Low? l\n then while_ni_com'_low_equiv_low env e c v l h0\n else while_ni_com'_low_equiv_high env e c v l h0\n\n#set-options \"--z3rlimit 5\"\n\nval while_com : env:label_fun -> e:exp -> c:com -> v:metric -> l:label ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l))\n\nPartial implementation:\nlet while_com env e c v l =\n \n"
},
{
"role": "assistant",
"content": "forall_intro (fun (h: rel heap) ->\n while_ni_com' env e c v l h <: Lemma (ensures (ni_com' env (While e c v) l h)));\nforall_intro (fun (h0: heap) ->\n while_inv_com' env e c v l h0 <: Lemma (ensures (inv_com' env (While e c v) l h0)))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n ct: WhileReify.com ->\n cf: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma\n (requires\n IfcRulesReify.ni_exp env e l /\\ IfcRulesReify.ni_com env ct l /\\\n IfcRulesReify.ni_com env cf l)\n (ensures IfcRulesReify.ni_com' env (WhileReify.If e ct cf) l h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com env (Seq c1 c2) l))\nlet seq_com env c1 c2 l =\n forall_intro\n (fun (h0:rel heap) ->\n seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0))\n\n(* Typing rule for conditional commands\n\n env |- e : l env,pc:l |- ct env,pc:l |- cf\n ----------------------------------------------\n env,pc:l |- if e <> 0 then ct else cf\n*)\n\n(* let project_inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Lemma (requires (ni_com env c l)) (ensures (inv_com' env c l h0)) = () *)\n\nval cond_inv_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (inv_com' env (If e ct cf) l h0))\nlet cond_inv_com' env e ct cf l h0 =\n let v = reify (interpret_exp_st e) h0 in\n if v = 0\n then assert (inv_com' env cf l h0 ==> inv_com' env (If e ct cf) l h0)\n else assert (inv_com' env ct l h0 ==> inv_com' env (If e ct cf) l h0)\n\n (* Works too but takes 20s more *)\n (* let c = if v = 0 then cf else ct in *)\n (* match reify (interpret_com_st c h0) h0 with *)\n (* | None, _ -> () *)\n (* | Some (), h1 -> () *)\n#reset-options \"--max_fuel 1\"\nlet interpret_cond (e:exp) (ct:com) (cf:com) (h:heap)\n : Lemma (let v = reify (interpret_exp_st e) h in\n let c = if v = 0 then cf else ct in\n (reify (interpret_com_st (If e ct cf) h) h ==\n reify (interpret_com_st c h) h))\n = ()\n\n\nval cond_ni_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:rel heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n\nPartial implementation:\nlet cond_ni_com' env e ct cf l h0 =\n \n"
},
{
"role": "assistant",
"content": "if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\nthen ()\nelse\n let R h0l h0r = h0 in\n let vl = reify (interpret_exp_st e) h0l in\n let vr = reify (interpret_exp_st e) h0r in\n if Low? l\n then\n (assert (vl == vr);\n let c = if vl = 0 then cf else ct in\n assert (ni_com env c l);\n let cif = If e ct cf in\n interpret_cond e ct cf h0l;\n interpret_cond e ct cf h0r;\n use_ni_com env c l (R h0l h0r))\n else\n match reify (interpret_com_st (If e ct cf) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (If e ct cf) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n cond_inv_com' env e ct cf l h0l;\n cond_inv_com' env e ct cf l h0r;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n c1: WhileReify.com ->\n c2: WhileReify.com ->\n l: IfcRulesReify.label ->\n h0: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma\n (requires IfcRulesReify.ni_com env c1 l /\\ IfcRulesReify.ni_com env c2 l)\n (ensures IfcRulesReify.ni_com' env (WhileReify.Seq c1 c2) l h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n\nPartial implementation:\nlet seq_com' env c1 c2 l h0 =\n \n"
},
{
"role": "assistant",
"content": "if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\nthen ()\nelse\n (assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1);\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n env: IfcRulesReify.label_fun ->\n e: WhileReify.exp ->\n c: WhileReify.com ->\n v: WhileReify.metric ->\n l: IfcRulesReify.label ->\n h0: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap\n -> FStar.Pervasives.Lemma (requires IfcRulesReify.ni_exp env e l /\\ IfcRulesReify.ni_com env c l)\n (ensures IfcRulesReify.ni_com' env (WhileReify.While e c v) l h0)\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2018 Microsoft Research\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*)\nmodule IfcRulesReify\n\nopen Rel\nopen WhileReify\nopen FStar.DM4F.Heap.IntStoreFixed\nopen FStar.DM4F.IntStoreExcFixed\nopen FStar.Squash\nopen FStar.Classical\n\n(****************************** Preliminaries ******************************)\n\n(* CH: Everything specialized to 2-point lattice *)\ntype label =\n| Low\n| High\n\nval op_Less : label -> label -> Tot bool\nlet op_Less l1 l2 =\n match l1, l2 with\n | Low,High -> true\n | _, _ -> false\n\nval op_Less_Equals : label -> label -> Tot bool\nlet op_Less_Equals l1 l2 =\n match l1, l2 with\n | High,Low -> false\n | _, _ -> true\n\nval join : label -> label -> Tot label\nlet join l1 l2 =\n match l1, l2 with\n | Low,Low -> Low\n | _, _ -> High\n\nval meet : label -> label -> Tot label\nlet meet l1 l2 =\n match l1, l2 with\n | High, High -> High\n | _, _ -> Low\n\nlet universal_property_meet l l1 l2\n : Lemma (requires (l <= l1 /\\ l <= l2)) (ensures (l <= meet l1 l2))\n= ()\n\ntype label_fun = id -> Tot label\n\ntype low_equiv (env:label_fun) (h1:rel heap) =\n (forall (x:id). (* {:pattern (env x)} *) env x = Low ==> index (R?.l h1) x = index (R?.r h1) x)\n\n(**************************** Typing Judgements ****************************)\n\n(* env |- e : l\n - Expressions do not modify the heap\n - Correctness\n - Low equivalent input heaps + Low label ==> same result\n*)\nlet ni_exp (env:label_fun) (e:exp) (l:label) : Tot Type0 =\n forall (h: rel heap). (* {:pattern (low_equiv env h)} *)\n (low_equiv env h /\\ Low? l) ==>\n (* interpret_exp (R?.r h) e = interpret_exp (R?.l h) e *)\n begin\n let vr = reify (interpret_exp_st e) (R?.r h)in\n let vl = reify (interpret_exp_st e) (R?.l h) in\n vr = vl\n end\n\n\n\n(* env,pc:l |- c\n - References with a label below l are not modified\n - Total correctness\n - Low equivalent input heaps ==> Low equivalent output heaps\n*)\nlet inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Tot Type0\n=\n match interpret_com h0 c with\n | None -> True\n | Some h1 ->\n forall (i:id). (* {:pattern (env i < l)} *) env i < l ==> index h0 i = index h1 i\n\nlet ni_com' (env:label_fun) (c:com) (l:label) (h0:rel heap) : Tot Type0 =\n let R h0l h0r = h0 in\n (* KM : That's the code that we would like to write but subtyping and matching on pairs interplay badly *)\n (* it generates a VC which boils down to [forall (h1l:heap). length h1l = length h0l] which is obviously false *)\n (* begin match interpret_com h0l c, interpret_com h0r c with *)\n (* | Some h1l, Some h1r -> low_equiv env (R h0l h0r) ==> low_equiv env (R h1l h1r) *)\n (* | _ -> True *)\n (* end *)\n begin match interpret_com h0l c with\n | Some h1l -> begin match interpret_com h0r c with\n | Some h1r -> low_equiv env h0 ==> low_equiv env (R h1l h1r)\n | _ -> True\n end\n | _ -> True\n end\n\nlet ni_com (env:label_fun) (c:com) (l:label) : Tot Type0 =\n (forall (h0: rel heap). (* {:pattern (low_equiv env h0)} *) ni_com' env c l h0) /\\\n (forall (h0:heap). (* {:pattern (Some? (interpret_com h0 c))} *) inv_com' env c l h0)\n\n(*********************** Typing Rules for Expressions **********************)\n\n(* CH: The way we derive these rules looks more like a\n semantically-justified program logic than a syntactic type\n system. Any connection to Dave Naumann and Anindya Banerjee's\n \"relational logic\"? (e.g. https://arxiv.org/abs/1611.08992) *)\n\n(* Subtyping rule for expression labels\n\n E |- e : l1 l1 <= l2\n ----------------------\n E |- e : l2\n*)\nval sub_exp : env:label_fun -> e:exp -> l1:label -> l2:label ->\n Lemma (requires (l1 <= l2 /\\ ni_exp env e l1))\n (ensures (ni_exp env e l2))\nlet sub_exp _ _ _ _ = ()\n\n\n\n(* Typing rule for dereferencing\n\n ----------------\n E | - r : E(r)\n*)\n\nval avar_exp : env:label_fun -> r:id ->\n Lemma (ensures (ni_exp env (AVar r) (env r)))\nlet avar_exp _ _ = ()\n\n(* Typing rule for Int constants\n\n i : int\n -------\n i : Low\n*)\nval aint_exp : env:label_fun -> i:int ->\n Lemma (requires True)\n (ensures (ni_exp env (AInt i) Low))\nlet aint_exp _ _ = ()\n\n\n(* Typing rule for binary operators\n\n e1 : l e2 : l\n ----------------\n e1 `op` e2 : l\n*)\n\nval binop_exp : env:label_fun -> op:binop -> e1:exp -> e2:exp -> l:label ->\n Lemma (requires (ni_exp env e1 l) /\\ (ni_exp env e2 l))\n (ensures (ni_exp env (AOp op e1 e2) l))\nlet binop_exp env op e1 e2 l =\n ()\n\n(************************ Typing Rules for Commands ************************)\n\n(* Subtyping rule for commands\n\n env,pc:l1 |- c l2 <= l1\n ---------------------------\n env,pc:l2 |- c\n*)\n\nval sub_com : env:label_fun -> c:com -> l1:label -> l2:label ->\n Lemma (requires (l2 <= l1 /\\ ni_com env c l1 ))\n (ensures (ni_com env c l2 ))\nlet sub_com _ _ _ _ = ()\n\n\n(* Typing rule for assignment\n\n env |- e : env(r)\n ------------------------\n env, pc:env(r) |- r := e\n\n - label of expression and context label have to be below label of r\n (first one to prevent explicit, second to prevent implicit flows)\n*)\n\nlet assign_inv_com0 (env:label_fun) (e:exp) (r:id) (ne:squash(ni_exp env e (env r))) (h0:rel heap)\n : Lemma (ni_com' env (Assign r e) (env r) h0)\n=\n FStar.Squash.give_proof ne ;\n let vr = reify (interpret_exp_st e) (R?.r h0) in\n let vl = reify (interpret_exp_st e) (R?.l h0) in\n match reify (interpret_com_st (Assign r e) (R?.l h0)) (R?.l h0) with\n | Some (), h1l ->\n begin match reify (interpret_com_st (Assign r e) (R?.r h0)) (R?.r h0) with\n | Some (), h1r -> assert (h1l = upd (R?.l h0) r vl /\\ h1r = upd (R?.r h0) r vr)\n | None, _ -> ()\n end\n | None, _ -> ()\n\nlet assign_inv_com' (env:label_fun) (e:exp) (r:id) (h0:heap)\n : Lemma (inv_com' env (Assign r e) (env r) h0)\n=\n let v = reify (interpret_exp_st e) h0 in\n match reify (interpret_com_st (Assign r e) h0) h0 with\n | None, h1 -> ()\n | Some (), h1 ->\n assert (h1 == upd h0 r v)\n\nval assign_com : env:label_fun -> e:exp -> r:id ->\n Lemma (requires (ni_exp env e (env r)))\n (ensures (ni_com env (Assign r e) (env r)))\nlet assign_com env e r =\n forall_intro (assign_inv_com0 env e r (FStar.Squash.get_proof (ni_exp env e (env r)))) ;\n forall_intro (assign_inv_com' env e r)\n\n\nlet seq_nil1 (c1:com) (c2:com) (h:heap)\n : Lemma\n (requires (fst (reify (interpret_com_st c1 h) h) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h) h) = None))\n = ()\n\nlet seq_nil2 (c1:com) (c2:com) (h0:heap) (h1:heap)\n : Lemma\n (requires (h1 == snd (reify (interpret_com_st c1 h0) h0) /\\\n fst (reify (interpret_com_st c2 h1) h1) = None))\n (ensures (fst (reify (interpret_com_st (Seq c1 c2) h0) h0) = None))\n = ()\n\n(* Sequencing rule for commands\n\n env,pc:l |- c1 env,pc:l |- c2\n ------------------------------\n env,pc:l |- c1; c2\n*)\n\nval seq_inv_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0:heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (inv_com' env (Seq c1 c2) l h0))\nlet seq_inv_com' env c1 c2 l h0 =\n match reify (interpret_com_st c1 h0) h0 with\n | None, _ -> seq_nil1 c1 c2 h0\n | Some (), h1 ->\n match reify (interpret_com_st c2 h1) h1 with\n | None, _ -> seq_nil2 c1 c2 h0 h1\n | Some (), h2 -> ()\n\n#set-options \"--z3rlimit 50\"\nlet use_ni_com (env:label_fun) (c:com) (l:label) (h:rel heap{low_equiv env h})\n : Lemma\n (requires ni_com env c l)\n (ensures\n (let R hl hr = h in\n match reify (interpret_com_st c hl) hl,\n reify (interpret_com_st c hr) hr with\n | (Some _, hl'),\n (Some _, hr') -> low_equiv env (R hl' hr')\n | _ -> True))\n = ()\n\nval seq_com' : env:label_fun -> c1:com -> c2:com -> l:label -> h0: rel heap ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com' env (Seq c1 c2) l h0))\nlet seq_com' env c1 c2 l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else begin\n assert (low_equiv env h0);\n let R h0l h0r = h0 in\n match reify (interpret_com_st c1 h0l) h0l with\n | None, _ -> seq_nil1 c1 c2 h0l\n | Some (), h1l ->\n match reify (interpret_com_st c1 h0r) h0r with\n | None, _ -> seq_nil1 c1 c2 h0r\n | Some (), h1r ->\n match reify (interpret_com_st c2 h1l) h1l with\n | None, _ -> seq_nil2 c1 c2 h0l h1l\n | Some (), h2l ->\n match reify (interpret_com_st c2 h1r) h1r with\n | None, _ -> seq_nil2 c1 c2 h0r h1r\n | Some (), h2r ->\n let h1 = R h1l h1r in\n use_ni_com env c1 l h0;\n assert (low_equiv env h1) ;\n let h2 = R h2l h2r in\n use_ni_com env c2 l h1;\n assert (low_equiv env h2)\n end\n\nval seq_com : env:label_fun -> c1:com -> c2:com -> l:label ->\n Lemma (requires (ni_com env c1 l /\\ ni_com env c2 l))\n (ensures (ni_com env (Seq c1 c2) l))\nlet seq_com env c1 c2 l =\n forall_intro\n (fun (h0:rel heap) ->\n seq_com' env c1 c2 l h0 <: Lemma (ni_com' env (Seq c1 c2) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n seq_inv_com' env c1 c2 l h0 <: Lemma (inv_com' env (Seq c1 c2) l h0))\n\n(* Typing rule for conditional commands\n\n env |- e : l env,pc:l |- ct env,pc:l |- cf\n ----------------------------------------------\n env,pc:l |- if e <> 0 then ct else cf\n*)\n\n(* let project_inv_com' (env:label_fun) (c:com) (l:label) (h0:heap) : Lemma (requires (ni_com env c l)) (ensures (inv_com' env c l h0)) = () *)\n\nval cond_inv_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (inv_com' env (If e ct cf) l h0))\nlet cond_inv_com' env e ct cf l h0 =\n let v = reify (interpret_exp_st e) h0 in\n if v = 0\n then assert (inv_com' env cf l h0 ==> inv_com' env (If e ct cf) l h0)\n else assert (inv_com' env ct l h0 ==> inv_com' env (If e ct cf) l h0)\n\n (* Works too but takes 20s more *)\n (* let c = if v = 0 then cf else ct in *)\n (* match reify (interpret_com_st c h0) h0 with *)\n (* | None, _ -> () *)\n (* | Some (), h1 -> () *)\n#reset-options \"--max_fuel 1\"\nlet interpret_cond (e:exp) (ct:com) (cf:com) (h:heap)\n : Lemma (let v = reify (interpret_exp_st e) h in\n let c = if v = 0 then cf else ct in\n (reify (interpret_com_st (If e ct cf) h) h ==\n reify (interpret_com_st c h) h))\n = ()\n\n\nval cond_ni_com' : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label -> h0:rel heap ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (ni_com' env (If e ct cf) l h0))\nlet cond_ni_com' env e ct cf l h0 =\n if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\n then ()\n else\n let R h0l h0r = h0 in\n let vl = reify (interpret_exp_st e) h0l in\n let vr = reify (interpret_exp_st e) h0r in\n if Low? l\n then begin\n assert (vl == vr) ;\n let c = if vl = 0 then cf else ct in\n assert (ni_com env c l) ;\n let cif = If e ct cf in\n //NS:05/15 ... this 2 should be trivial to prove.\n // Why do they require a lemma?\n interpret_cond e ct cf h0l;\n interpret_cond e ct cf h0r;\n use_ni_com env c l (R h0l h0r)\n end\n else (* h0 and h1 are low_equiv since cl and cr cannot write at low cells *)\n match reify (interpret_com_st (If e ct cf) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (If e ct cf) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n cond_inv_com' env e ct cf l h0l ;\n cond_inv_com' env e ct cf l h0r ;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))\n\n#set-options \"--z3rlimit 5\"\n\nval cond_com : env:label_fun -> e:exp -> ct:com -> cf:com -> l:label ->\n Lemma (requires ((ni_exp env e l) /\\ (ni_com env ct l) /\\ (ni_com env cf l)))\n (ensures (ni_com env (If e ct cf) l))\nlet cond_com env e ct cf l =\n forall_intro\n (fun (h0:rel heap) ->\n cond_ni_com' env e ct cf l h0 <: Lemma (ni_com' env (If e ct cf) l h0)) ;\n forall_intro\n (fun (h0:heap) ->\n cond_inv_com' env e ct cf l h0 <: Lemma (inv_com' env (If e ct cf) l h0))\n\n\n(* Typing rule for Skip\n\n -------------------\n env,pc:High |- skip\n*)\n\nval skip_com : env:label_fun ->\n Lemma (ni_com env Skip High)\nlet skip_com _ = ()\n\n(* While rule for commands\n\n env |- e : l env,pc:l |- c\n -----------------------------------\n env,pc:l |- while (e <> 0) do c\n*)\n\n\nval while_inv_com'\n : env:label_fun ->\n e:exp ->\n c:com ->\n v:metric ->\n l:label ->\n h0:heap ->\n Lemma\n (requires (ni_exp env e l /\\ ni_com env c l))\n (ensures (inv_com' env (While e c v) l h0))\n (decreases (decr_while h0 (While e c v)))\n\n#reset-options \"--z3rlimit 40\"\n\nlet interpret_while_nil e c v h\n : Lemma (requires (reify (interpret_exp_st e) h <> 0 /\\\n fst (reify (interpret_com_st c h) h) == None))\n (ensures (interpret_com h (While e c v) == None))\n = ()\n\nlet interpret_while_loops (e:exp) (c:com) (v:metric) (h:heap)\n : Lemma (requires (reify (interpret_exp_st e) h <> 0 /\\\n (match reify (interpret_com_st c h) h with\n | None, _ -> True\n | Some _, h' ->\n interpret_exp' h' v >= interpret_exp' h v)))\n (ensures (interpret_com h (While e c v) == None))\n = ()\n\nlet rec while_inv_com' env e c v l h0 =\n let v0 = reify (interpret_exp_st e) h0 in\n if v0 = 0 then assert (interpret_com h0 (While e c v) == Some h0)\n else\n let m0 = interpret_exp' h0 v in\n match reify (interpret_com_st c h0) h0 with\n | None, _ -> interpret_while_nil e c v h0\n | Some (), h2 ->\n let m1 = interpret_exp' h2 v in\n if m0 > m1\n then begin\n assert (decr_while h2 (While e c v) << decr_while h0 (While e c v)) ;\n while_inv_com' env e c v l h2\n end\n else interpret_while_loops e c v h0\n\nval while_ni_com'_low_equiv_high : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l /\\ low_equiv env h0 /\\ High? l))\n (ensures (ni_com' env (While e c v) l h0))\nlet while_ni_com'_low_equiv_high env e c v l h0 =\n (* h0 and h1 are low_equiv since cl and cr cannot write at low cells *)\n let R h0l h0r = h0 in\n match reify (interpret_com_st (While e c v) h0l) h0l with\n | None, _ -> ()\n | Some (), h1l ->\n match reify (interpret_com_st (While e c v) h0r) h0r with\n | None, _ -> ()\n | Some (), h1r ->\n while_inv_com' env e c v l h0l ;\n while_inv_com' env e c v l h0r ;\n assert (low_equiv env h0 ==> low_equiv env (R h1l h1r))\n\nval while_ni_com'_low_equiv_low : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l /\\ low_equiv env h0 /\\ Low? l))\n (ensures (ni_com' env (While e c v) l h0))\n (decreases (decr_while (R?.l h0) (While e c v) + decr_while (R?.r h0) (While e c v)))\nlet rec while_ni_com'_low_equiv_low env e c v l h0 =\n let R h0l h0r = h0 in\n let v0l = reify (interpret_exp_st e) h0l in\n let v0r = reify (interpret_exp_st e) h0r in\n assert (v0l == v0r) ;\n if v0l = 0 then begin\n assert (interpret_com h0l (While e c v) == Some h0l);\n assert (interpret_com h0r (While e c v) == Some h0r)\n end\n else\n let m0l = interpret_exp' h0l v in\n let m0r = interpret_exp' h0r v in\n match reify (interpret_com_st c h0l) h0l with\n | None, _ -> interpret_while_nil e c v h0l\n | Some (), h2l ->\n match reify (interpret_com_st c h0r) h0r with\n | None, _ -> interpret_while_nil e c v h0r\n | Some (), h2r ->\n let m1l = interpret_exp' h2l v in\n let m1r = interpret_exp' h2r v in\n if m0l > m1l\n then if m0r > m1r\n then begin\n assert (decr_while h2l (While e c v) << decr_while h0l (While e c v)) ;\n while_ni_com'_low_equiv_low env e c v l (R h2l h2r)\n end\n else interpret_while_loops e c v h0r\n else interpret_while_loops e c v h0l\n\nval while_ni_com' : env:label_fun -> e:exp -> c:com -> v:metric -> l:label -> h0:rel heap ->\n Lemma (requires (ni_exp env e l /\\ ni_com env c l))\n (ensures (ni_com' env (While e c v) l h0))\n\nPartial implementation:\nlet while_ni_com' env e c v l h0 =\n \n"
},
{
"role": "assistant",
"content": "if not (FStar.StrongExcludedMiddle.strong_excluded_middle (low_equiv env h0))\nthen ()\nelse\n if Low? l\n then while_ni_com'_low_equiv_low env e c v l h0\n else while_ni_com'_low_equiv_high env e c v l h0"
}
] |
This dataset is a preprocessed version of microsoft/FStarDataSet-V2. It has been reformatted into a chat-style JSONL structure for supervised fine-tuning of language models on F* function synthesis and proof completion.
The dataset consists of three splits:
fstar_train.jsonlfstar_validation.jsonlfstar_test.jsonlEach line in these files is a JSON object with the following schema (where the keys correspond to the keys in the original dataset):
{
"messages": [
{"role": "user", "content": "Complete this F* function with a correct proof.\nType: <verbose_type>\nEffect: <effect>\nContext: <file_context>\nPartial implementation: <partial_definition>"},
{"role": "assistant", "content": "<completed_definiton>"}
]
}
This format is compatible with supervised fine-tuning frameworks such as TRL, Fireworks AI SFT, or OpenAI-style chat tuning.
microsoft/FStarDataSet-V2The dataset is intended for research and experimentation in program synthesis, theorem proving, and fine-tuning large language models on functional proof-oriented languages such as F*.