messages
listlengths 2
2
|
|---|
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n post: FStar.Stubs.Reflection.Types.term ->\n a: FStar.Stubs.Reflection.Types.term ->\n ret_t: FStar.Stubs.Reflection.Types.term ->\n arr: 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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nlet elim_exists_post_body (u:universe) (a:term) (p:term) (x:var) =\n let x_tm = RT.var_as_term x in\n let reveal_x = mk_reveal u a x_tm in\n let post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\n RT.subst_term post [ RT.ND x 0 ]\n\nlet elim_exists_post (u:universe) (a:term) (p:term) (x:var) =\n let erased_a = mk_erased u a in\n mk_abs erased_a Q_Explicit (elim_exists_post_body u a p x)\n\nval elim_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n : GTot (RT.tot_typing g\n (mk_elim_exists u a p)\n (mk_stt_ghost_comp\n u\n (mk_erased u a)\n (mk_exists u a p)\n (elim_exists_post u a p x)))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n g |- e : vprop\n -------------------------------------------------------------------------\n g |- intro_exists<u> #a p e : stt_ghost<0> unit empty (p e) (fun _ -> exists_ p)\n\n*)\nval intro_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#e:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n (e_typing:RT.ghost_typing g e a)\n : GTot (RT.tot_typing g\n (mk_intro_exists u a p e)\n (mk_stt_ghost_comp uzero unit_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists u a p))))\n\n(*\n\n g |- a : Type u\n g |- p : vprop\n g |- q : a -> vprop\n ------------------------------------------\n g |- stt_admit a p q : stt a p q\n\n*)\n\nval stt_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_admit u a p q)\n (mk_stt_comp u a p q))\n \nval stt_atomic_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_admit u a p q)\n (mk_stt_atomic_comp neutral_fv u a emp_inames_tm p q))\n\nval stt_ghost_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_admit u a p q)\n (mk_stt_ghost_comp u a p q))\n\nval rewrite_typing\n (#g:env)\n (#p:term)\n (#q:term)\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q vprop_tm)\n (equiv:RT.tot_typing g (`()) (stt_vprop_equiv p q))\n\n\t\t: GTot (RT.tot_typing g\n (mk_rewrite p q)\n (mk_stt_ghost_comp\n uzero\n unit_tm\n p\n (mk_abs unit_tm Q_Explicit q)))\n\n// mk_star pre (mk_pts_to a (RT.bound_var 0) full_perm_tm init\nlet with_local_body_pre (pre:term) (a:term) (x:term) (init:term) : term =\n let pts_to : term =\n mk_pts_to a x full_perm_tm init in\n mk_star pre pts_to\n\n//\n// post has 0 db index free\n//\nlet with_local_body_post_body (post:term) (a:term) (x:term) : term =\n // exists_ (R.pts_to r full_perm)\n let exists_tm =\n mk_exists (pack_universe Uv_Zero) a\n (mk_abs a Q_Explicit\n (mk_pts_to a x full_perm_tm (RT.bound_var 0))) in\n mk_star post exists_tm\n\nlet with_local_body_post (post:term) (a:term) (ret_t:term) (x:term) : term =\n mk_abs ret_t Q_Explicit (with_local_body_post_body post a x)\n\nval with_local_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#init:term)\n (#pre:term)\n (#ret_t:term)\n (#post:term) // post has db 0 free\n (#body:term) // body has x free\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type (pack_universe Uv_Zero))))\n (init_typing:RT.tot_typing g init a)\n (pre_typing:RT.tot_typing g pre vprop_tm)\n (ret_t_typing:RT.tot_typing g ret_t (pack_ln (Tv_Type u)))\n (post_typing:RT.tot_typing g (RT.mk_abs ret_t Q_Explicit post)\n (mk_arrow (ret_t, Q_Explicit) vprop_tm))\n (body_typing:RT.tot_typing (RT.extend_env g x (mk_ref a)) \n body\n (mk_stt_comp u ret_t\n (with_local_body_pre pre a (RT.var_as_term x) init)\n (with_local_body_post post a ret_t (RT.var_as_term x))))\n\n : GTot (RT.tot_typing g (mk_withlocal u a init pre ret_t (RT.mk_abs ret_t Q_Explicit post)\n (RT.mk_abs (mk_ref a) Q_Explicit (RT.close_term body x)))\n (mk_stt_comp u ret_t pre (mk_abs ret_t Q_Explicit post)))\n\nlet with_localarray_body_pre (pre:term) (a:term) (arr:term) (init:term) (len:term) : term =\n let pts_to : term =\n mk_array_pts_to a arr full_perm_tm (mk_seq_create uzero a (mk_szv len) init) in\n let len_vp : term =\n mk_pure (mk_eq2 uzero nat_tm (mk_array_length a arr) (mk_szv len)) in\n mk_star pre (mk_star pts_to len_vp)\n\n//\n// post has 0 db index free\n//\nlet with_localarray_body_post_body (post:term) (a:term) (arr:term) : term =\n // exists_ (A.pts_to arr full_perm)\n let exists_tm =\n mk_exists uzero (mk_seq uzero a)\n (mk_abs (mk_seq uzero a) Q_Explicit\n (mk_array_pts_to a arr full_perm_tm (RT.bound_var 0))) in\n mk_star post exists_tm\n\nPartial implementation:\nlet with_localarray_body_post (post a ret_t arr: term) : term =\n \n"
},
{
"role": "assistant",
"content": "mk_abs ret_t Q_Explicit (with_localarray_body_post_body post a arr)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: k_seq: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0\nEffect: Prims.Tot\n\nContext:\nmodule Vale.SHA.PPC64LE.SHA_helpers\n\nopen FStar.Mul\nopen Vale.Def.Prop_s\nopen Vale.Def.Opaque_s\nopen Vale.Def.Types_s\nopen Vale.Def.Words_s\nopen Vale.Def.Words.Seq_s\nopen FStar.Seq\nopen Vale.Arch.Types\nopen Vale.Def.Sel\nopen Vale.SHA2.Wrapper\nopen Vale.Def.Words.Four_s\n\nunfold let (.[]) = FStar.Seq.index\n\n#reset-options \"--max_fuel 0 --max_ifuel 0\"\n\n// Specialize these definitions (from Spec.SHA2.fst) for SHA256\nunfold let size_k_w_256 = 64\nval word:Type0\n(* Number of words for a block size *)\nlet size_block_w_256 = 16\n(* Define the size block in bytes *)\nlet block_length =\n 4 (*word_length a*) * size_block_w_256\nlet block_w = m:seq word {length m = size_block_w_256}\nlet counter = nat\nval k : (s:seq word {length s = size_k_w_256})\nlet hash256 = m:Seq.seq word {Seq.length m = 8}\n\n(* Input data. *)\ntype byte = UInt8.t\ntype bytes = Seq.seq byte\n\n(* Input data, multiple of a block length. *)\nlet bytes_blocks =\n l:bytes { Seq.length l % block_length = 0 }\n\n// Hide various SHA2 definitions\nval ws_opaque (b:block_w) (t:counter{t < size_k_w_256}):nat32\nval shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256\nval update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256\nval update_multi_transparent (hash:hash256) (blocks:bytes_blocks):hash256\n\n// Hide some functions that operate on words & bytes\nval word_to_nat32 (x:word) : nat32\nval nat32_to_word (x:nat32) : word\n\n//unfold let bytes_blocks256 = bytes_blocks SHA2_256\nlet repeat_range_vale (max:nat { max < size_k_w_256}) (block:block_w) (hash:hash256) =\n Spec.Loops.repeat_range 0 max (shuffle_core_opaque block) hash\nlet update_multi_opaque_vale (hash:hash256) (blocks:bytes) : hash256 =\n if length blocks % size_k_w_256 = 0 then let b:bytes_blocks = blocks in update_multi_opaque hash b else hash\n\nval make_ordered_hash (abcd efgh:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word abcd.lo0 /\\\n hash.[1] == nat32_to_word abcd.lo1 /\\\n hash.[2] == nat32_to_word abcd.hi2 /\\\n hash.[3] == nat32_to_word abcd.hi3 /\\\n hash.[4] == nat32_to_word efgh.lo0 /\\\n hash.[5] == nat32_to_word efgh.lo1 /\\\n hash.[6] == nat32_to_word efgh.hi2 /\\\n hash.[7] == nat32_to_word efgh.hi3\n )\n\nval update_block (hash:hash256) (block:block_w): hash256\n\nval lemma_update_multi_opaque_vale_is_update_multi (hash:hash256) (blocks:bytes) : Lemma\n (requires length blocks % 64 = 0)\n (ensures update_multi_opaque_vale hash blocks == update_multi_transparent hash blocks)\n\nval sigma_0_0_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_0_partial = opaque_make sigma_0_0_partial_def\nirreducible let sigma_0_0_partial_reveal = opaque_revealer (`%sigma_0_0_partial) sigma_0_0_partial sigma_0_0_partial_def\n\nval lemma_sha256_sigma0 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-15))\n (ensures (sigma256_0_0 src.hi3 == sigma_0_0_partial t block))\n\nval sigma_0_1_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_1_partial = opaque_make sigma_0_1_partial_def\nirreducible let sigma_0_1_partial_reveal = opaque_revealer (`%sigma_0_1_partial) sigma_0_1_partial sigma_0_1_partial_def\n\nval lemma_sha256_sigma1 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-2))\n (ensures (sigma256_0_1 src.hi3 == sigma_0_1_partial t block))\n\nval sigma_1_0_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_0_partial = opaque_make sigma_1_0_partial_def\nirreducible let sigma_1_0_partial_reveal = opaque_revealer (`%sigma_1_0_partial) sigma_1_0_partial sigma_1_0_partial_def\n\nval lemma_sha256_sigma2 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[0]))\n (ensures (sigma256_1_0 src.hi3 == sigma_1_0_partial t block hash_orig))\n\nval sigma_1_1_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_1_partial = opaque_make sigma_1_1_partial_def\nirreducible let sigma_1_1_partial_reveal = opaque_revealer (`%sigma_1_1_partial) sigma_1_1_partial sigma_1_1_partial_def\n\nval lemma_sha256_sigma3 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[4]))\n (ensures (sigma256_1_1 src.hi3 == sigma_1_1_partial t block hash_orig))\n\nval make_seperated_hash (a b c d e f g h:nat32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a /\\\n hash.[1] == nat32_to_word b /\\\n hash.[2] == nat32_to_word c /\\\n hash.[3] == nat32_to_word d /\\\n hash.[4] == nat32_to_word e /\\\n hash.[5] == nat32_to_word f /\\\n hash.[6] == nat32_to_word g /\\\n hash.[7] == nat32_to_word h\n )\n\nval make_seperated_hash_quad32 (a b c d e f g h:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a.hi3 /\\\n hash.[1] == nat32_to_word b.hi3 /\\\n hash.[2] == nat32_to_word c.hi3 /\\\n hash.[3] == nat32_to_word d.hi3 /\\\n hash.[4] == nat32_to_word e.hi3 /\\\n hash.[5] == nat32_to_word f.hi3 /\\\n hash.[6] == nat32_to_word g.hi3 /\\\n hash.[7] == nat32_to_word h.hi3\n )\n\nval lemma_make_seperated_hash (hash:hash256) (a b c d e f g h:quad32) : Lemma\n (requires length hash == 8 /\\\n a.hi3 == word_to_nat32 hash.[0] /\\\n b.hi3 == word_to_nat32 hash.[1] /\\\n c.hi3 == word_to_nat32 hash.[2] /\\\n d.hi3 == word_to_nat32 hash.[3] /\\\n e.hi3 == word_to_nat32 hash.[4] /\\\n f.hi3 == word_to_nat32 hash.[5] /\\\n g.hi3 == word_to_nat32 hash.[6] /\\\n h.hi3 == word_to_nat32 hash.[7])\n (ensures hash == make_seperated_hash_quad32 a b c d e f g h)\n\nval lemma_vsel32 (a b c:nat32) : Lemma\n (ensures (isel32 a b c = (iand32 c a) *^ (iand32 (inot32 c) b)))\n\nval ch_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ (iand32 (inot32 x) z))\n\nval lemma_eq_maj_xvsel32 (a b c:nat32) : Lemma\n (ensures (isel32 c b (a *^ b) = (iand32 a b) *^ ((iand32 a c) *^ (iand32 b c))))\n\nval maj_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ ((iand32 x z) *^ (iand32 y z)))\n\nval lemma_sigma_0_0_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_0 (ws_opaque block (t-15)) == sigma_0_0_partial t block))\n\nval lemma_sigma_0_1_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_1 (ws_opaque block (t-2)) == sigma_0_1_partial t block))\n\nval lemma_sigma_1_0_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_0 (word_to_nat32 ((repeat_range_vale t block hash_orig).[0])) == sigma_1_0_partial t block hash_orig))\n\nval lemma_sigma_1_1_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_1 (word_to_nat32 ((repeat_range_vale t block hash_orig).[4])) == sigma_1_1_partial t block hash_orig))\n\nPartial implementation:\nlet k_reqs (k_seq: seq quad32) : prop0 =\n \n"
},
{
"role": "assistant",
"content": "length k_seq == size_k_w_256 / 4 /\\\n(forall i. {:pattern (index k_seq i)}\n 0 <= i /\\ i < (size_k_w_256 / 4) ==>\n (k_seq.[ i ]).lo0 == word_to_nat32 (k.[ 4 * i ]) /\\\n (k_seq.[ i ]).lo1 == word_to_nat32 (k.[ 4 * i + 1 ]) /\\\n (k_seq.[ i ]).hi2 == word_to_nat32 (k.[ 4 * i + 2 ]) /\\\n (k_seq.[ i ]).hi3 == word_to_nat32 (k.[ 4 * i + 3 ]))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n pre: FStar.Stubs.Reflection.Types.term ->\n a: FStar.Stubs.Reflection.Types.term ->\n arr: FStar.Stubs.Reflection.Types.term ->\n init: FStar.Stubs.Reflection.Types.term ->\n len: 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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nlet elim_exists_post_body (u:universe) (a:term) (p:term) (x:var) =\n let x_tm = RT.var_as_term x in\n let reveal_x = mk_reveal u a x_tm in\n let post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\n RT.subst_term post [ RT.ND x 0 ]\n\nlet elim_exists_post (u:universe) (a:term) (p:term) (x:var) =\n let erased_a = mk_erased u a in\n mk_abs erased_a Q_Explicit (elim_exists_post_body u a p x)\n\nval elim_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n : GTot (RT.tot_typing g\n (mk_elim_exists u a p)\n (mk_stt_ghost_comp\n u\n (mk_erased u a)\n (mk_exists u a p)\n (elim_exists_post u a p x)))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n g |- e : vprop\n -------------------------------------------------------------------------\n g |- intro_exists<u> #a p e : stt_ghost<0> unit empty (p e) (fun _ -> exists_ p)\n\n*)\nval intro_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#e:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n (e_typing:RT.ghost_typing g e a)\n : GTot (RT.tot_typing g\n (mk_intro_exists u a p e)\n (mk_stt_ghost_comp uzero unit_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists u a p))))\n\n(*\n\n g |- a : Type u\n g |- p : vprop\n g |- q : a -> vprop\n ------------------------------------------\n g |- stt_admit a p q : stt a p q\n\n*)\n\nval stt_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_admit u a p q)\n (mk_stt_comp u a p q))\n \nval stt_atomic_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_admit u a p q)\n (mk_stt_atomic_comp neutral_fv u a emp_inames_tm p q))\n\nval stt_ghost_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_admit u a p q)\n (mk_stt_ghost_comp u a p q))\n\nval rewrite_typing\n (#g:env)\n (#p:term)\n (#q:term)\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q vprop_tm)\n (equiv:RT.tot_typing g (`()) (stt_vprop_equiv p q))\n\n\t\t: GTot (RT.tot_typing g\n (mk_rewrite p q)\n (mk_stt_ghost_comp\n uzero\n unit_tm\n p\n (mk_abs unit_tm Q_Explicit q)))\n\n// mk_star pre (mk_pts_to a (RT.bound_var 0) full_perm_tm init\nlet with_local_body_pre (pre:term) (a:term) (x:term) (init:term) : term =\n let pts_to : term =\n mk_pts_to a x full_perm_tm init in\n mk_star pre pts_to\n\n//\n// post has 0 db index free\n//\nlet with_local_body_post_body (post:term) (a:term) (x:term) : term =\n // exists_ (R.pts_to r full_perm)\n let exists_tm =\n mk_exists (pack_universe Uv_Zero) a\n (mk_abs a Q_Explicit\n (mk_pts_to a x full_perm_tm (RT.bound_var 0))) in\n mk_star post exists_tm\n\nlet with_local_body_post (post:term) (a:term) (ret_t:term) (x:term) : term =\n mk_abs ret_t Q_Explicit (with_local_body_post_body post a x)\n\nval with_local_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#init:term)\n (#pre:term)\n (#ret_t:term)\n (#post:term) // post has db 0 free\n (#body:term) // body has x free\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type (pack_universe Uv_Zero))))\n (init_typing:RT.tot_typing g init a)\n (pre_typing:RT.tot_typing g pre vprop_tm)\n (ret_t_typing:RT.tot_typing g ret_t (pack_ln (Tv_Type u)))\n (post_typing:RT.tot_typing g (RT.mk_abs ret_t Q_Explicit post)\n (mk_arrow (ret_t, Q_Explicit) vprop_tm))\n (body_typing:RT.tot_typing (RT.extend_env g x (mk_ref a)) \n body\n (mk_stt_comp u ret_t\n (with_local_body_pre pre a (RT.var_as_term x) init)\n (with_local_body_post post a ret_t (RT.var_as_term x))))\n\n : GTot (RT.tot_typing g (mk_withlocal u a init pre ret_t (RT.mk_abs ret_t Q_Explicit post)\n (RT.mk_abs (mk_ref a) Q_Explicit (RT.close_term body x)))\n (mk_stt_comp u ret_t pre (mk_abs ret_t Q_Explicit post)))\n\nPartial implementation:\nlet with_localarray_body_pre (pre a arr init len: term) : term =\n \n"
},
{
"role": "assistant",
"content": "let pts_to:term = mk_array_pts_to a arr full_perm_tm (mk_seq_create uzero a (mk_szv len) init) in\nlet len_vp:term = mk_pure (mk_eq2 uzero nat_tm (mk_array_length a arr) (mk_szv len)) in\nmk_star pre (mk_star pts_to len_vp)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: r: Vale.X64.Machine_s.reg_64 -> Prims.bool\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nPartial implementation:\nlet cswap_regs_modified: MS.reg_64 -> bool =\n \n"
},
{
"role": "assistant",
"content": "fun (r: MS.reg_64) ->\n let open MS in if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true else false"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: qs: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Vale.SHA.PPC64LE.SHA_helpers.block_w\nEffect: Prims.Tot\n\nContext:\nmodule Vale.SHA.PPC64LE.SHA_helpers\n\nopen FStar.Mul\nopen Vale.Def.Prop_s\nopen Vale.Def.Opaque_s\nopen Vale.Def.Types_s\nopen Vale.Def.Words_s\nopen Vale.Def.Words.Seq_s\nopen FStar.Seq\nopen Vale.Arch.Types\nopen Vale.Def.Sel\nopen Vale.SHA2.Wrapper\nopen Vale.Def.Words.Four_s\n\nunfold let (.[]) = FStar.Seq.index\n\n#reset-options \"--max_fuel 0 --max_ifuel 0\"\n\n// Specialize these definitions (from Spec.SHA2.fst) for SHA256\nunfold let size_k_w_256 = 64\nval word:Type0\n(* Number of words for a block size *)\nlet size_block_w_256 = 16\n(* Define the size block in bytes *)\nlet block_length =\n 4 (*word_length a*) * size_block_w_256\nlet block_w = m:seq word {length m = size_block_w_256}\nlet counter = nat\nval k : (s:seq word {length s = size_k_w_256})\nlet hash256 = m:Seq.seq word {Seq.length m = 8}\n\n(* Input data. *)\ntype byte = UInt8.t\ntype bytes = Seq.seq byte\n\n(* Input data, multiple of a block length. *)\nlet bytes_blocks =\n l:bytes { Seq.length l % block_length = 0 }\n\n// Hide various SHA2 definitions\nval ws_opaque (b:block_w) (t:counter{t < size_k_w_256}):nat32\nval shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256\nval update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256\nval update_multi_transparent (hash:hash256) (blocks:bytes_blocks):hash256\n\n// Hide some functions that operate on words & bytes\nval word_to_nat32 (x:word) : nat32\nval nat32_to_word (x:nat32) : word\n\n//unfold let bytes_blocks256 = bytes_blocks SHA2_256\nlet repeat_range_vale (max:nat { max < size_k_w_256}) (block:block_w) (hash:hash256) =\n Spec.Loops.repeat_range 0 max (shuffle_core_opaque block) hash\nlet update_multi_opaque_vale (hash:hash256) (blocks:bytes) : hash256 =\n if length blocks % size_k_w_256 = 0 then let b:bytes_blocks = blocks in update_multi_opaque hash b else hash\n\nval make_ordered_hash (abcd efgh:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word abcd.lo0 /\\\n hash.[1] == nat32_to_word abcd.lo1 /\\\n hash.[2] == nat32_to_word abcd.hi2 /\\\n hash.[3] == nat32_to_word abcd.hi3 /\\\n hash.[4] == nat32_to_word efgh.lo0 /\\\n hash.[5] == nat32_to_word efgh.lo1 /\\\n hash.[6] == nat32_to_word efgh.hi2 /\\\n hash.[7] == nat32_to_word efgh.hi3\n )\n\nval update_block (hash:hash256) (block:block_w): hash256\n\nval lemma_update_multi_opaque_vale_is_update_multi (hash:hash256) (blocks:bytes) : Lemma\n (requires length blocks % 64 = 0)\n (ensures update_multi_opaque_vale hash blocks == update_multi_transparent hash blocks)\n\nval sigma_0_0_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_0_partial = opaque_make sigma_0_0_partial_def\nirreducible let sigma_0_0_partial_reveal = opaque_revealer (`%sigma_0_0_partial) sigma_0_0_partial sigma_0_0_partial_def\n\nval lemma_sha256_sigma0 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-15))\n (ensures (sigma256_0_0 src.hi3 == sigma_0_0_partial t block))\n\nval sigma_0_1_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_1_partial = opaque_make sigma_0_1_partial_def\nirreducible let sigma_0_1_partial_reveal = opaque_revealer (`%sigma_0_1_partial) sigma_0_1_partial sigma_0_1_partial_def\n\nval lemma_sha256_sigma1 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-2))\n (ensures (sigma256_0_1 src.hi3 == sigma_0_1_partial t block))\n\nval sigma_1_0_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_0_partial = opaque_make sigma_1_0_partial_def\nirreducible let sigma_1_0_partial_reveal = opaque_revealer (`%sigma_1_0_partial) sigma_1_0_partial sigma_1_0_partial_def\n\nval lemma_sha256_sigma2 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[0]))\n (ensures (sigma256_1_0 src.hi3 == sigma_1_0_partial t block hash_orig))\n\nval sigma_1_1_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_1_partial = opaque_make sigma_1_1_partial_def\nirreducible let sigma_1_1_partial_reveal = opaque_revealer (`%sigma_1_1_partial) sigma_1_1_partial sigma_1_1_partial_def\n\nval lemma_sha256_sigma3 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[4]))\n (ensures (sigma256_1_1 src.hi3 == sigma_1_1_partial t block hash_orig))\n\nval make_seperated_hash (a b c d e f g h:nat32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a /\\\n hash.[1] == nat32_to_word b /\\\n hash.[2] == nat32_to_word c /\\\n hash.[3] == nat32_to_word d /\\\n hash.[4] == nat32_to_word e /\\\n hash.[5] == nat32_to_word f /\\\n hash.[6] == nat32_to_word g /\\\n hash.[7] == nat32_to_word h\n )\n\nval make_seperated_hash_quad32 (a b c d e f g h:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a.hi3 /\\\n hash.[1] == nat32_to_word b.hi3 /\\\n hash.[2] == nat32_to_word c.hi3 /\\\n hash.[3] == nat32_to_word d.hi3 /\\\n hash.[4] == nat32_to_word e.hi3 /\\\n hash.[5] == nat32_to_word f.hi3 /\\\n hash.[6] == nat32_to_word g.hi3 /\\\n hash.[7] == nat32_to_word h.hi3\n )\n\nval lemma_make_seperated_hash (hash:hash256) (a b c d e f g h:quad32) : Lemma\n (requires length hash == 8 /\\\n a.hi3 == word_to_nat32 hash.[0] /\\\n b.hi3 == word_to_nat32 hash.[1] /\\\n c.hi3 == word_to_nat32 hash.[2] /\\\n d.hi3 == word_to_nat32 hash.[3] /\\\n e.hi3 == word_to_nat32 hash.[4] /\\\n f.hi3 == word_to_nat32 hash.[5] /\\\n g.hi3 == word_to_nat32 hash.[6] /\\\n h.hi3 == word_to_nat32 hash.[7])\n (ensures hash == make_seperated_hash_quad32 a b c d e f g h)\n\nval lemma_vsel32 (a b c:nat32) : Lemma\n (ensures (isel32 a b c = (iand32 c a) *^ (iand32 (inot32 c) b)))\n\nval ch_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ (iand32 (inot32 x) z))\n\nval lemma_eq_maj_xvsel32 (a b c:nat32) : Lemma\n (ensures (isel32 c b (a *^ b) = (iand32 a b) *^ ((iand32 a c) *^ (iand32 b c))))\n\nval maj_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ ((iand32 x z) *^ (iand32 y z)))\n\nval lemma_sigma_0_0_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_0 (ws_opaque block (t-15)) == sigma_0_0_partial t block))\n\nval lemma_sigma_0_1_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_1 (ws_opaque block (t-2)) == sigma_0_1_partial t block))\n\nval lemma_sigma_1_0_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_0 (word_to_nat32 ((repeat_range_vale t block hash_orig).[0])) == sigma_1_0_partial t block hash_orig))\n\nval lemma_sigma_1_1_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_1 (word_to_nat32 ((repeat_range_vale t block hash_orig).[4])) == sigma_1_1_partial t block hash_orig))\n\n(* Abbreviations and lemmas for the code itself *)\nlet k_reqs (k_seq:seq quad32) : prop0 =\n length k_seq == size_k_w_256 / 4 /\\\n (forall i . {:pattern (index k_seq i)} 0 <= i /\\ i < (size_k_w_256/4) ==>\n (k_seq.[i]).lo0 == word_to_nat32 (k.[4 * i]) /\\\n (k_seq.[i]).lo1 == word_to_nat32 (k.[4 * i + 1]) /\\\n (k_seq.[i]).hi2 == word_to_nat32 (k.[4 * i + 2]) /\\\n (k_seq.[i]).hi3 == word_to_nat32 (k.[4 * i + 3]))\n\nPartial implementation:\nlet quads_to_block_be (qs: seq quad32) : block_w =\n \n"
},
{
"role": "assistant",
"content": "let nat32_seq = Vale.Def.Words.Seq_s.seq_four_to_seq_BE qs in\nlet f (n: nat{n < 16}) : word =\n nat32_to_word (if n < length nat32_seq then nat32_seq.[ n ] else 0)\nin\ninit 16 f"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: b: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> Vale.SHA.PPC64LE.SHA_helpers.hash256\nEffect: Prims.Tot\n\nContext:\nmodule Vale.SHA.PPC64LE.SHA_helpers\n\nopen FStar.Mul\nopen Vale.Def.Prop_s\nopen Vale.Def.Opaque_s\nopen Vale.Def.Types_s\nopen Vale.Def.Words_s\nopen Vale.Def.Words.Seq_s\nopen FStar.Seq\nopen Vale.Arch.Types\nopen Vale.Def.Sel\nopen Vale.SHA2.Wrapper\nopen Vale.Def.Words.Four_s\n\nunfold let (.[]) = FStar.Seq.index\n\n#reset-options \"--max_fuel 0 --max_ifuel 0\"\n\n// Specialize these definitions (from Spec.SHA2.fst) for SHA256\nunfold let size_k_w_256 = 64\nval word:Type0\n(* Number of words for a block size *)\nlet size_block_w_256 = 16\n(* Define the size block in bytes *)\nlet block_length =\n 4 (*word_length a*) * size_block_w_256\nlet block_w = m:seq word {length m = size_block_w_256}\nlet counter = nat\nval k : (s:seq word {length s = size_k_w_256})\nlet hash256 = m:Seq.seq word {Seq.length m = 8}\n\n(* Input data. *)\ntype byte = UInt8.t\ntype bytes = Seq.seq byte\n\n(* Input data, multiple of a block length. *)\nlet bytes_blocks =\n l:bytes { Seq.length l % block_length = 0 }\n\n// Hide various SHA2 definitions\nval ws_opaque (b:block_w) (t:counter{t < size_k_w_256}):nat32\nval shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256\nval update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256\nval update_multi_transparent (hash:hash256) (blocks:bytes_blocks):hash256\n\n// Hide some functions that operate on words & bytes\nval word_to_nat32 (x:word) : nat32\nval nat32_to_word (x:nat32) : word\n\n//unfold let bytes_blocks256 = bytes_blocks SHA2_256\nlet repeat_range_vale (max:nat { max < size_k_w_256}) (block:block_w) (hash:hash256) =\n Spec.Loops.repeat_range 0 max (shuffle_core_opaque block) hash\nlet update_multi_opaque_vale (hash:hash256) (blocks:bytes) : hash256 =\n if length blocks % size_k_w_256 = 0 then let b:bytes_blocks = blocks in update_multi_opaque hash b else hash\n\nval make_ordered_hash (abcd efgh:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word abcd.lo0 /\\\n hash.[1] == nat32_to_word abcd.lo1 /\\\n hash.[2] == nat32_to_word abcd.hi2 /\\\n hash.[3] == nat32_to_word abcd.hi3 /\\\n hash.[4] == nat32_to_word efgh.lo0 /\\\n hash.[5] == nat32_to_word efgh.lo1 /\\\n hash.[6] == nat32_to_word efgh.hi2 /\\\n hash.[7] == nat32_to_word efgh.hi3\n )\n\nval update_block (hash:hash256) (block:block_w): hash256\n\nval lemma_update_multi_opaque_vale_is_update_multi (hash:hash256) (blocks:bytes) : Lemma\n (requires length blocks % 64 = 0)\n (ensures update_multi_opaque_vale hash blocks == update_multi_transparent hash blocks)\n\nval sigma_0_0_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_0_partial = opaque_make sigma_0_0_partial_def\nirreducible let sigma_0_0_partial_reveal = opaque_revealer (`%sigma_0_0_partial) sigma_0_0_partial sigma_0_0_partial_def\n\nval lemma_sha256_sigma0 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-15))\n (ensures (sigma256_0_0 src.hi3 == sigma_0_0_partial t block))\n\nval sigma_0_1_partial_def (t:counter) (block:block_w) : nat32\n[@\"opaque_to_smt\"] let sigma_0_1_partial = opaque_make sigma_0_1_partial_def\nirreducible let sigma_0_1_partial_reveal = opaque_revealer (`%sigma_0_1_partial) sigma_0_1_partial sigma_0_1_partial_def\n\nval lemma_sha256_sigma1 (src:quad32) (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256 /\\\n src.hi3 == ws_opaque block (t-2))\n (ensures (sigma256_0_1 src.hi3 == sigma_0_1_partial t block))\n\nval sigma_1_0_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_0_partial = opaque_make sigma_1_0_partial_def\nirreducible let sigma_1_0_partial_reveal = opaque_revealer (`%sigma_1_0_partial) sigma_1_0_partial sigma_1_0_partial_def\n\nval lemma_sha256_sigma2 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[0]))\n (ensures (sigma256_1_0 src.hi3 == sigma_1_0_partial t block hash_orig))\n\nval sigma_1_1_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32\n[@\"opaque_to_smt\"] let sigma_1_1_partial = opaque_make sigma_1_1_partial_def\nirreducible let sigma_1_1_partial_reveal = opaque_revealer (`%sigma_1_1_partial) sigma_1_1_partial sigma_1_1_partial_def\n\nval lemma_sha256_sigma3 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256 /\\\n src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[4]))\n (ensures (sigma256_1_1 src.hi3 == sigma_1_1_partial t block hash_orig))\n\nval make_seperated_hash (a b c d e f g h:nat32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a /\\\n hash.[1] == nat32_to_word b /\\\n hash.[2] == nat32_to_word c /\\\n hash.[3] == nat32_to_word d /\\\n hash.[4] == nat32_to_word e /\\\n hash.[5] == nat32_to_word f /\\\n hash.[6] == nat32_to_word g /\\\n hash.[7] == nat32_to_word h\n )\n\nval make_seperated_hash_quad32 (a b c d e f g h:quad32): Pure (hash256)\n (requires True)\n (ensures fun hash ->\n length hash == 8 /\\\n hash.[0] == nat32_to_word a.hi3 /\\\n hash.[1] == nat32_to_word b.hi3 /\\\n hash.[2] == nat32_to_word c.hi3 /\\\n hash.[3] == nat32_to_word d.hi3 /\\\n hash.[4] == nat32_to_word e.hi3 /\\\n hash.[5] == nat32_to_word f.hi3 /\\\n hash.[6] == nat32_to_word g.hi3 /\\\n hash.[7] == nat32_to_word h.hi3\n )\n\nval lemma_make_seperated_hash (hash:hash256) (a b c d e f g h:quad32) : Lemma\n (requires length hash == 8 /\\\n a.hi3 == word_to_nat32 hash.[0] /\\\n b.hi3 == word_to_nat32 hash.[1] /\\\n c.hi3 == word_to_nat32 hash.[2] /\\\n d.hi3 == word_to_nat32 hash.[3] /\\\n e.hi3 == word_to_nat32 hash.[4] /\\\n f.hi3 == word_to_nat32 hash.[5] /\\\n g.hi3 == word_to_nat32 hash.[6] /\\\n h.hi3 == word_to_nat32 hash.[7])\n (ensures hash == make_seperated_hash_quad32 a b c d e f g h)\n\nval lemma_vsel32 (a b c:nat32) : Lemma\n (ensures (isel32 a b c = (iand32 c a) *^ (iand32 (inot32 c) b)))\n\nval ch_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ (iand32 (inot32 x) z))\n\nval lemma_eq_maj_xvsel32 (a b c:nat32) : Lemma\n (ensures (isel32 c b (a *^ b) = (iand32 a b) *^ ((iand32 a c) *^ (iand32 b c))))\n\nval maj_256 (x y z:nat32):Pure(nat32)\n (requires True)\n (ensures fun a -> a == (iand32 x y) *^ ((iand32 x z) *^ (iand32 y z)))\n\nval lemma_sigma_0_0_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_0 (ws_opaque block (t-15)) == sigma_0_0_partial t block))\n\nval lemma_sigma_0_1_partial (t:counter) (block:block_w) : Lemma\n (requires 16 <= t /\\ t < size_k_w_256)\n (ensures (sigma256_0_1 (ws_opaque block (t-2)) == sigma_0_1_partial t block))\n\nval lemma_sigma_1_0_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_0 (word_to_nat32 ((repeat_range_vale t block hash_orig).[0])) == sigma_1_0_partial t block hash_orig))\n\nval lemma_sigma_1_1_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (sigma256_1_1 (word_to_nat32 ((repeat_range_vale t block hash_orig).[4])) == sigma_1_1_partial t block hash_orig))\n\n(* Abbreviations and lemmas for the code itself *)\nlet k_reqs (k_seq:seq quad32) : prop0 =\n length k_seq == size_k_w_256 / 4 /\\\n (forall i . {:pattern (index k_seq i)} 0 <= i /\\ i < (size_k_w_256/4) ==>\n (k_seq.[i]).lo0 == word_to_nat32 (k.[4 * i]) /\\\n (k_seq.[i]).lo1 == word_to_nat32 (k.[4 * i + 1]) /\\\n (k_seq.[i]).hi2 == word_to_nat32 (k.[4 * i + 2]) /\\\n (k_seq.[i]).hi3 == word_to_nat32 (k.[4 * i + 3]))\n\nlet quads_to_block_be (qs:seq quad32) : block_w\n =\n let nat32_seq = Vale.Def.Words.Seq_s.seq_four_to_seq_BE qs in\n let f (n:nat{n < 16}) : word = nat32_to_word (if n < length nat32_seq then nat32_seq.[n] else 0) in\n init 16 f\n\nval lemma_quads_to_block_be (qs:seq quad32) : Lemma\n (requires length qs == 4)\n (ensures\n (let block = quads_to_block_be qs in\n forall i . {:pattern (index qs i)} 0 <= i /\\ i < 4 ==>\n (qs.[i]).hi3 == ws_opaque block (4 * i + 0) /\\\n (qs.[i]).hi2 == ws_opaque block (4 * i + 1) /\\\n (qs.[i]).lo1 == ws_opaque block (4 * i + 2) /\\\n (qs.[i]).lo0 == ws_opaque block (4 * i + 3)))\n\nlet k_index (ks:seq quad32) (i:nat) : nat32 =\n if length ks = size_k_w_256 / 4 && i < size_k_w_256 then four_select ks.[(i/4)] (i % 4)\n else 0\n\n\nval lemma_shuffle_core_properties (t:counter) (block:block_w) (hash_orig:hash256) : Lemma\n (requires t < size_k_w_256)\n (ensures (let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in\n let h = Spec.Loops.repeat_range 0 (t + 1) (shuffle_core_opaque block) hash_orig in\n let a0 = word_to_nat32 hash.[0] in\n let b0 = word_to_nat32 hash.[1] in\n let c0 = word_to_nat32 hash.[2] in\n let d0 = word_to_nat32 hash.[3] in\n let e0 = word_to_nat32 hash.[4] in\n let f0 = word_to_nat32 hash.[5] in\n let g0 = word_to_nat32 hash.[6] in\n let h0 = word_to_nat32 hash.[7] in\n let t1 = add_wrap (add_wrap (add_wrap (add_wrap h0 (sigma256_1_1 e0)) (ch_256 e0 f0 g0)) (word_to_nat32 k.[t])) (ws_opaque block t) in\n let t2 = add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0) in\n word_to_nat32 h.[0] == add_wrap t1 t2 /\\\n word_to_nat32 h.[1] == a0 /\\\n word_to_nat32 h.[2] == b0 /\\\n word_to_nat32 h.[3] == c0 /\\\n word_to_nat32 h.[4] == add_wrap d0 t1 /\\\n word_to_nat32 h.[5] == e0 /\\\n word_to_nat32 h.[6] == f0 /\\\n word_to_nat32 h.[7] == g0))\n\nval lemma_ws_opaque (block:block_w) (t:counter) : Lemma\n (requires 16 <= t && t < size_k_w_256)\n (ensures (let sigma0 = sigma256_0_0 (ws_opaque block (t - 15)) in\n let sigma1 = sigma256_0_1 (ws_opaque block (t - 2)) in\n ws_opaque block t == add_wrap (add_wrap (add_wrap sigma1 (ws_opaque block (t - 7))) sigma0) (ws_opaque block (t - 16))))\n\nlet repeat_range_vale_64 (block:block_w) (hash:hash256) =\n Spec.Loops.repeat_range 0 64 (shuffle_core_opaque block) hash\n\nval update_lemma (a b c d e f g h a_old b_old c_old d_old e_old f_old g_old h_old a' b' c' d' e' f' g' h':quad32) (block:block_w) : Lemma\n (requires (let hash_orig = make_seperated_hash_quad32 a_old b_old c_old d_old e_old f_old g_old h_old in\n make_seperated_hash_quad32 a b c d e f g h ==\n repeat_range_vale_64 block hash_orig /\\\n a' == add_wrap_quad32 a a_old /\\\n b' == add_wrap_quad32 b b_old /\\\n c' == add_wrap_quad32 c c_old /\\\n d' == add_wrap_quad32 d d_old /\\\n e' == add_wrap_quad32 e e_old /\\\n f' == add_wrap_quad32 f f_old /\\\n g' == add_wrap_quad32 g g_old /\\\n h' == add_wrap_quad32 h h_old))\n (ensures (let hash_orig = make_seperated_hash_quad32 a_old b_old c_old d_old e_old f_old g_old h_old in\n make_seperated_hash_quad32 a' b' c' d' e' f' g' h' == update_block hash_orig block))\n\nlet rec update_multi_quads (s:seq quad32) (hash_orig:hash256) : Tot (hash256) (decreases (length s))\n =\n if length s < 4 then\n hash_orig\n else\n let prefix, qs = split s (length s - 4) in\n let h_prefix = update_multi_quads prefix hash_orig in\n let hash = update_block h_prefix (quads_to_block_be qs) in\n hash\n\nval lemma_update_multi_quads (s:seq quad32) (hash_orig:hash256) (bound:nat) : Lemma\n (requires bound + 4 <= length s)\n (ensures (let prefix_LE = slice s 0 bound in\n let prefix_BE = reverse_bytes_quad32_seq prefix_LE in\n let h_prefix = update_multi_quads prefix_BE hash_orig in\n let block_quads_LE = slice s bound (bound + 4) in\n let block_quads_BE = reverse_bytes_quad32_seq block_quads_LE in\n let input_LE = slice s 0 (bound+4) in\n let input_BE = reverse_bytes_quad32_seq input_LE in\n let h = update_block h_prefix (quads_to_block_be block_quads_BE) in\n h == update_multi_quads input_BE hash_orig))\n\nPartial implementation:\nlet le_bytes_to_hash (b: seq nat8) : hash256 =\n \n"
},
{
"role": "assistant",
"content": "if length b <> 32\nthen\n (let f (n: nat{n < 8}) : word = nat32_to_word 0 in\n init 8 f)\nelse\n (let open Vale.Def.Words.Seq_s in\n Vale.Lib.Seqs_s.seq_map nat32_to_word (seq_nat8_to_seq_nat32_LE b))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n u166: FStar.Stubs.Reflection.Types.universe ->\n a: FStar.Stubs.Reflection.Types.term ->\n p: FStar.Stubs.Reflection.Types.term ->\n x: FStar.Stubs.Reflection.V2.Data.var\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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nPartial implementation:\nlet elim_exists_post_body (u: universe) (a p: term) (x: var) =\n \n"
},
{
"role": "assistant",
"content": "let x_tm = RT.var_as_term x in\nlet reveal_x = mk_reveal u a x_tm in\nlet post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\nRT.subst_term post [RT.ND x 0]"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n u90: FStar.Stubs.Reflection.Types.universe ->\n a: FStar.Stubs.Reflection.Types.term ->\n e: FStar.Stubs.Reflection.Types.term ->\n p: FStar.Stubs.Reflection.Types.term ->\n x: FStar.Stubs.Reflection.V2.Data.var\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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nPartial implementation:\nlet return_stt_ghost_comp (u: universe) (a e p: term) (x: var) : term =\n \n"
},
{
"role": "assistant",
"content": "mk_stt_ghost_comp u a (pack_ln (Tv_App p (e, Q_Explicit))) (return_post_with_eq u a e p x)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.AsLowStar.ValeSig.vale_post Vale.Inline.X64.Fswap_inline.cswap_dom\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\nPartial implementation:\nlet cswap_post:VSig.vale_post cswap_dom =\n \n"
},
{
"role": "assistant",
"content": "fun\n (c: V.va_code)\n (bit: uint64)\n (p0: b64)\n (p1: b64)\n (va_s0: V.va_state)\n (va_s1: V.va_state)\n (f: V.va_fuel)\n ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.X64.arity_ok 3 Vale.Interop.Base.td\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\nPartial implementation:\nlet cswap_dom:IX64.arity_ok 3 td =\n \n"
},
{
"role": "assistant",
"content": "let y = [tuint64; t64_mod; t64_mod] in\nassert_norm (List.length y = 3);\ny"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n pre: FStar.Stubs.Reflection.Types.term ->\n a: FStar.Stubs.Reflection.Types.term ->\n x: FStar.Stubs.Reflection.Types.term ->\n init: 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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nlet elim_exists_post_body (u:universe) (a:term) (p:term) (x:var) =\n let x_tm = RT.var_as_term x in\n let reveal_x = mk_reveal u a x_tm in\n let post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\n RT.subst_term post [ RT.ND x 0 ]\n\nlet elim_exists_post (u:universe) (a:term) (p:term) (x:var) =\n let erased_a = mk_erased u a in\n mk_abs erased_a Q_Explicit (elim_exists_post_body u a p x)\n\nval elim_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n : GTot (RT.tot_typing g\n (mk_elim_exists u a p)\n (mk_stt_ghost_comp\n u\n (mk_erased u a)\n (mk_exists u a p)\n (elim_exists_post u a p x)))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n g |- e : vprop\n -------------------------------------------------------------------------\n g |- intro_exists<u> #a p e : stt_ghost<0> unit empty (p e) (fun _ -> exists_ p)\n\n*)\nval intro_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#e:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n (e_typing:RT.ghost_typing g e a)\n : GTot (RT.tot_typing g\n (mk_intro_exists u a p e)\n (mk_stt_ghost_comp uzero unit_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists u a p))))\n\n(*\n\n g |- a : Type u\n g |- p : vprop\n g |- q : a -> vprop\n ------------------------------------------\n g |- stt_admit a p q : stt a p q\n\n*)\n\nval stt_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_admit u a p q)\n (mk_stt_comp u a p q))\n \nval stt_atomic_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_admit u a p q)\n (mk_stt_atomic_comp neutral_fv u a emp_inames_tm p q))\n\nval stt_ghost_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_admit u a p q)\n (mk_stt_ghost_comp u a p q))\n\nval rewrite_typing\n (#g:env)\n (#p:term)\n (#q:term)\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q vprop_tm)\n (equiv:RT.tot_typing g (`()) (stt_vprop_equiv p q))\n\n\t\t: GTot (RT.tot_typing g\n (mk_rewrite p q)\n (mk_stt_ghost_comp\n uzero\n unit_tm\n p\n (mk_abs unit_tm Q_Explicit q)))\n\nPartial implementation:\nlet with_local_body_pre (pre a x init: term) : term =\n \n"
},
{
"role": "assistant",
"content": "let pts_to:term = mk_pts_to a x full_perm_tm init in\nmk_star pre pts_to"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit -> FStar.All.ML Prims.int\nEffect: FStar.All.ML\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet cswap_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true\n else false\n\nlet cswap_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet cswap_lemma'\n (code:V.va_code)\n (_win:bool)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n cswap_pre code bit p0 p1 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 cswap_regs_modified cswap_xmms_modified /\\\n cswap_post code bit p0 p1 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p0) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p1) /\\\n ME.buffer_writeable (as_vale_buffer p0) /\\\n ME.buffer_writeable (as_vale_buffer p1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer p0))\n (ME.loc_union (ME.loc_buffer (as_vale_buffer p1))\n ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Cswap2 code va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p0;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p1;\n (va_s1, f)\n\n(* Prove that cswap_lemma' has the required type *)\nlet cswap_lemma = as_t #(VSig.vale_sig cswap_regs_modified cswap_xmms_modified cswap_pre cswap_post) cswap_lemma'\n\nlet code_cswap = FU.va_code_Cswap2 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the cswap wrapper *)\n[@__reduce__]\nlet lowstar_cswap_t =\n assert_norm (List.length cswap_dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n cswap_regs_modified\n cswap_xmms_modified\n code_cswap\n cswap_dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_cswap cswap_dom [] (cswap_lemma code_cswap IA.win))\n\n(* And here's the cswap wrapper itself *)\nlet lowstar_cswap : lowstar_cswap_t =\n assert_norm (List.length cswap_dom + List.length ([]<:list arg) <= 3);\n IX64.wrap_weak\n 3\n arg_reg\n cswap_regs_modified\n cswap_xmms_modified\n code_cswap\n cswap_dom\n (W.mk_prediction code_cswap cswap_dom [] (cswap_lemma code_cswap IA.win))\n\nlet lowstar_cswap_normal_t : normal lowstar_cswap_t\n = as_normal_t #lowstar_cswap_t lowstar_cswap\n\nopen Vale.AsLowStar.MemoryHelpers\n\nlet cswap2 bit p0 p1\n = DV.length_eq (get_downview p0);\n DV.length_eq (get_downview p1);\n let (x, _) = lowstar_cswap_normal_t bit p0 p1 () in\n ()\n\nlet cswap_comments : list string = \n [\"Computes p1 <- bit ? p2 : p1 in constant time\"]\n\nlet cswap_names (n:nat) : string =\n match n with\n | 0 -> \"bit\"\n | 1 -> \"p1\"\n | 2 -> \"p2\"\n | _ -> \"\"\n\nPartial implementation:\nlet cswap2_code_inline () : FStar.All.ML int =\n \n"
},
{
"role": "assistant",
"content": "PR.print_inline \"cswap2\" 0 None (List.length cswap_dom) cswap_dom cswap_names code_cswap of_arg\n cswap_regs_modified cswap_comments"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n post: FStar.Stubs.Reflection.Types.term ->\n a: FStar.Stubs.Reflection.Types.term ->\n arr: 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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nlet elim_exists_post_body (u:universe) (a:term) (p:term) (x:var) =\n let x_tm = RT.var_as_term x in\n let reveal_x = mk_reveal u a x_tm in\n let post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\n RT.subst_term post [ RT.ND x 0 ]\n\nlet elim_exists_post (u:universe) (a:term) (p:term) (x:var) =\n let erased_a = mk_erased u a in\n mk_abs erased_a Q_Explicit (elim_exists_post_body u a p x)\n\nval elim_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n : GTot (RT.tot_typing g\n (mk_elim_exists u a p)\n (mk_stt_ghost_comp\n u\n (mk_erased u a)\n (mk_exists u a p)\n (elim_exists_post u a p x)))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n g |- e : vprop\n -------------------------------------------------------------------------\n g |- intro_exists<u> #a p e : stt_ghost<0> unit empty (p e) (fun _ -> exists_ p)\n\n*)\nval intro_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#e:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n (e_typing:RT.ghost_typing g e a)\n : GTot (RT.tot_typing g\n (mk_intro_exists u a p e)\n (mk_stt_ghost_comp uzero unit_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists u a p))))\n\n(*\n\n g |- a : Type u\n g |- p : vprop\n g |- q : a -> vprop\n ------------------------------------------\n g |- stt_admit a p q : stt a p q\n\n*)\n\nval stt_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_admit u a p q)\n (mk_stt_comp u a p q))\n \nval stt_atomic_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_admit u a p q)\n (mk_stt_atomic_comp neutral_fv u a emp_inames_tm p q))\n\nval stt_ghost_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_admit u a p q)\n (mk_stt_ghost_comp u a p q))\n\nval rewrite_typing\n (#g:env)\n (#p:term)\n (#q:term)\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q vprop_tm)\n (equiv:RT.tot_typing g (`()) (stt_vprop_equiv p q))\n\n\t\t: GTot (RT.tot_typing g\n (mk_rewrite p q)\n (mk_stt_ghost_comp\n uzero\n unit_tm\n p\n (mk_abs unit_tm Q_Explicit q)))\n\n// mk_star pre (mk_pts_to a (RT.bound_var 0) full_perm_tm init\nlet with_local_body_pre (pre:term) (a:term) (x:term) (init:term) : term =\n let pts_to : term =\n mk_pts_to a x full_perm_tm init in\n mk_star pre pts_to\n\n//\n// post has 0 db index free\n//\nlet with_local_body_post_body (post:term) (a:term) (x:term) : term =\n // exists_ (R.pts_to r full_perm)\n let exists_tm =\n mk_exists (pack_universe Uv_Zero) a\n (mk_abs a Q_Explicit\n (mk_pts_to a x full_perm_tm (RT.bound_var 0))) in\n mk_star post exists_tm\n\nlet with_local_body_post (post:term) (a:term) (ret_t:term) (x:term) : term =\n mk_abs ret_t Q_Explicit (with_local_body_post_body post a x)\n\nval with_local_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#init:term)\n (#pre:term)\n (#ret_t:term)\n (#post:term) // post has db 0 free\n (#body:term) // body has x free\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type (pack_universe Uv_Zero))))\n (init_typing:RT.tot_typing g init a)\n (pre_typing:RT.tot_typing g pre vprop_tm)\n (ret_t_typing:RT.tot_typing g ret_t (pack_ln (Tv_Type u)))\n (post_typing:RT.tot_typing g (RT.mk_abs ret_t Q_Explicit post)\n (mk_arrow (ret_t, Q_Explicit) vprop_tm))\n (body_typing:RT.tot_typing (RT.extend_env g x (mk_ref a)) \n body\n (mk_stt_comp u ret_t\n (with_local_body_pre pre a (RT.var_as_term x) init)\n (with_local_body_post post a ret_t (RT.var_as_term x))))\n\n : GTot (RT.tot_typing g (mk_withlocal u a init pre ret_t (RT.mk_abs ret_t Q_Explicit post)\n (RT.mk_abs (mk_ref a) Q_Explicit (RT.close_term body x)))\n (mk_stt_comp u ret_t pre (mk_abs ret_t Q_Explicit post)))\n\nlet with_localarray_body_pre (pre:term) (a:term) (arr:term) (init:term) (len:term) : term =\n let pts_to : term =\n mk_array_pts_to a arr full_perm_tm (mk_seq_create uzero a (mk_szv len) init) in\n let len_vp : term =\n mk_pure (mk_eq2 uzero nat_tm (mk_array_length a arr) (mk_szv len)) in\n mk_star pre (mk_star pts_to len_vp)\n\n//\n// post has 0 db index free\n\nPartial implementation:\nlet with_localarray_body_post_body (post a arr: term) : term =\n \n"
},
{
"role": "assistant",
"content": "let exists_tm =\n mk_exists uzero\n (mk_seq uzero a)\n (mk_abs (mk_seq uzero a) Q_Explicit (mk_array_pts_to a arr full_perm_tm (RT.bound_var 0)))\nin\nmk_star post exists_tm"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n post: FStar.Stubs.Reflection.Types.term ->\n a: FStar.Stubs.Reflection.Types.term ->\n x: 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.Steel.Wrapper.Typing\n\nopen FStar.Reflection.V2\nopen Pulse.Reflection.Util\n\nmodule RT = FStar.Reflection.Typing\n\nlet return_post_with_eq (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let eq2_tm = mk_eq2 u a x_tm e in\n let p_app_x = pack_ln (Tv_App p (x_tm, Q_Explicit)) in \n let star_tm = mk_star p_app_x (mk_pure eq2_tm) in\n mk_abs a Q_Explicit (RT.subst_term star_tm [ RT.ND x 0 ])\n\nlet return_stt_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return u a e p)\n (return_stt_comp u a e p x))\n\nlet return_stt_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_return_noeq u a x p)\n (return_stt_noeq_comp u a x p))\n\nlet neutral_fv = pack_ln (Tv_FVar (pack_fv neutral_lid))\nlet return_stt_atomic_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_atomic_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.tot_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return u a e p)\n (return_stt_atomic_comp u a e p x))\n\nlet return_stt_atomic_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_atomic_comp neutral_fv u a emp_inames_tm (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_atomic_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.tot_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_return_noeq u a x p)\n (return_stt_atomic_noeq_comp u a x p))\n\nlet return_stt_ghost_comp (u:universe) (a:term) (e:term) (p:term) (x:var) : term =\n mk_stt_ghost_comp u a\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (return_post_with_eq u a e p x)\n\nval return_stt_ghost_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#e:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (e_typing:RT.ghost_typing g e a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return u a e p)\n (return_stt_ghost_comp u a e p x))\n\nlet return_stt_ghost_noeq_comp (u:universe) (a:term) (x:term) (p:term) : term =\n mk_stt_ghost_comp u a (pack_ln (Tv_App p (x, Q_Explicit))) p\n\nval return_stt_ghost_noeq_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#x:term)\n (#p:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (x_typing:RT.ghost_typing g x a)\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_return_noeq u a x p)\n (return_stt_ghost_noeq_comp u a x p))\n\n\n(*\n\n g |- inv : bool -> vprop\n g |- cond : stt<0> bool (exists_ inv) inv\n g |- body : stt<0> unit (inv true) (fun _ -> exists_ inv)\n -------------------------------------------------------------------------\n g |- while inv cond body : stt<0> unit (exists_ inv) (fun _ -> inv false)\n\n*)\n\nval while_typing\n (#g:env)\n (#inv:term)\n (#cond:term)\n (#body:term)\n (inv_typing:RT.tot_typing g\n inv\n (mk_arrow (bool_tm, Q_Explicit) vprop_tm))\n (cond_typing:RT.tot_typing g\n cond\n (mk_stt_comp uzero bool_tm (mk_exists uzero bool_tm inv) inv))\n (body_typing:RT.tot_typing g\n body\n (mk_stt_comp uzero unit_tm\n (pack_ln (Tv_App inv (true_tm, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists uzero bool_tm inv))))\n : RT.tot_typing g\n (mk_while inv cond body)\n (mk_stt_comp uzero unit_tm (mk_exists uzero bool_tm inv)\n (mk_abs unit_tm Q_Explicit (pack_ln (Tv_App inv (false_tm, Q_Explicit)))))\n\nlet par_post (u:universe) (aL aR:term) (postL postR:term) (x:var) : term =\n let x_tm = RT.var_as_term x in\n let postL = pack_ln (Tv_App postL (mk_fst u u aL aR x_tm, Q_Explicit)) in\n let postR = pack_ln (Tv_App postR (mk_snd u u aL aR x_tm, Q_Explicit)) in\n let post = mk_star postL postR in\n RT.subst_term post [ RT.ND x 0 ]\n\nval par_typing\n (#g:env)\n (#u:universe)\n (#aL #aR:term)\n (#preL #postL:term)\n (#preR #postR:term)\n (#eL #eR:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (aL_typing:RT.tot_typing g aL (pack_ln (Tv_Type u)))\n (aR_typing:RT.tot_typing g aR (pack_ln (Tv_Type u)))\n (preL_typing:RT.tot_typing g preL vprop_tm)\n (postL_typing:RT.tot_typing g postL (mk_arrow (aL, Q_Explicit) vprop_tm))\n (preR_typing:RT.tot_typing g preR vprop_tm)\n (postR_typing:RT.tot_typing g postR (mk_arrow (aR, Q_Explicit) vprop_tm))\n (eL_typing:RT.tot_typing g eL (mk_stt_comp u aL preL postL))\n (eR_typing:RT.tot_typing g eR (mk_stt_comp u aR preR postR))\n\n : GTot (RT.tot_typing g\n (mk_par u aL aR preL postL preR postR eL eR)\n (mk_stt_comp u (mk_tuple2 u u aL aR)\n (mk_star preL preR)\n (mk_abs (mk_tuple2 u u aL aR) Q_Explicit (par_post u aL aR postL postR x))))\n\nval exists_inversion\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (e_typing:RT.tot_typing g\n (mk_exists u a p)\n vprop_tm)\n : GTot (RT.tot_typing g\n p\n (mk_arrow (a, Q_Explicit) vprop_tm))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n ----------------------------------------------------------------\n g |- elim_exists<u> #a p : stt_ghost<u> a empty (exists_<u> p) (fun x -> p (reveal x))\n\n*)\n\nlet elim_exists_post_body (u:universe) (a:term) (p:term) (x:var) =\n let x_tm = RT.var_as_term x in\n let reveal_x = mk_reveal u a x_tm in\n let post = pack_ln (Tv_App p (reveal_x, Q_Explicit)) in\n RT.subst_term post [ RT.ND x 0 ]\n\nlet elim_exists_post (u:universe) (a:term) (p:term) (x:var) =\n let erased_a = mk_erased u a in\n mk_abs erased_a Q_Explicit (elim_exists_post_body u a p x)\n\nval elim_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (x:var{None? (RT.lookup_bvar g x)})\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n : GTot (RT.tot_typing g\n (mk_elim_exists u a p)\n (mk_stt_ghost_comp\n u\n (mk_erased u a)\n (mk_exists u a p)\n (elim_exists_post u a p x)))\n\n(*\n\n g |- a : Type u\n g |- p : a -> vprop\n g |- e : vprop\n -------------------------------------------------------------------------\n g |- intro_exists<u> #a p e : stt_ghost<0> unit empty (p e) (fun _ -> exists_ p)\n\n*)\nval intro_exists_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#e:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p (mk_arrow (a, Q_Explicit) vprop_tm))\n (e_typing:RT.ghost_typing g e a)\n : GTot (RT.tot_typing g\n (mk_intro_exists u a p e)\n (mk_stt_ghost_comp uzero unit_tm\n (pack_ln (Tv_App p (e, Q_Explicit)))\n (mk_abs unit_tm Q_Explicit (mk_exists u a p))))\n\n(*\n\n g |- a : Type u\n g |- p : vprop\n g |- q : a -> vprop\n ------------------------------------------\n g |- stt_admit a p q : stt a p q\n\n*)\n\nval stt_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_admit u a p q)\n (mk_stt_comp u a p q))\n \nval stt_atomic_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_atomic_admit u a p q)\n (mk_stt_atomic_comp neutral_fv u a emp_inames_tm p q))\n\nval stt_ghost_admit_typing\n (#g:env)\n (#u:universe)\n (#a:term)\n (#p:term)\n (#q:term)\n (a_typing:RT.tot_typing g a (pack_ln (Tv_Type u)))\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q (mk_arrow (a, Q_Explicit) vprop_tm))\n\n : GTot (RT.tot_typing g\n (mk_stt_ghost_admit u a p q)\n (mk_stt_ghost_comp u a p q))\n\nval rewrite_typing\n (#g:env)\n (#p:term)\n (#q:term)\n (p_typing:RT.tot_typing g p vprop_tm)\n (q_typing:RT.tot_typing g q vprop_tm)\n (equiv:RT.tot_typing g (`()) (stt_vprop_equiv p q))\n\n\t\t: GTot (RT.tot_typing g\n (mk_rewrite p q)\n (mk_stt_ghost_comp\n uzero\n unit_tm\n p\n (mk_abs unit_tm Q_Explicit q)))\n\n// mk_star pre (mk_pts_to a (RT.bound_var 0) full_perm_tm init\nlet with_local_body_pre (pre:term) (a:term) (x:term) (init:term) : term =\n let pts_to : term =\n mk_pts_to a x full_perm_tm init in\n mk_star pre pts_to\n\n//\n// post has 0 db index free\n\nPartial implementation:\nlet with_local_body_post_body (post a x: term) : term =\n \n"
},
{
"role": "assistant",
"content": "let exists_tm =\n mk_exists (pack_universe Uv_Zero)\n a\n (mk_abs a Q_Explicit (mk_pts_to a x full_perm_tm (RT.bound_var 0)))\nin\nmk_star post exists_tm"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.AsLowStar.ValeSig.vale_pre Vale.Inline.X64.Fswap_inline.cswap_dom\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n\nPartial implementation:\nlet cswap_pre:VSig.vale_pre cswap_dom =\n \n"
},
{
"role": "assistant",
"content": "fun (c: V.va_code) (bit: uint64) (p0: b64) (p1: b64) (va_s0: V.va_state) ->\n FU.va_req_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Inline.X64.Fswap_inline.lowstar_cswap_t\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet cswap_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true\n else false\n\nlet cswap_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet cswap_lemma'\n (code:V.va_code)\n (_win:bool)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n cswap_pre code bit p0 p1 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 cswap_regs_modified cswap_xmms_modified /\\\n cswap_post code bit p0 p1 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p0) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p1) /\\\n ME.buffer_writeable (as_vale_buffer p0) /\\\n ME.buffer_writeable (as_vale_buffer p1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer p0))\n (ME.loc_union (ME.loc_buffer (as_vale_buffer p1))\n ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Cswap2 code va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p0;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p1;\n (va_s1, f)\n\n(* Prove that cswap_lemma' has the required type *)\nlet cswap_lemma = as_t #(VSig.vale_sig cswap_regs_modified cswap_xmms_modified cswap_pre cswap_post) cswap_lemma'\n\nlet code_cswap = FU.va_code_Cswap2 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the cswap wrapper *)\n[@__reduce__]\nlet lowstar_cswap_t =\n assert_norm (List.length cswap_dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n cswap_regs_modified\n cswap_xmms_modified\n code_cswap\n cswap_dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_cswap cswap_dom [] (cswap_lemma code_cswap IA.win))\n\nPartial implementation:\nlet lowstar_cswap:lowstar_cswap_t =\n \n"
},
{
"role": "assistant",
"content": "assert_norm (List.length cswap_dom + List.length ([] <: list arg) <= 3);\nIX64.wrap_weak 3\n arg_reg\n cswap_regs_modified\n cswap_xmms_modified\n code_cswap\n cswap_dom\n (W.mk_prediction code_cswap cswap_dom [] (cswap_lemma code_cswap IA.win))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: v:\nVale.Interop.X64.arg_reg_relation' 3\n { forall (r: Vale.X64.Machine_s.reg_64). {:pattern Rel?.of_reg v r}\n Some? (Rel?.of_reg v r) ==> Rel?.of_arg v (Some?.v (Rel?.of_reg v r)) = r }\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet cswap_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true\n else false\n\nlet cswap_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet cswap_lemma'\n (code:V.va_code)\n (_win:bool)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n cswap_pre code bit p0 p1 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 cswap_regs_modified cswap_xmms_modified /\\\n cswap_post code bit p0 p1 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p0) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p1) /\\\n ME.buffer_writeable (as_vale_buffer p0) /\\\n ME.buffer_writeable (as_vale_buffer p1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer p0))\n (ME.loc_union (ME.loc_buffer (as_vale_buffer p1))\n ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Cswap2 code va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p0;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p1;\n (va_s1, f)\n\n(* Prove that cswap_lemma' has the required type *)\nlet cswap_lemma = as_t #(VSig.vale_sig cswap_regs_modified cswap_xmms_modified cswap_pre cswap_post) cswap_lemma'\n\nlet code_cswap = FU.va_code_Cswap2 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nPartial implementation:\nlet arg_reg:IX64.arg_reg_relation 3 =\n \n"
},
{
"role": "assistant",
"content": "IX64.Rel of_reg of_arg"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.int\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\n\nPartial implementation:\nlet bn_exp_mont_vartime_threshold =\n \n"
},
{
"role": "assistant",
"content": "200"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: f: FStar.Seq.Properties.tot_ord a -> x: FStar.Array.array a -> FStar.ST.ST Prims.unit\nEffect: FStar.ST.ST\n\nContext:\n(*\n Copyright 2008-2014 Nikhil Swamy and 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 QuickSort.Array\nopen FStar.Array\nopen FStar.Seq\nopen FStar.Heap\nopen FStar.ST\n#set-options \"--initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\n\n(* 2016-11-22: Due to the QuickSort namespace being opened *after* the\nFStar namespace,Array resolves to QuickSort.Array instead of\nFStar.Array, so we have to fix this explicitly as a module abbrev. *)\nmodule Array = FStar.Array\nmodule Seq = FStar.Seq\n\ntype partition_inv (a:eqtype) (f:tot_ord a) (lo:seq a) (pv:a) (hi:seq a) =\n ((length hi) >= 0)\n /\\ (forall y. (mem y hi ==> f pv y) /\\ (mem y lo ==> f y pv))\n\ntype partition_pre (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h:heap) =\n (Array.contains h x\n /\\ ((let s = Array.sel h x in (len <= length s) /\\ (partition_inv a f\n (slice s start pivot)\n (index s pivot)\n (slice s (back + 1) len)))\n ))\n\ntype partition_post (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h0:heap) (i:nat) (h1:heap) =\n (len <= length (Array.sel h0 x)\n /\\ Array.contains h1 x\n /\\ start <= i\n /\\ i < len\n /\\ (length (Array.sel h1 x) = length (Array.sel h0 x))\n /\\ (Array.sel h1 x == splice (Array.sel h0 x) start (Array.sel h1 x) len)\n /\\ (permutation a (slice (Array.sel h0 x) start len) (slice (Array.sel h1 x) start len))\n /\\ (partition_inv a f\n (slice (Array.sel h1 x) start i)\n (index (Array.sel h1 x) i)\n (slice (Array.sel h1 x) i len)))\n\n#reset-options \"--z3rlimit 20 --initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\nval partition: #a:eqtype -> f:tot_ord a\n -> start:nat -> len:nat{start <= len}\n -> pivot:nat{start <= pivot /\\ pivot < len}\n -> back:nat{pivot <= back /\\ back < len}\n -> x:array a -> ST nat\n (requires (partition_pre a f start len pivot back x))\n (ensures (fun h0 n h1 -> partition_post a f start len pivot back x h0 n h1 /\\ modifies (Array.only x) h0 h1))\nlet rec partition #a f start len pivot back x =\n let h0 = get() in\n if pivot = back\n then\n begin\n(*ghost*) (let s = Array.sel h0 x in\n(*ghost*) lemma_slice_cons s pivot len;\n(*ghost*) splice_refl s start len);\n pivot\n end\n else\n begin\n let next = Array.index x (pivot + 1) in\n let p = Array.index x pivot in\n if f next p\n then\n begin\n Array.swap x pivot (pivot + 1); (* the pivot moves forward *)\n let h1 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) swap_frame_lo s start pivot (pivot + 1);\n(* ghost *) swap_frame_hi s pivot (pivot + 1) (back + 1) len;\n assume (pivot < length s');\n //lemma_swap_splice s start (pivot + 1) back len;\n (* need pivot < length s',\n but only have pivot < length s *)\n(* ghost *) lemma_ordering_lo_snoc f s' start pivot p in\n let res = partition f start len (pivot + 1) back x in\n\t let h2 = get () in\n let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n else\n begin\n Array.swap x (pivot + 1) back; (* the back moves backward *)\n\t let h1 = get () in\n// (* ghost *) let s = Array.sel h0 x in\n// (* ghost *) let s' = Array.sel h1 x in\n// (* ghost *) swap_frame_lo' s start pivot (pivot + 1) back;\n// (* ghost *) swap_frame_hi s (pivot + 1) back (back + 1) len;\n// (* ghost *) lemma_ordering_hi_cons f s' back len p in\n let res = partition f start len pivot (back - 1) x in\n\t let h2 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n end\n#reset-options\n\nval lemma_slice_cons_pv: #a:Type -> s:seq a -> i:nat -> pivot:nat{i <= pivot} -> j:nat{pivot < j && j <= length s} -> pv:a\n -> Lemma\n (requires (pv == index s pivot))\n (ensures (slice s i j == append (slice s i pivot) (cons pv (slice s (pivot + 1) j))))\nlet lemma_slice_cons_pv #a s i pivot j pv =\n let lo = slice s i pivot in\n let hi = slice s (pivot + 1) j in\n cut (Seq.equal (slice s i j) (append lo (cons pv hi)))\n\n#reset-options\n#set-options \"--initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0 --z3rlimit 50\"\nval sort: #a:eqtype -> f:tot_ord a -> i:nat -> j:nat{i <= j} -> x:array a\n -> ST unit\n (requires (fun h -> Array.contains h x /\\ j <= length (Array.sel h x)))\n (ensures (fun h0 u h1 -> (modifies (Array.only x) h0 h1\n /\\ j <= length (Array.sel h0 x) (* carrying this along from the requires clause *)\n /\\ Array.contains h1 x (* the array is still in the heap *)\n /\\ (length (Array.sel h0 x) = length (Array.sel h1 x)) (* its length has not changed *)\n /\\ sorted f (slice (Array.sel h1 x) i j) (* it is sorted between [i, j) *)\n /\\ (Array.sel h1 x == splice (Array.sel h0 x) i (Array.sel h1 x) j) (* the rest of it is unchanged *)\n /\\ permutation a (slice (Array.sel h0 x) i j) (slice (Array.sel h1 x) i j)))) (* the [i,j) sub-array is a permutation of the original one *)\nlet rec sort #a f i j x =\n let h0 = ST.get () in\n if i=j\n then splice_refl (Array.sel h0 x) i j\n else begin\n let pivot = partition f i j i (j - 1) x in\n\n(* ghost *) let h1 = get() in\n\n sort f i pivot x;\n\n(* ghost *) let h2 = get() in\n\t let _ =\n(* ghost *) lemma_seq_frame_hi (Array.sel h2 x) (Array.sel h1 x) i pivot pivot j;\n(* ghost *) lemma_tail_slice (Array.sel h2 x) pivot j in\n\n sort f (pivot + 1) j x;\n\n(* ghost *) let h3 = get() in\n(* ghost *) lemma_seq_frame_lo (Array.sel h3 x) (Array.sel h2 x) i pivot (pivot + 1) j;\n(* ghost *) let lo = slice (Array.sel h3 x) i pivot in\n(* ghost *) let hi = slice (Array.sel h3 x) (pivot + 1) j in\n(* ghost *) let pv = index (Array.sel h1 x) pivot in\n(* ghost *) Seq.sorted_concat_lemma f lo pv hi;\n(* ghost *) lemma_slice_cons_pv (Array.sel h3 x) i pivot j pv;\n\n(* ghost *) lemma_weaken_frame_right (Array.sel h2 x) (Array.sel h1 x) i pivot j;\n(* ghost *) lemma_weaken_frame_left (Array.sel h3 x) (Array.sel h2 x) i (pivot + 1) j;\n(* ghost *) lemma_trans_frame (Array.sel h3 x) (Array.sel h2 x) (Array.sel h1 x) i j;\n(* ghost *) lemma_trans_frame (Array.sel h3 x) (Array.sel h1 x) (Array.sel h0 x) i j;\n\n(* ghost *) lemma_weaken_perm_right (Array.sel h2 x) (Array.sel h1 x) i pivot j;\n(* ghost *) lemma_weaken_perm_left (Array.sel h3 x) (Array.sel h2 x) i (pivot + 1) j\n end\n\n\nval qsort: #a:eqtype -> f:tot_ord a -> x:array a -> ST unit\n (requires (fun h -> Array.contains h x))\n (ensures (fun h0 u h1 -> modifies (Array.only x) h0 h1\n\nPartial implementation:\nlet qsort #a f x =\n \n"
},
{
"role": "assistant",
"content": "let h0 = get () in\nlet len = Array.length x in\nsort f 0 len x;\nlet h1 = get () in\ncut (Seq.equal (Array.sel h0 x) (slice (Array.sel h0 x) 0 len));\ncut (Seq.equal (Array.sel h1 x) (slice (Array.sel h1 x) 0 len))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.int\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\nPartial implementation:\nlet bn_exp_mont_consttime_threshold =\n \n"
},
{
"role": "assistant",
"content": "200"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n s: FStar.Seq.Base.seq a ->\n i: Prims.nat ->\n pivot: Prims.nat{i <= pivot} ->\n j: Prims.nat{pivot < j && j <= FStar.Seq.Base.length s} ->\n pv: a\n -> FStar.Pervasives.Lemma (requires pv == FStar.Seq.Base.index s pivot)\n (ensures\n FStar.Seq.Base.slice s i j ==\n FStar.Seq.Base.append (FStar.Seq.Base.slice s i pivot)\n (FStar.Seq.Base.cons pv (FStar.Seq.Base.slice s (pivot + 1) j)))\nEffect: FStar.Pervasives.Lemma\n\nContext:\n(*\n Copyright 2008-2014 Nikhil Swamy and 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 QuickSort.Array\nopen FStar.Array\nopen FStar.Seq\nopen FStar.Heap\nopen FStar.ST\n#set-options \"--initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\n\n(* 2016-11-22: Due to the QuickSort namespace being opened *after* the\nFStar namespace,Array resolves to QuickSort.Array instead of\nFStar.Array, so we have to fix this explicitly as a module abbrev. *)\nmodule Array = FStar.Array\nmodule Seq = FStar.Seq\n\ntype partition_inv (a:eqtype) (f:tot_ord a) (lo:seq a) (pv:a) (hi:seq a) =\n ((length hi) >= 0)\n /\\ (forall y. (mem y hi ==> f pv y) /\\ (mem y lo ==> f y pv))\n\ntype partition_pre (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h:heap) =\n (Array.contains h x\n /\\ ((let s = Array.sel h x in (len <= length s) /\\ (partition_inv a f\n (slice s start pivot)\n (index s pivot)\n (slice s (back + 1) len)))\n ))\n\ntype partition_post (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h0:heap) (i:nat) (h1:heap) =\n (len <= length (Array.sel h0 x)\n /\\ Array.contains h1 x\n /\\ start <= i\n /\\ i < len\n /\\ (length (Array.sel h1 x) = length (Array.sel h0 x))\n /\\ (Array.sel h1 x == splice (Array.sel h0 x) start (Array.sel h1 x) len)\n /\\ (permutation a (slice (Array.sel h0 x) start len) (slice (Array.sel h1 x) start len))\n /\\ (partition_inv a f\n (slice (Array.sel h1 x) start i)\n (index (Array.sel h1 x) i)\n (slice (Array.sel h1 x) i len)))\n\n#reset-options \"--z3rlimit 20 --initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\nval partition: #a:eqtype -> f:tot_ord a\n -> start:nat -> len:nat{start <= len}\n -> pivot:nat{start <= pivot /\\ pivot < len}\n -> back:nat{pivot <= back /\\ back < len}\n -> x:array a -> ST nat\n (requires (partition_pre a f start len pivot back x))\n (ensures (fun h0 n h1 -> partition_post a f start len pivot back x h0 n h1 /\\ modifies (Array.only x) h0 h1))\nlet rec partition #a f start len pivot back x =\n let h0 = get() in\n if pivot = back\n then\n begin\n(*ghost*) (let s = Array.sel h0 x in\n(*ghost*) lemma_slice_cons s pivot len;\n(*ghost*) splice_refl s start len);\n pivot\n end\n else\n begin\n let next = Array.index x (pivot + 1) in\n let p = Array.index x pivot in\n if f next p\n then\n begin\n Array.swap x pivot (pivot + 1); (* the pivot moves forward *)\n let h1 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) swap_frame_lo s start pivot (pivot + 1);\n(* ghost *) swap_frame_hi s pivot (pivot + 1) (back + 1) len;\n assume (pivot < length s');\n //lemma_swap_splice s start (pivot + 1) back len;\n (* need pivot < length s',\n but only have pivot < length s *)\n(* ghost *) lemma_ordering_lo_snoc f s' start pivot p in\n let res = partition f start len (pivot + 1) back x in\n\t let h2 = get () in\n let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n else\n begin\n Array.swap x (pivot + 1) back; (* the back moves backward *)\n\t let h1 = get () in\n// (* ghost *) let s = Array.sel h0 x in\n// (* ghost *) let s' = Array.sel h1 x in\n// (* ghost *) swap_frame_lo' s start pivot (pivot + 1) back;\n// (* ghost *) swap_frame_hi s (pivot + 1) back (back + 1) len;\n// (* ghost *) lemma_ordering_hi_cons f s' back len p in\n let res = partition f start len pivot (back - 1) x in\n\t let h2 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n end\n#reset-options\n\nval lemma_slice_cons_pv: #a:Type -> s:seq a -> i:nat -> pivot:nat{i <= pivot} -> j:nat{pivot < j && j <= length s} -> pv:a\n -> Lemma\n (requires (pv == index s pivot))\n\nPartial implementation:\nlet lemma_slice_cons_pv #a s i pivot j pv =\n \n"
},
{
"role": "assistant",
"content": "let lo = slice s i pivot in\nlet hi = slice s (pivot + 1) j in\ncut (Seq.equal (slice s i j) (append lo (cons pv hi)))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Benton2004.exp 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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nPartial implementation:\nlet cond =\n \n"
},
{
"role": "assistant",
"content": "eop op_LessThan (evar i) (evar n)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.AsLowStar.ValeSig.vale_sig Vale.Inline.X64.Fswap_inline.cswap_regs_modified\n Vale.Inline.X64.Fswap_inline.cswap_xmms_modified\n Vale.Inline.X64.Fswap_inline.cswap_pre\n Vale.Inline.X64.Fswap_inline.cswap_post\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet cswap_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true\n else false\n\nlet cswap_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet cswap_lemma'\n (code:V.va_code)\n (_win:bool)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n cswap_pre code bit p0 p1 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 cswap_regs_modified cswap_xmms_modified /\\\n cswap_post code bit p0 p1 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p0) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p1) /\\\n ME.buffer_writeable (as_vale_buffer p0) /\\\n ME.buffer_writeable (as_vale_buffer p1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer p0))\n (ME.loc_union (ME.loc_buffer (as_vale_buffer p1))\n ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Cswap2 code va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p0;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p1;\n (va_s1, f)\n\nPartial implementation:\nlet cswap_lemma =\n \n"
},
{
"role": "assistant",
"content": "as_t #(VSig.vale_sig cswap_regs_modified cswap_xmms_modified cswap_pre cswap_post) cswap_lemma'"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Benton2004.exp Prims.int\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nPartial implementation:\nlet asx_e =\n \n"
},
{
"role": "assistant",
"content": "eop op_Addition (evar y) (const 1)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Benton2004.exp Prims.int\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nlet cond = eop op_LessThan (evar i) (evar n)\n\nPartial implementation:\nlet asi_e =\n \n"
},
{
"role": "assistant",
"content": "eop op_Addition (evar i) (evar x)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Benton2004.computation\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nlet cond = eop op_LessThan (evar i) (evar n)\nlet asx_e = eop op_Addition (evar y) (const 1)\n\nPartial implementation:\nlet l =\n \n"
},
{
"role": "assistant",
"content": "while cond (seq (assign x asx_e) (assign i asi_e))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Benton2004.computation\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nlet cond = eop op_LessThan (evar i) (evar n)\nlet asx_e = eop op_Addition (evar y) (const 1)\nlet asi_e = eop op_Addition (evar i) (evar x)\n\nPartial implementation:\nlet r =\n \n"
},
{
"role": "assistant",
"content": "seq (assign x asx_e) (while cond (assign i asi_e))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit -> Prims.GTot (Benton2004.RHL.gexp Prims.bool)\nEffect: Prims.GTot\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nlet cond = eop op_LessThan (evar i) (evar n)\nlet asx_e = eop op_Addition (evar y) (const 1)\nlet asi_e = eop op_Addition (evar i) (evar x)\nlet l = while cond (seq (assign x asx_e) (assign i asi_e))\nlet r = seq (assign x asx_e) (while cond (assign i asi_e))\n\nPartial implementation:\nlet phi () : GTot (gexp bool) =\n \n"
},
{
"role": "assistant",
"content": "gand (geq (gvar i Left) (gvar i Right))\n (gand (geq (gvar n Left) (gvar n Right)) (geq (gvar y Left) (gvar y Right)))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: n: Hacl.Spec.Bignum.Definitions.lbignum t len -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nPartial implementation:\nlet bn_mont_t (#t: limb_t) (#len: BN.bn_len t) (n: lbignum t len) =\n \n"
},
{
"role": "assistant",
"content": "x: lbignum t len {bn_v x < bn_v n}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: min: Prims.nat -> max: Prims.nat{min <= max} -> k: LowParse.Spec.Base.parser_kind\n -> LowParse.Spec.Base.parser_kind\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nPartial implementation:\nlet parse_deplen_payload_kind =\n \n"
},
{
"role": "assistant",
"content": "parse_bounded_vlgen_payload_kind"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n fact: Steel.Memory.property a ->\n r: Steel.GhostPCMReference.ref a pcm ->\n v: FStar.Ghost.erased a ->\n w: Steel.GhostPCMReference.witnessed r fact\n -> Steel.Effect.Atomic.SteelAtomicU (FStar.Ghost.erased a)\nEffect: Steel.Effect.Atomic.SteelAtomicU\n\nContext:\n(*\n Copyright 2020 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 Steel.GhostPCMReference\n(* A ghost variant of Steel.PCMReference *)\nopen FStar.PCM\nopen FStar.Ghost\n\nopen Steel.Memory\nopen Steel.Effect.Atomic\nopen Steel.Effect\nmodule Mem = Steel.Memory\nmodule P = Steel.PCMReference\n\nlet ref (a:Type) (p:pcm a) = erased (Steel.Memory.ref a p)\n\n/// Its selector is non-informative (it is unit)\n[@@__reduce__]\nlet pts_to (#a:Type u#1) (#pcm:pcm a) (r:ref a pcm) ([@@@smt_fallback]v:a)\n = to_vprop (Steel.Memory.pts_to r v)\n\nlet alloc (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (x:a)\n : SteelGhost\n (ref a pcm) o\n (emp)\n (fun r -> pts_to r x)\n (requires fun _ -> pcm.refine x)\n (ensures fun _ _ _ -> True)\n = rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp ());\n FStar.PCM.compatible_refl pcm x;\n let r = as_atomic_action_ghost (alloc_action o x) in\n r\n\nlet read (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (#v0:a)\n (r:ref a pcm)\n : SteelGhost a o\n (pts_to r v0)\n (fun _ -> pts_to r v0)\n (requires fun _ -> True)\n (ensures fun _ v _ -> compatible pcm v0 v)\n = let v = as_atomic_action_ghost (sel_action o r v0) in\n v\n\nlet write (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (r:ref a pcm)\n (v0:a)\n (v1:a)\n : SteelGhost unit o\n (pts_to r v0)\n (fun _ -> pts_to r v1)\n (requires fun _ -> frame_preserving pcm v0 v1 /\\ pcm.refine v1)\n (ensures fun _ _ _ -> True)\n = as_atomic_action_ghost (upd_action o r v0 v1)\n\nlet upd_gen (#o:inames)\n (#a:Type)\n (#p:pcm a)\n (r:ref a p)\n (x y:a)\n (f:frame_preserving_upd p x y)\n : SteelGhostT unit o\n (pts_to r x)\n (fun _ -> pts_to r y)\n = as_atomic_action_ghost (Steel.Memory.upd_gen o r x y f)\n\nlet share (#o:inames)\n (#a:Type)\n (#p:pcm a)\n (r:ref a p)\n (v:a)\n (v0:a)\n (v1:a)\n : SteelGhost unit o\n (pts_to r v)\n (fun _ -> pts_to r v0 `star` pts_to r v1)\n (requires fun _ ->\n composable p v0 v1 /\\\n v == op p v0 v1)\n (ensures fun _ _ _ -> True)\n = P.split r v v0 v1\n\nlet gather (#o:inames)\n (#a:Type)\n (#p:FStar.PCM.pcm a)\n (r:ref a p)\n (v0:a)\n (v1:a)\n : SteelGhostT (_:unit{composable p v0 v1}) o\n (pts_to r v0 `star` pts_to r v1)\n (fun _ -> pts_to r (op p v0 v1))\n = P.gather r v0 v1\n\nlet witnessed (#a:Type) (#p:pcm a) (r:ref a p) (fact:property a)\n : Type0\n = Steel.Memory.witnessed r fact\n\nlet witness (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (r:ref a pcm)\n (fact:Steel.Preorder.stable_property pcm)\n (v:erased a)\n (_:squash (Steel.Preorder.fact_valid_compat fact v))\n = P.witness r fact v ()\n\nPartial implementation:\nlet recall\n (#o: _)\n (#a: Type)\n (#pcm: pcm a)\n (fact: property a)\n (r: ref a pcm)\n (v: erased a)\n (w: witnessed r fact)\n =\n \n"
},
{
"role": "assistant",
"content": "P.recall fact r v w"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: t: Hacl.Spec.Bignum.Definitions.limb_t -> len: Hacl.Spec.Bignum.bn_len t -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\nPartial implementation:\nlet bn_exp_mont_st (t: limb_t) (len: BN.bn_len t) =\n \n"
},
{
"role": "assistant",
"content": "\n n: lbignum t len ->\n mu: limb t {BM.bn_mont_pre n mu} ->\n aM: bn_mont_t n ->\n bBits: size_nat ->\n b: lbignum t (blocks0 bBits (bits t)) {bn_v b < pow2 bBits}\n -> Pure (bn_mont_t n)\n (requires True)\n (ensures\n fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n n: Hacl.Spec.Bignum.Definitions.lbignum t len ->\n mu: Hacl.Spec.Bignum.Definitions.limb t {Hacl.Spec.Bignum.Montgomery.bn_mont_pre n mu}\n -> Spec.Exponentiation.one_st (Hacl.Spec.Bignum.MontExponentiation.bn_mont_t n)\n (Hacl.Spec.Bignum.MontExponentiation.mk_to_nat_mont_ll_comm_monoid n mu)\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nPartial implementation:\nlet bn_mont_one #t #len n mu _ =\n \n"
},
{
"role": "assistant",
"content": "BM.bn_precomp_r2_mod_n_lemma 0 n;\nlet r2 = BM.bn_precomp_r2_mod_n 0 n in\nBM.bn_mont_one_lemma n mu r2;\nBM.bn_mont_one n mu r2"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n n: Hacl.Spec.Bignum.Definitions.lbignum t len ->\n mu: Hacl.Spec.Bignum.Definitions.limb t {Hacl.Spec.Bignum.Montgomery.bn_mont_pre n mu}\n -> Spec.Exponentiation.sqr_st (Hacl.Spec.Bignum.MontExponentiation.bn_mont_t n)\n (Hacl.Spec.Bignum.MontExponentiation.mk_to_nat_mont_ll_comm_monoid n mu)\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nPartial implementation:\nlet bn_mont_sqr #t #len n mu aM =\n \n"
},
{
"role": "assistant",
"content": "BM.bn_mont_sqr_lemma n mu aM;\nBM.bn_mont_sqr n mu aM"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n n: Hacl.Spec.Bignum.Definitions.lbignum t len ->\n mu: Hacl.Spec.Bignum.Definitions.limb t {Hacl.Spec.Bignum.Montgomery.bn_mont_pre n mu}\n -> Spec.Exponentiation.mul_st (Hacl.Spec.Bignum.MontExponentiation.bn_mont_t n)\n (Hacl.Spec.Bignum.MontExponentiation.mk_to_nat_mont_ll_comm_monoid n mu)\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nPartial implementation:\nlet bn_mont_mul #t #len n mu aM bM =\n \n"
},
{
"role": "assistant",
"content": "BM.bn_mont_mul_lemma n mu aM bM;\nBM.bn_mont_mul n mu aM bM"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit -> Prims.squash (2 == 1 + 1)\nEffect: Prims.Tot\n\nContext:\nmodule CalcInference\n\nlet lem () : squash (2 == 1 + 1) = ()\n\nlet test1 () : squash (2 == 1 + 1) =\n calc (==) {\n 2;\n == { lem () }\n _;\n }\n\nPartial implementation:\nlet test2 () : squash (2 == 1 + 1) =\n \n"
},
{
"role": "assistant",
"content": "calc ( == ) {\n _;\n ( == ) { lem () }\n 1 + 1;\n}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n code: Vale.X64.Decls.va_code ->\n _win: Prims.bool ->\n bit: Vale.Inline.X64.Fswap_inline.uint64 ->\n p0: Vale.Inline.X64.Fswap_inline.b64 ->\n p1: Vale.Inline.X64.Fswap_inline.b64 ->\n va_s0: Vale.X64.Decls.va_state\n -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)\nEffect: Prims.Ghost\n\nContext:\nmodule Vale.Inline.X64.Fswap_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet cswap_dom: IX64.arity_ok 3 td =\n let y = [tuint64; t64_mod; t64_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet cswap_pre : VSig.vale_pre cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state) ->\n FU.va_req_Cswap2 c va_s0\n (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\n\n[@__reduce__]\nlet cswap_post : VSig.vale_post cswap_dom =\n fun (c:V.va_code)\n (bit:uint64)\n (p0:b64)\n (p1:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Cswap2 c va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet cswap_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRdi || r = rR8 || r = rR9 || r = rR10 then true\n else false\n\nlet cswap_xmms_modified = fun _ -> false\n\nPartial implementation:\nlet cswap_lemma' (code: V.va_code) (_win: bool) (bit: uint64) (p0 p1: b64) (va_s0: V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires cswap_pre code bit p0 p1 va_s0)\n (ensures\n (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 cswap_regs_modified cswap_xmms_modified /\\\n cswap_post code bit p0 p1 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p0) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer p1) /\\\n ME.buffer_writeable (as_vale_buffer p0) /\\ ME.buffer_writeable (as_vale_buffer p1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer p0))\n (ME.loc_union (ME.loc_buffer (as_vale_buffer p1)) ME.loc_none))\n (VS.vs_get_vale_heap va_s0)\n (VS.vs_get_vale_heap va_s1))) =\n \n"
},
{
"role": "assistant",
"content": "let va_s1, f =\n FU.va_lemma_Cswap2 code va_s0 (UInt64.v bit) (as_vale_buffer p0) (as_vale_buffer p1)\nin\nVale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p0;\nVale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 p1;\n(va_s1, f)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit -> Prims.squash (2 == 1 + 1)\nEffect: Prims.Tot\n\nContext:\nmodule CalcInference\n\nlet lem () : squash (2 == 1 + 1) = ()\n\nPartial implementation:\nlet test1 () : squash (2 == 1 + 1) =\n \n"
},
{
"role": "assistant",
"content": "calc ( == ) {\n 2;\n ( == ) { lem () }\n _;\n}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit -> Prims.squash (2 == 1 + 1)\nEffect: Prims.Tot\n\nContext:\nmodule CalcInference\n\nlet lem () : squash (2 == 1 + 1) = ()\n\nlet test1 () : squash (2 == 1 + 1) =\n calc (==) {\n 2;\n == { lem () }\n _;\n }\n\nlet test2 () : squash (2 == 1 + 1) =\n calc (==) {\n _;\n == { lem () }\n 1 + 1;\n }\n\nPartial implementation:\nlet test3 () : squash (2 == 1 + 1) =\n \n"
},
{
"role": "assistant",
"content": "calc ( == ) {\n _;\n ( == ) { lem () }\n _;\n}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\n\nnoextract\nlet bn_exp_mont_st (t:limb_t) (len:BN.bn_len t) =\n n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu}\n -> aM:bn_mont_t n\n -> bBits:size_nat\n -> b:lbignum t (blocks0 bBits (bits t)){bn_v b < pow2 bBits} ->\n Pure (bn_mont_t n)\n (requires True)\n (ensures fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))\n\n\n// no diff between vartime and consttime at the spec level\nval bn_exp_mont_bm_vartime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_vartime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_rl_lemma k1 aM bBits (bn_v b);\n LE.exp_rl_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_rl k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_bm_consttime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_consttime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_mont_ladder_swap_lemma k1 aM bBits (bn_v b);\n LE.exp_mont_ladder_swap_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n LE.exp_mont_ladder_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_mont_ladder_swap k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_fw:\n #t:limb_t\n -> #len:BN.bn_len t\n -> l:size_pos{l < bits t /\\ pow2 l * len <= max_size_t} ->\n bn_exp_mont_st t len\n\nlet bn_exp_mont_fw #t #len l n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_fw_lemma k1 aM bBits (bn_v b) l;\n LE.exp_fw_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b) l;\n SE.exp_fw k1 aM bBits (bn_v b) l\n\nPartial implementation:\nlet bn_exp_mont_vartime #t #len n mu aM bBits b =\n \n"
},
{
"role": "assistant",
"content": "if bBits < bn_exp_mont_vartime_threshold\nthen bn_exp_mont_bm_vartime n mu aM bBits b\nelse bn_exp_mont_fw 4 n mu aM bBits b"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\n\nnoextract\nlet bn_exp_mont_st (t:limb_t) (len:BN.bn_len t) =\n n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu}\n -> aM:bn_mont_t n\n -> bBits:size_nat\n -> b:lbignum t (blocks0 bBits (bits t)){bn_v b < pow2 bBits} ->\n Pure (bn_mont_t n)\n (requires True)\n (ensures fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))\n\n\n// no diff between vartime and consttime at the spec level\nval bn_exp_mont_bm_vartime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_vartime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_rl_lemma k1 aM bBits (bn_v b);\n LE.exp_rl_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_rl k1 aM bBits (bn_v b)\n\nPartial implementation:\nlet bn_exp_mont_bm_consttime #t #len n mu aM bBits b =\n \n"
},
{
"role": "assistant",
"content": "let k1 = mk_bn_mont_concrete_ops n mu in\nSE.exp_mont_ladder_swap_lemma k1 aM bBits (bn_v b);\nLE.exp_mont_ladder_swap_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\nLE.exp_mont_ladder_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\nSE.exp_mont_ladder_swap k1 aM bBits (bn_v b)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: l: Lib.IntTypes.size_pos{l < Lib.IntTypes.bits t /\\ Prims.pow2 l * len <= Lib.IntTypes.max_size_t}\n -> Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\n\nnoextract\nlet bn_exp_mont_st (t:limb_t) (len:BN.bn_len t) =\n n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu}\n -> aM:bn_mont_t n\n -> bBits:size_nat\n -> b:lbignum t (blocks0 bBits (bits t)){bn_v b < pow2 bBits} ->\n Pure (bn_mont_t n)\n (requires True)\n (ensures fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))\n\n\n// no diff between vartime and consttime at the spec level\nval bn_exp_mont_bm_vartime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_vartime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_rl_lemma k1 aM bBits (bn_v b);\n LE.exp_rl_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_rl k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_bm_consttime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_consttime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_mont_ladder_swap_lemma k1 aM bBits (bn_v b);\n LE.exp_mont_ladder_swap_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n LE.exp_mont_ladder_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_mont_ladder_swap k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_fw:\n #t:limb_t\n -> #len:BN.bn_len t\n -> l:size_pos{l < bits t /\\ pow2 l * len <= max_size_t} ->\n bn_exp_mont_st t len\n\nPartial implementation:\nlet bn_exp_mont_fw #t #len l n mu aM bBits b =\n \n"
},
{
"role": "assistant",
"content": "let k1 = mk_bn_mont_concrete_ops n mu in\nSE.exp_fw_lemma k1 aM bBits (bn_v b) l;\nLE.exp_fw_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b) l;\nSE.exp_fw k1 aM bBits (bn_v b) l"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\n\nnoextract\nlet bn_exp_mont_st (t:limb_t) (len:BN.bn_len t) =\n n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu}\n -> aM:bn_mont_t n\n -> bBits:size_nat\n -> b:lbignum t (blocks0 bBits (bits t)){bn_v b < pow2 bBits} ->\n Pure (bn_mont_t n)\n (requires True)\n (ensures fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))\n\n\n// no diff between vartime and consttime at the spec level\n\nPartial implementation:\nlet bn_exp_mont_bm_vartime #t #len n mu aM bBits b =\n \n"
},
{
"role": "assistant",
"content": "let k1 = mk_bn_mont_concrete_ops n mu in\nSE.exp_rl_lemma k1 aM bBits (bn_v b);\nLE.exp_rl_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\nSE.exp_rl k1 aM bBits (bn_v b)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Hacl.Spec.Bignum.MontExponentiation.bn_exp_mont_st t len\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Spec.Bignum.MontExponentiation\n\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Sequence\n\nopen Hacl.Spec.Bignum.Definitions\n\nmodule LE = Lib.Exponentiation\nmodule SE = Spec.Exponentiation\n\nmodule E = Hacl.Spec.Exponentiation.Lemmas\nmodule M = Hacl.Spec.Montgomery.Lemmas\n\nmodule BN = Hacl.Spec.Bignum\nmodule BM = Hacl.Spec.Bignum.Montgomery\n\n#reset-options \"--z3rlimit 50 --fuel 0 --ifuel 0\"\n\n// All operations are performed in the Montgomery domain!\n\nunfold\nlet bn_mont_t (#t:limb_t) (#len:BN.bn_len t) (n:lbignum t len) =\n x:lbignum t len{bn_v x < bn_v n}\n\nlet mk_to_nat_mont_ll_comm_monoid\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.to_comm_monoid (bn_mont_t n) =\n{\n SE.a_spec = Lib.NatMod.nat_mod (bn_v n);\n SE.comm_monoid = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu);\n SE.refl = (fun (x:bn_mont_t n) -> bn_v x);\n }\n\n\nval bn_mont_one:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.one_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_one #t #len n mu _ =\n BM.bn_precomp_r2_mod_n_lemma 0 n;\n let r2 = BM.bn_precomp_r2_mod_n 0 n in\n BM.bn_mont_one_lemma n mu r2;\n BM.bn_mont_one n mu r2\n\n\nval bn_mont_mul:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.mul_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_mul #t #len n mu aM bM =\n BM.bn_mont_mul_lemma n mu aM bM;\n BM.bn_mont_mul n mu aM bM\n\n\nval bn_mont_sqr:\n #t:limb_t\n -> #len:BN.bn_len t\n -> n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu} ->\n SE.sqr_st (bn_mont_t n) (mk_to_nat_mont_ll_comm_monoid n mu)\n\nlet bn_mont_sqr #t #len n mu aM =\n BM.bn_mont_sqr_lemma n mu aM;\n BM.bn_mont_sqr n mu aM\n\n\nlet mk_bn_mont_concrete_ops\n (#t:limb_t)\n (#len:BN.bn_len t)\n (n:lbignum t len)\n (mu:limb t{BM.bn_mont_pre n mu})\n : SE.concrete_ops (bn_mont_t n) =\n{\n SE.to = mk_to_nat_mont_ll_comm_monoid n mu;\n SE.one = bn_mont_one #t #len n mu;\n SE.mul = bn_mont_mul #t #len n mu;\n SE.sqr = bn_mont_sqr #t #len n mu;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n//TODO: set _threshold properly and\n//add `bn_get_window_size` (consttime and vartime)\ninline_for_extraction noextract\nlet bn_exp_mont_vartime_threshold = 200\n\ninline_for_extraction noextract\nlet bn_exp_mont_consttime_threshold = 200\n\n\nnoextract\nlet bn_exp_mont_st (t:limb_t) (len:BN.bn_len t) =\n n:lbignum t len\n -> mu:limb t{BM.bn_mont_pre n mu}\n -> aM:bn_mont_t n\n -> bBits:size_nat\n -> b:lbignum t (blocks0 bBits (bits t)){bn_v b < pow2 bBits} ->\n Pure (bn_mont_t n)\n (requires True)\n (ensures fun resM ->\n let k = E.mk_nat_mont_ll_comm_monoid (bits t) len (bn_v n) (v mu) in\n bn_v resM == LE.pow k (bn_v aM) (bn_v b))\n\n\n// no diff between vartime and consttime at the spec level\nval bn_exp_mont_bm_vartime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_vartime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_rl_lemma k1 aM bBits (bn_v b);\n LE.exp_rl_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_rl k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_bm_consttime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_bm_consttime #t #len n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_mont_ladder_swap_lemma k1 aM bBits (bn_v b);\n LE.exp_mont_ladder_swap_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n LE.exp_mont_ladder_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b);\n SE.exp_mont_ladder_swap k1 aM bBits (bn_v b)\n\n\nval bn_exp_mont_fw:\n #t:limb_t\n -> #len:BN.bn_len t\n -> l:size_pos{l < bits t /\\ pow2 l * len <= max_size_t} ->\n bn_exp_mont_st t len\n\nlet bn_exp_mont_fw #t #len l n mu aM bBits b =\n let k1 = mk_bn_mont_concrete_ops n mu in\n SE.exp_fw_lemma k1 aM bBits (bn_v b) l;\n LE.exp_fw_lemma k1.SE.to.SE.comm_monoid (bn_v aM) bBits (bn_v b) l;\n SE.exp_fw k1 aM bBits (bn_v b) l\n\n\nval bn_exp_mont_vartime: #t:limb_t -> #len:BN.bn_len t -> bn_exp_mont_st t len\nlet bn_exp_mont_vartime #t #len n mu aM bBits b =\n if bBits < bn_exp_mont_vartime_threshold then\n bn_exp_mont_bm_vartime n mu aM bBits b\n else\n bn_exp_mont_fw 4 n mu aM bBits b\n\nPartial implementation:\nlet bn_exp_mont_consttime #t #len n mu aM bBits b =\n \n"
},
{
"role": "assistant",
"content": "if bBits < bn_exp_mont_consttime_threshold\nthen bn_exp_mont_bm_consttime n mu aM bBits b\nelse bn_exp_mont_fw 4 n mu aM bBits b"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n hp: LowParse.Spec.Base.parser hk ht ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp\n -> LowParse.Spec.Base.parser (LowParse.Spec.DepLen.parse_deplen_kind min max hk pk)\n (LowParse.Spec.DepLen.parse_deplen_data_t min max dlf ps)\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nPartial implementation:\nlet parse_deplen\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n : Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps)) =\n \n"
},
{
"role": "assistant",
"content": "parse_tagged_union hp (calc_tag_of_deplen_data min max dlf ps) (parse_deplen_payload min max dlf ps)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n x: LowParse.Spec.DepLen.parse_deplen_data_t min max dlf ps\n -> Prims.GTot ht\nEffect: Prims.GTot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nPartial implementation:\nlet calc_tag_of_deplen_data\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (x: parse_deplen_data_t min max dlf ps)\n : GTot ht =\n \n"
},
{
"role": "assistant",
"content": "fst x"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp\n -> Type\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nPartial implementation:\nlet parse_deplen_data_t\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n =\n \n"
},
{
"role": "assistant",
"content": "x: (ht & pt){U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x))}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n hk: LowParse.Spec.Base.parser_kind ->\n pk: LowParse.Spec.Base.parser_kind\n -> LowParse.Spec.Base.parser_kind\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nPartial implementation:\nlet parse_deplen_kind (min: nat) (max: nat{min <= max /\\ max < 4294967296}) (hk pk: parser_kind) =\n \n"
},
{
"role": "assistant",
"content": "and_then_kind hk (parse_deplen_payload_kind min max pk)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: t: Hacl.Bignum.Definitions.limb_t -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Impl.RSAPSS\n\nopen FStar.HyperStack\nopen FStar.HyperStack.ST\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Buffer\n\nopen Hacl.Bignum.Definitions\n\nmodule ST = FStar.HyperStack.ST\n\nmodule Hash = Spec.Agile.Hash\nmodule SB = Hacl.Spec.Bignum\nmodule BB = Hacl.Spec.Bignum.Base\nmodule SD = Hacl.Spec.Bignum.Definitions\nmodule SM = Hacl.Spec.Bignum.Montgomery\nmodule SE = Hacl.Spec.Bignum.Exponentiation\n\nmodule BN = Hacl.Bignum\nmodule BE = Hacl.Bignum.Exponentiation\nmodule BM = Hacl.Bignum.Montgomery\n\nmodule S = Spec.RSAPSS\nmodule LS = Hacl.Spec.RSAPSS\nmodule LSeq = Lib.Sequence\n\nmodule RP = Hacl.Impl.RSAPSS.Padding\nmodule RM = Hacl.Impl.RSAPSS.MGF\nmodule RK = Hacl.Impl.RSAPSS.Keys\n\n#reset-options \"--z3rlimit 150 --fuel 0 --ifuel 0\"\n\nPartial implementation:\nlet modBits_t (t: limb_t) =\n \n"
},
{
"role": "assistant",
"content": "modBits: size_t{1 < v modBits /\\ (2 * bits t) * SD.blocks (v modBits) (bits t) <= max_size_t}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht\n -> LowParse.Spec.Base.parser (LowParse.Spec.DepLen.parse_deplen_payload_kind min max pk)\n (LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DepLen.calc_tag_of_deplen_data min\n max\n dlf\n ps)\n h)\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nPartial implementation:\nlet parse_deplen_payload\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n : Tot\n (parser (parse_deplen_payload_kind min max pk)\n (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) =\n \n"
},
{
"role": "assistant",
"content": "let sz = (U32.v (dlf h)) in\nlet bounds_off =\n pk.parser_kind_low > sz ||\n (match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz)\nin\nif bounds_off\nthen\n fail_parser (parse_deplen_payload_kind min max pk)\n (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\nelse\n weaken (parse_deplen_payload_kind min max pk)\n ((parse_fldata_strong ps sz) `parse_synth` (synth_deplen_data min max dlf ps h))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: Steel.GhostPCMReference.ref a pcm ->\n fact: Steel.Preorder.stable_property pcm ->\n v: FStar.Ghost.erased a ->\n _: Prims.squash (Steel.Preorder.fact_valid_compat fact (FStar.Ghost.reveal v))\n -> Steel.Effect.Atomic.SteelAtomicUT (Steel.GhostPCMReference.witnessed r fact)\nEffect: Steel.Effect.Atomic.SteelAtomicUT\n\nContext:\n(*\n Copyright 2020 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 Steel.GhostPCMReference\n(* A ghost variant of Steel.PCMReference *)\nopen FStar.PCM\nopen FStar.Ghost\n\nopen Steel.Memory\nopen Steel.Effect.Atomic\nopen Steel.Effect\nmodule Mem = Steel.Memory\nmodule P = Steel.PCMReference\n\nlet ref (a:Type) (p:pcm a) = erased (Steel.Memory.ref a p)\n\n/// Its selector is non-informative (it is unit)\n[@@__reduce__]\nlet pts_to (#a:Type u#1) (#pcm:pcm a) (r:ref a pcm) ([@@@smt_fallback]v:a)\n = to_vprop (Steel.Memory.pts_to r v)\n\nlet alloc (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (x:a)\n : SteelGhost\n (ref a pcm) o\n (emp)\n (fun r -> pts_to r x)\n (requires fun _ -> pcm.refine x)\n (ensures fun _ _ _ -> True)\n = rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp ());\n FStar.PCM.compatible_refl pcm x;\n let r = as_atomic_action_ghost (alloc_action o x) in\n r\n\nlet read (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (#v0:a)\n (r:ref a pcm)\n : SteelGhost a o\n (pts_to r v0)\n (fun _ -> pts_to r v0)\n (requires fun _ -> True)\n (ensures fun _ v _ -> compatible pcm v0 v)\n = let v = as_atomic_action_ghost (sel_action o r v0) in\n v\n\nlet write (#o:inames)\n (#a:Type)\n (#pcm:pcm a)\n (r:ref a pcm)\n (v0:a)\n (v1:a)\n : SteelGhost unit o\n (pts_to r v0)\n (fun _ -> pts_to r v1)\n (requires fun _ -> frame_preserving pcm v0 v1 /\\ pcm.refine v1)\n (ensures fun _ _ _ -> True)\n = as_atomic_action_ghost (upd_action o r v0 v1)\n\nlet upd_gen (#o:inames)\n (#a:Type)\n (#p:pcm a)\n (r:ref a p)\n (x y:a)\n (f:frame_preserving_upd p x y)\n : SteelGhostT unit o\n (pts_to r x)\n (fun _ -> pts_to r y)\n = as_atomic_action_ghost (Steel.Memory.upd_gen o r x y f)\n\nlet share (#o:inames)\n (#a:Type)\n (#p:pcm a)\n (r:ref a p)\n (v:a)\n (v0:a)\n (v1:a)\n : SteelGhost unit o\n (pts_to r v)\n (fun _ -> pts_to r v0 `star` pts_to r v1)\n (requires fun _ ->\n composable p v0 v1 /\\\n v == op p v0 v1)\n (ensures fun _ _ _ -> True)\n = P.split r v v0 v1\n\nlet gather (#o:inames)\n (#a:Type)\n (#p:FStar.PCM.pcm a)\n (r:ref a p)\n (v0:a)\n (v1:a)\n : SteelGhostT (_:unit{composable p v0 v1}) o\n (pts_to r v0 `star` pts_to r v1)\n (fun _ -> pts_to r (op p v0 v1))\n = P.gather r v0 v1\n\nlet witnessed (#a:Type) (#p:pcm a) (r:ref a p) (fact:property a)\n : Type0\n = Steel.Memory.witnessed r fact\n\nPartial implementation:\nlet witness\n (#o: inames)\n (#a: Type)\n (#pcm: pcm a)\n (r: ref a pcm)\n (fact: Steel.Preorder.stable_property pcm)\n (v: erased a)\n (_: squash (Steel.Preorder.fact_valid_compat fact v))\n =\n \n"
},
{
"role": "assistant",
"content": "P.witness r fact v ()"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht ->\n x: LowParse.Spec.FLData.parse_fldata_strong_t ps (FStar.UInt32.v (dlf h))\n -> LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DepLen.calc_tag_of_deplen_data min max dlf ps\n )\n h\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nPartial implementation:\nlet synth_deplen_data\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n (x: parse_fldata_strong_t ps (U32.v (dlf h)))\n : Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) =\n \n"
},
{
"role": "assistant",
"content": "(h, x)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht ->\n input:\n LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DepLen.calc_tag_of_deplen_data min\n max\n dlf\n ps)\n h\n -> FStar.Pervasives.Lemma\n (ensures\n LowParse.Spec.Base.serialize (LowParse.Spec.DepLen.serialize_deplen_payload min max dlf ps h)\n input ==\n LowParse.Spec.Base.serialize ps\n (LowParse.Spec.DepLen.synth_deplen_data_recip min max dlf ps h input))\nEffect: FStar.Pervasives.Lemma\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nlet parse_deplen_unfold\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some(x, consumed') -> \n if consumed' = U32.v (dlf h) then\n Some (x, consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n(* a stronger version that further unfolds the payload *)\n\nlet parse_deplen_unfold2\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (U32.v (dlf h) + consumed) in\n match parse pp input' with\n | None -> None\n | Some (t, consumed') -> \n if consumed' = U32.v (dlf h) && Seq.length (serialize ps t) = consumed' then\n Some ((h, t), consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n\n(* serializer spec *)\n\nlet synth_deplen_data_recip\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Tot (parse_fldata_strong_t ps (U32.v (dlf h)))\n= snd x\n\nlet serialize_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (serializer (parse_deplen_payload min max dlf ps h))\n= let sz = U32.v (dlf h) in\n let bounds_off =\n pk.parser_kind_low > sz || \n ( match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_serializer (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) (fun _ -> ())\n else\n serialize_weaken (parse_deplen_payload_kind min max pk)\n (serialize_synth\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n )\n\n(* the lemma says serializing the payload from the data (header + payload) is the same as serializing only the payload *)\n\nPartial implementation:\nlet serialize_deplen_payload_unfold\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n (input: refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n : Lemma\n (serialize (serialize_deplen_payload min max dlf ps h) input ==\n serialize ps (synth_deplen_data_recip min max dlf ps h input)) =\n \n"
},
{
"role": "assistant",
"content": "let sz = U32.v (dlf h) in\nserialize_synth_eq (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n input"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n hs:\n LowParse.Spec.Base.serializer hp\n { Mkparser_kind'?.parser_kind_subkind hk ==\n FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n input: LowParse.Spec.DepLen.parse_deplen_data_t min max dlf ps\n -> FStar.Pervasives.Lemma\n (ensures\n LowParse.Spec.Base.serialize (LowParse.Spec.DepLen.serialize_deplen min max hs dlf ps) input ==\n (let sh = LowParse.Spec.Base.serialize hs (FStar.Pervasives.Native.fst input) in\n let sp = LowParse.Spec.Base.serialize ps (FStar.Pervasives.Native.snd input) in\n FStar.Seq.Base.append sh sp))\nEffect: FStar.Pervasives.Lemma\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nlet parse_deplen_unfold\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some(x, consumed') -> \n if consumed' = U32.v (dlf h) then\n Some (x, consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n(* a stronger version that further unfolds the payload *)\n\nlet parse_deplen_unfold2\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (U32.v (dlf h) + consumed) in\n match parse pp input' with\n | None -> None\n | Some (t, consumed') -> \n if consumed' = U32.v (dlf h) && Seq.length (serialize ps t) = consumed' then\n Some ((h, t), consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n\n(* serializer spec *)\n\nlet synth_deplen_data_recip\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Tot (parse_fldata_strong_t ps (U32.v (dlf h)))\n= snd x\n\nlet serialize_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (serializer (parse_deplen_payload min max dlf ps h))\n= let sz = U32.v (dlf h) in\n let bounds_off =\n pk.parser_kind_low > sz || \n ( match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_serializer (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) (fun _ -> ())\n else\n serialize_weaken (parse_deplen_payload_kind min max pk)\n (serialize_synth\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n )\n\n(* the lemma says serializing the payload from the data (header + payload) is the same as serializing only the payload *)\n\nlet serialize_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Lemma\n (serialize (serialize_deplen_payload min max dlf ps h) input == serialize ps (synth_deplen_data_recip min max dlf ps h input))\n= let sz = U32.v (dlf h) in\n serialize_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n input\n\nlet serialize_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (#hp: parser hk ht)\n (hs: serializer hp { hk.parser_kind_subkind == Some ParserStrong } )\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (serializer (parse_deplen min max hp dlf ps))\n= serialize_tagged_union\n hs\n (calc_tag_of_deplen_data min max dlf ps)\n (serialize_deplen_payload min max dlf ps)\n\n(* the lemma says serializing the data is the same as first serializing the header then the payload *)\n\nPartial implementation:\nlet serialize_deplen_unfold\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#hk: parser_kind)\n (#ht: Type)\n (#hp: parser hk ht)\n (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong})\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input: parse_deplen_data_t min max dlf ps)\n : Lemma\n (serialize (serialize_deplen min max hs dlf ps) input ==\n (let sh = serialize hs (fst input) in\n let sp = serialize ps (snd input) in\n sh `Seq.append` sp)) =\n \n"
},
{
"role": "assistant",
"content": "serialize_tagged_union_eq hs\n (calc_tag_of_deplen_data min max dlf ps)\n (serialize_deplen_payload min max dlf ps)\n input;\nlet h:ht = calc_tag_of_deplen_data min max dlf ps input in\nserialize_deplen_payload_unfold min max dlf ps h input"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht ->\n x:\n LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DepLen.calc_tag_of_deplen_data min\n max\n dlf\n ps)\n h\n -> LowParse.Spec.FLData.parse_fldata_strong_t ps (FStar.UInt32.v (dlf h))\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nlet parse_deplen_unfold\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some(x, consumed') -> \n if consumed' = U32.v (dlf h) then\n Some (x, consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n(* a stronger version that further unfolds the payload *)\n\nlet parse_deplen_unfold2\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (U32.v (dlf h) + consumed) in\n match parse pp input' with\n | None -> None\n | Some (t, consumed') -> \n if consumed' = U32.v (dlf h) && Seq.length (serialize ps t) = consumed' then\n Some ((h, t), consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n\n(* serializer spec *)\n\nPartial implementation:\nlet synth_deplen_data_recip\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n (x: refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n : Tot (parse_fldata_strong_t ps (U32.v (dlf h))) =\n \n"
},
{
"role": "assistant",
"content": "snd x"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: Prims.unit\n -> FStar.Pervasives.Lemma\n (ensures\n Benton2004.RHL.Derived.related Benton2004.RHL.Examples2.l\n Benton2004.RHL.Examples2.r\n (Benton2004.RHL.Examples2.phi ())\n (Benton2004.RHL.Examples2.phi ()))\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 Benton2004.RHL.Examples2\ninclude Benton2004.RHL.Derived\n\nassume val i: var\nassume val n: var\nassume val x: var\nassume val y: var\nassume val hyp : squash (List.Tot.noRepeats [i; n; x; y] == true)\n\nlet cond = eop op_LessThan (evar i) (evar n)\nlet asx_e = eop op_Addition (evar y) (const 1)\nlet asi_e = eop op_Addition (evar i) (evar x)\nlet l = while cond (seq (assign x asx_e) (assign i asi_e))\nlet r = seq (assign x asx_e) (while cond (assign i asi_e))\n\nlet phi () : GTot (gexp bool) = gand (geq (gvar i Left) (gvar i Right)) (gand (geq (gvar n Left) (gvar n Right)) (geq (gvar y Left) (gvar y Right)))\n\nlet lemma_included_helper ()\n : Lemma (let phi = phi () in\n let phi1 = gand phi (geq (gvar x Right) (gop op_Addition (gvar y Right) (gconst 1))) in\n let phi2 = gand phi1 (geq (gvar x Left) (gvar x Right)) in\n included phi2 (gsubst (gsubst phi2 i Left (exp_to_gexp asi_e Left)) i Right (exp_to_gexp asi_e Right)))\n = ()\n\n#set-options \"--max_fuel 3 --max_ifuel 0 --initial_fuel 3 --z3rlimit_factor 4\"\n\nPartial implementation:\nlet proof () : Lemma (related l r (phi ()) (phi ())) =\n \n"
},
{
"role": "assistant",
"content": "let phi = phi () in\nlet phi1 = gand phi (geq (gvar x Right) (gop op_Addition (gvar y Right) (gconst 1))) in\nlet phi2 = gand phi1 (geq (gvar x Left) (gvar x Right)) in\nhyp;\nassert (related (assign x asx_e) skip phi1 phi2);\nlemma_included_helper ();\nassert (related (assign i asi_e) (assign i asi_e) phi2 phi2);\nd_su1' (assign x asx_e) (assign i asi_e) (assign i asi_e) phi1 phi2 phi2;\nr_while cond cond (seq (assign x asx_e) (assign i asi_e)) (assign i asi_e) phi1;\nassert (related skip (assign x asx_e) phi phi1);\nassert (related l (while cond (assign i asi_e)) phi1 phi);\nd_su1'_flip l (assign x asx_e) (while cond (assign i asi_e)) phi phi1 phi"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: Prims.int -> Prims.int\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\nPartial implementation:\nlet add_2 (x: int) : int =\n \n"
},
{
"role": "assistant",
"content": "FStar.Tactics.Effect.synth_by_tactic (fun _ -> (normalize [primops; delta] (add_1 (add_1 x))))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht\n -> LowParse.Spec.Base.serializer (LowParse.Spec.DepLen.parse_deplen_payload min max dlf ps h)\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nlet parse_deplen_unfold\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some(x, consumed') -> \n if consumed' = U32.v (dlf h) then\n Some (x, consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n(* a stronger version that further unfolds the payload *)\n\nlet parse_deplen_unfold2\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (U32.v (dlf h) + consumed) in\n match parse pp input' with\n | None -> None\n | Some (t, consumed') -> \n if consumed' = U32.v (dlf h) && Seq.length (serialize ps t) = consumed' then\n Some ((h, t), consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n\n(* serializer spec *)\n\nlet synth_deplen_data_recip\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Tot (parse_fldata_strong_t ps (U32.v (dlf h)))\n= snd x\n\nPartial implementation:\nlet serialize_deplen_payload\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n : Tot (serializer (parse_deplen_payload min max dlf ps h)) =\n \n"
},
{
"role": "assistant",
"content": "let sz = U32.v (dlf h) in\nlet bounds_off =\n pk.parser_kind_low > sz ||\n (match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz)\nin\nif bounds_off\nthen\n fail_serializer (parse_deplen_payload_kind min max pk)\n (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n (fun _ -> ())\nelse\n serialize_weaken (parse_deplen_payload_kind min max pk)\n (serialize_synth (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ())"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: steps: Prims.list FStar.Pervasives.norm_step -> x: t -> FStar.Tactics.Effect.Tac Prims.unit\nEffect: FStar.Tactics.Effect.Tac\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n\nPartial implementation:\nlet normalize (#t: Type) (steps: list norm_step) (x: t) : Tac unit =\n \n"
},
{
"role": "assistant",
"content": "dup ();\nexact (quote x);\nnorm steps;\ntrefl ()"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: Prims.int -> Prims.int\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nPartial implementation:\nlet add_1 (x: int) : int =\n \n"
},
{
"role": "assistant",
"content": "x + 1"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.int\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\n(* add_2 is defined to be (x + 1) + 1 *)\nlet add_2 (x:int) : int = _ by (normalize [primops; delta] (add_1 (add_1 x)))\n\nPartial implementation:\nlet four:int =\n \n"
},
{
"role": "assistant",
"content": "FStar.Tactics.Effect.synth_by_tactic (fun _ -> (normalize [primops; delta] (add_2 2)))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n hs:\n LowParse.Spec.Base.serializer hp\n { Mkparser_kind'?.parser_kind_subkind hk ==\n FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp\n -> LowParse.Spec.Base.serializer (LowParse.Spec.DepLen.parse_deplen min max hp dlf ps)\nEffect: Prims.Tot\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nlet parse_deplen_unfold\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some(x, consumed') -> \n if consumed' = U32.v (dlf h) then\n Some (x, consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n(* a stronger version that further unfolds the payload *)\n\nlet parse_deplen_unfold2\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input : bytes)\n: Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n begin\n if (U32.v (dlf h) + consumed) > (Seq.length input) then\n None\n else\n let input' = Seq.slice input consumed (U32.v (dlf h) + consumed) in\n match parse pp input' with\n | None -> None\n | Some (t, consumed') -> \n if consumed' = U32.v (dlf h) && Seq.length (serialize ps t) = consumed' then\n Some ((h, t), consumed + (U32.v (dlf h)))\n else\n None\n end)\n )\n= parse_tagged_union_eq\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\n match parse hp input with\n | None -> ()\n | Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz then\n ()\n else\n Seq.slice_slice input consumed (Seq.length input) 0 sz\n\n\n(* serializer spec *)\n\nlet synth_deplen_data_recip\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Tot (parse_fldata_strong_t ps (U32.v (dlf h)))\n= snd x\n\nlet serialize_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (serializer (parse_deplen_payload min max dlf ps h))\n= let sz = U32.v (dlf h) in\n let bounds_off =\n pk.parser_kind_low > sz || \n ( match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_serializer (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) (fun _ -> ())\n else\n serialize_weaken (parse_deplen_payload_kind min max pk)\n (serialize_synth\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n )\n\n(* the lemma says serializing the payload from the data (header + payload) is the same as serializing only the payload *)\n\nlet serialize_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input : refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n: Lemma\n (serialize (serialize_deplen_payload min max dlf ps h) input == serialize ps (synth_deplen_data_recip min max dlf ps h input))\n= let sz = U32.v (dlf h) in\n serialize_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n (serialize_fldata_strong ps sz)\n (synth_deplen_data_recip min max dlf ps h)\n ()\n input\n\nPartial implementation:\nlet serialize_deplen\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#hk: parser_kind)\n (#ht: Type)\n (#hp: parser hk ht)\n (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong})\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n : Tot (serializer (parse_deplen min max hp dlf ps)) =\n \n"
},
{
"role": "assistant",
"content": "serialize_tagged_union hs\n (calc_tag_of_deplen_data min max dlf ps)\n (serialize_deplen_payload min max dlf ps)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: t -> t\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\n(* add_2 is defined to be (x + 1) + 1 *)\nlet add_2 (x:int) : int = _ by (normalize [primops; delta] (add_1 (add_1 x)))\n\n(* `four` is defined as `4` ... *)\nlet four : int = _ by (normalize [primops; delta] (add_2 2))\n\n(* .. as we can check by inspecting its definition *)\nlet _ = assert True\n by (let t = def_of four in\n if compare_term t (`4) = FStar.Order.Eq\n then ()\n else fail \"Test 1\")\n\n(* GM, 2023/11/09: this is now no longer true. The unifier does trigger\nprimitive steps computations, and the trefl() call above\nwill instantiate the RHS with the WHNF of the LHS, which is also 4. *)\n\n(* If we only allow for Delta steps, then there's no primitive computation and we\n * end up with (2 + 1) + 1 *)\n(* let four' : int = _ by (normalize [delta] (add_2 2)) *)\n\n(* let _ = assert True *)\n(* by (let t = def_of four' in *)\n(* if compare_term t (`((2 + 1) + 1)) = FStar.Order.Eq *)\n(* then () *)\n(* else fail \"Test 2\") *)\n\n(* Here, we allow for primitive computation but don't allow for `add_2` to be expanded to\n * its definition, so the final result is `add_2 1` *)\nlet unfold_add_1: norm_step = delta_only [\"Normalization.add_1\"]\n\nlet three : int = _ by (normalize [delta; unfold_add_1; primops] (add_2 (add_1 0)))\n\nlet _ = assert True\n by (let t = def_of three in\n if compare_term t (`(add_2 1)) = FStar.Order.Eq\n then ()\n else fail \"Test 3\")\n\n(* Writing a function that normalizes its argument does not work! The tactic runs\n * when this definition is type-checked, and not when it's called. So, this function is just an\n\nPartial implementation:\nlet does_not_normalize (#t: Type) (x: t) : t =\n \n"
},
{
"role": "assistant",
"content": "FStar.Tactics.Effect.synth_by_tactic (fun _ -> (normalize [primops; delta] x))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.int\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\n(* add_2 is defined to be (x + 1) + 1 *)\nlet add_2 (x:int) : int = _ by (normalize [primops; delta] (add_1 (add_1 x)))\n\n(* `four` is defined as `4` ... *)\nlet four : int = _ by (normalize [primops; delta] (add_2 2))\n\n(* .. as we can check by inspecting its definition *)\nlet _ = assert True\n by (let t = def_of four in\n if compare_term t (`4) = FStar.Order.Eq\n then ()\n else fail \"Test 1\")\n\n(* GM, 2023/11/09: this is now no longer true. The unifier does trigger\nprimitive steps computations, and the trefl() call above\nwill instantiate the RHS with the WHNF of the LHS, which is also 4. *)\n\n(* If we only allow for Delta steps, then there's no primitive computation and we\n * end up with (2 + 1) + 1 *)\n(* let four' : int = _ by (normalize [delta] (add_2 2)) *)\n\n(* let _ = assert True *)\n(* by (let t = def_of four' in *)\n(* if compare_term t (`((2 + 1) + 1)) = FStar.Order.Eq *)\n(* then () *)\n(* else fail \"Test 2\") *)\n\n(* Here, we allow for primitive computation but don't allow for `add_2` to be expanded to\n * its definition, so the final result is `add_2 1` *)\nlet unfold_add_1: norm_step = delta_only [\"Normalization.add_1\"]\n\nlet three : int = _ by (normalize [delta; unfold_add_1; primops] (add_2 (add_1 0)))\n\nlet _ = assert True\n by (let t = def_of three in\n if compare_term t (`(add_2 1)) = FStar.Order.Eq\n then ()\n else fail \"Test 3\")\n\n(* Writing a function that normalizes its argument does not work! The tactic runs\n * when this definition is type-checked, and not when it's called. So, this function is just an\n * identity function with no special semantics. *)\nlet does_not_normalize (#t:Type) (x:t) : t =\n _ by (normalize [primops; delta] x)\n\nPartial implementation:\nlet four'':int =\n \n"
},
{
"role": "assistant",
"content": "does_not_normalize (2 + 2)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: f: FStar.Seq.Properties.tot_ord a -> i: Prims.nat -> j: Prims.nat{i <= j} -> x: FStar.Array.array a\n -> FStar.ST.ST Prims.unit\nEffect: FStar.ST.ST\n\nContext:\n(*\n Copyright 2008-2014 Nikhil Swamy and 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 QuickSort.Array\nopen FStar.Array\nopen FStar.Seq\nopen FStar.Heap\nopen FStar.ST\n#set-options \"--initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\n\n(* 2016-11-22: Due to the QuickSort namespace being opened *after* the\nFStar namespace,Array resolves to QuickSort.Array instead of\nFStar.Array, so we have to fix this explicitly as a module abbrev. *)\nmodule Array = FStar.Array\nmodule Seq = FStar.Seq\n\ntype partition_inv (a:eqtype) (f:tot_ord a) (lo:seq a) (pv:a) (hi:seq a) =\n ((length hi) >= 0)\n /\\ (forall y. (mem y hi ==> f pv y) /\\ (mem y lo ==> f y pv))\n\ntype partition_pre (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h:heap) =\n (Array.contains h x\n /\\ ((let s = Array.sel h x in (len <= length s) /\\ (partition_inv a f\n (slice s start pivot)\n (index s pivot)\n (slice s (back + 1) len)))\n ))\n\ntype partition_post (a:eqtype) (f:tot_ord a) (start:nat) (len:nat{start <= len} )\n (pivot:nat{start <= pivot /\\ pivot < len})\n (back:nat{pivot <= back /\\ back < len})\n (x:array a) (h0:heap) (i:nat) (h1:heap) =\n (len <= length (Array.sel h0 x)\n /\\ Array.contains h1 x\n /\\ start <= i\n /\\ i < len\n /\\ (length (Array.sel h1 x) = length (Array.sel h0 x))\n /\\ (Array.sel h1 x == splice (Array.sel h0 x) start (Array.sel h1 x) len)\n /\\ (permutation a (slice (Array.sel h0 x) start len) (slice (Array.sel h1 x) start len))\n /\\ (partition_inv a f\n (slice (Array.sel h1 x) start i)\n (index (Array.sel h1 x) i)\n (slice (Array.sel h1 x) i len)))\n\n#reset-options \"--z3rlimit 20 --initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0\"\nval partition: #a:eqtype -> f:tot_ord a\n -> start:nat -> len:nat{start <= len}\n -> pivot:nat{start <= pivot /\\ pivot < len}\n -> back:nat{pivot <= back /\\ back < len}\n -> x:array a -> ST nat\n (requires (partition_pre a f start len pivot back x))\n (ensures (fun h0 n h1 -> partition_post a f start len pivot back x h0 n h1 /\\ modifies (Array.only x) h0 h1))\nlet rec partition #a f start len pivot back x =\n let h0 = get() in\n if pivot = back\n then\n begin\n(*ghost*) (let s = Array.sel h0 x in\n(*ghost*) lemma_slice_cons s pivot len;\n(*ghost*) splice_refl s start len);\n pivot\n end\n else\n begin\n let next = Array.index x (pivot + 1) in\n let p = Array.index x pivot in\n if f next p\n then\n begin\n Array.swap x pivot (pivot + 1); (* the pivot moves forward *)\n let h1 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) swap_frame_lo s start pivot (pivot + 1);\n(* ghost *) swap_frame_hi s pivot (pivot + 1) (back + 1) len;\n assume (pivot < length s');\n //lemma_swap_splice s start (pivot + 1) back len;\n (* need pivot < length s',\n but only have pivot < length s *)\n(* ghost *) lemma_ordering_lo_snoc f s' start pivot p in\n let res = partition f start len (pivot + 1) back x in\n\t let h2 = get () in\n let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start pivot (pivot + 1) len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n else\n begin\n Array.swap x (pivot + 1) back; (* the back moves backward *)\n\t let h1 = get () in\n// (* ghost *) let s = Array.sel h0 x in\n// (* ghost *) let s' = Array.sel h1 x in\n// (* ghost *) swap_frame_lo' s start pivot (pivot + 1) back;\n// (* ghost *) swap_frame_hi s (pivot + 1) back (back + 1) len;\n// (* ghost *) lemma_ordering_hi_cons f s' back len p in\n let res = partition f start len pivot (back - 1) x in\n\t let h2 = get () in\n\t let _ =\n(* ghost *) let s = Array.sel h0 x in\n(* ghost *) let s' = Array.sel h1 x in\n(* ghost *) let s'' = Array.sel h2 x in\n(* ghost *) lemma_swap_splice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_frame s'' s' s start len;\n(* ghost *) lemma_swap_permutes_slice s start (pivot + 1) back len;\n(* ghost *) lemma_trans_perm s s' s'' start len in\n res\n end\n end\n#reset-options\n\nval lemma_slice_cons_pv: #a:Type -> s:seq a -> i:nat -> pivot:nat{i <= pivot} -> j:nat{pivot < j && j <= length s} -> pv:a\n -> Lemma\n (requires (pv == index s pivot))\n (ensures (slice s i j == append (slice s i pivot) (cons pv (slice s (pivot + 1) j))))\nlet lemma_slice_cons_pv #a s i pivot j pv =\n let lo = slice s i pivot in\n let hi = slice s (pivot + 1) j in\n cut (Seq.equal (slice s i j) (append lo (cons pv hi)))\n\n#reset-options\n#set-options \"--initial_fuel 1 --initial_ifuel 0 --max_fuel 1 --max_ifuel 0 --z3rlimit 50\"\nval sort: #a:eqtype -> f:tot_ord a -> i:nat -> j:nat{i <= j} -> x:array a\n -> ST unit\n (requires (fun h -> Array.contains h x /\\ j <= length (Array.sel h x)))\n (ensures (fun h0 u h1 -> (modifies (Array.only x) h0 h1\n /\\ j <= length (Array.sel h0 x) (* carrying this along from the requires clause *)\n /\\ Array.contains h1 x (* the array is still in the heap *)\n /\\ (length (Array.sel h0 x) = length (Array.sel h1 x)) (* its length has not changed *)\n /\\ sorted f (slice (Array.sel h1 x) i j) (* it is sorted between [i, j) *)\n /\\ (Array.sel h1 x == splice (Array.sel h0 x) i (Array.sel h1 x) j) (* the rest of it is unchanged *)\n\nPartial implementation:\nlet rec sort #a f i j x =\n \n"
},
{
"role": "assistant",
"content": "let h0 = ST.get () in\nif i = j\nthen splice_refl (Array.sel h0 x) i j\nelse\n let pivot = partition f i j i (j - 1) x in\n let h1 = get () in\n sort f i pivot x;\n let h2 = get () in\n let _ =\n lemma_seq_frame_hi (Array.sel h2 x) (Array.sel h1 x) i pivot pivot j;\n lemma_tail_slice (Array.sel h2 x) pivot j\n in\n sort f (pivot + 1) j x;\n let h3 = get () in\n lemma_seq_frame_lo (Array.sel h3 x) (Array.sel h2 x) i pivot (pivot + 1) j;\n let lo = slice (Array.sel h3 x) i pivot in\n let hi = slice (Array.sel h3 x) (pivot + 1) j in\n let pv = index (Array.sel h1 x) pivot in\n Seq.sorted_concat_lemma f lo pv hi;\n lemma_slice_cons_pv (Array.sel h3 x) i pivot j pv;\n lemma_weaken_frame_right (Array.sel h2 x) (Array.sel h1 x) i pivot j;\n lemma_weaken_frame_left (Array.sel h3 x) (Array.sel h2 x) i (pivot + 1) j;\n lemma_trans_frame (Array.sel h3 x) (Array.sel h2 x) (Array.sel h1 x) i j;\n lemma_trans_frame (Array.sel h3 x) (Array.sel h1 x) (Array.sel h0 x) i j;\n lemma_weaken_perm_right (Array.sel h2 x) (Array.sel h1 x) i pivot j;\n lemma_weaken_perm_left (Array.sel h3 x) (Array.sel h2 x) i (pivot + 1) j"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: FStar.Pervasives.norm_step\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\n(* add_2 is defined to be (x + 1) + 1 *)\nlet add_2 (x:int) : int = _ by (normalize [primops; delta] (add_1 (add_1 x)))\n\n(* `four` is defined as `4` ... *)\nlet four : int = _ by (normalize [primops; delta] (add_2 2))\n\n(* .. as we can check by inspecting its definition *)\nlet _ = assert True\n by (let t = def_of four in\n if compare_term t (`4) = FStar.Order.Eq\n then ()\n else fail \"Test 1\")\n\n(* GM, 2023/11/09: this is now no longer true. The unifier does trigger\nprimitive steps computations, and the trefl() call above\nwill instantiate the RHS with the WHNF of the LHS, which is also 4. *)\n\n(* If we only allow for Delta steps, then there's no primitive computation and we\n * end up with (2 + 1) + 1 *)\n(* let four' : int = _ by (normalize [delta] (add_2 2)) *)\n\n(* let _ = assert True *)\n(* by (let t = def_of four' in *)\n(* if compare_term t (`((2 + 1) + 1)) = FStar.Order.Eq *)\n(* then () *)\n(* else fail \"Test 2\") *)\n\n(* Here, we allow for primitive computation but don't allow for `add_2` to be expanded to\n\nPartial implementation:\nlet unfold_add_1:norm_step =\n \n"
},
{
"role": "assistant",
"content": "delta_only [\"Normalization.add_1\"]"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.int\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\n(* This tactic also depends on said behaviour of quote, and returns the definition of a top-level fvar *)\nlet def_of (#t:Type) (x:t) : Tac term =\n let e = cur_env () in\n let t = quote x in\n match inspect t with\n | Tv_UInst fv _\n | Tv_FVar fv -> begin\n let se = match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n match inspect_sigelt se with\n | Sg_Let {lbs} -> begin\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n end\n | _ -> fail \"not a sig_let\"\n end\n | _ -> fail \"not an fvar\"\n\nlet add_1 (x:int) : int = x + 1\n\n(* add_2 is defined to be (x + 1) + 1 *)\nlet add_2 (x:int) : int = _ by (normalize [primops; delta] (add_1 (add_1 x)))\n\n(* `four` is defined as `4` ... *)\nlet four : int = _ by (normalize [primops; delta] (add_2 2))\n\n(* .. as we can check by inspecting its definition *)\nlet _ = assert True\n by (let t = def_of four in\n if compare_term t (`4) = FStar.Order.Eq\n then ()\n else fail \"Test 1\")\n\n(* GM, 2023/11/09: this is now no longer true. The unifier does trigger\nprimitive steps computations, and the trefl() call above\nwill instantiate the RHS with the WHNF of the LHS, which is also 4. *)\n\n(* If we only allow for Delta steps, then there's no primitive computation and we\n * end up with (2 + 1) + 1 *)\n(* let four' : int = _ by (normalize [delta] (add_2 2)) *)\n\n(* let _ = assert True *)\n(* by (let t = def_of four' in *)\n(* if compare_term t (`((2 + 1) + 1)) = FStar.Order.Eq *)\n(* then () *)\n(* else fail \"Test 2\") *)\n\n(* Here, we allow for primitive computation but don't allow for `add_2` to be expanded to\n * its definition, so the final result is `add_2 1` *)\nlet unfold_add_1: norm_step = delta_only [\"Normalization.add_1\"]\n\nPartial implementation:\nlet three:int =\n \n"
},
{
"role": "assistant",
"content": "FStar.Tactics.Effect.synth_by_tactic (fun _ ->\n (normalize [delta; unfold_add_1; primops] (add_2 (add_1 0))))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n t: Hacl.Bignum.Definitions.limb_t ->\n a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} ->\n modBits: Hacl.Impl.RSAPSS.modBits_t t\n -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Impl.RSAPSS\n\nopen FStar.HyperStack\nopen FStar.HyperStack.ST\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Buffer\n\nopen Hacl.Bignum.Definitions\n\nmodule ST = FStar.HyperStack.ST\n\nmodule Hash = Spec.Agile.Hash\nmodule SB = Hacl.Spec.Bignum\nmodule BB = Hacl.Spec.Bignum.Base\nmodule SD = Hacl.Spec.Bignum.Definitions\nmodule SM = Hacl.Spec.Bignum.Montgomery\nmodule SE = Hacl.Spec.Bignum.Exponentiation\n\nmodule BN = Hacl.Bignum\nmodule BE = Hacl.Bignum.Exponentiation\nmodule BM = Hacl.Bignum.Montgomery\n\nmodule S = Spec.RSAPSS\nmodule LS = Hacl.Spec.RSAPSS\nmodule LSeq = Lib.Sequence\n\nmodule RP = Hacl.Impl.RSAPSS.Padding\nmodule RM = Hacl.Impl.RSAPSS.MGF\nmodule RK = Hacl.Impl.RSAPSS.Keys\n\n#reset-options \"--z3rlimit 150 --fuel 0 --ifuel 0\"\n\ninline_for_extraction noextract\nlet modBits_t (t:limb_t) = modBits:size_t{1 < v modBits /\\ 2 * bits t * SD.blocks (v modBits) (bits t) <= max_size_t}\n\n\ninline_for_extraction noextract\nlet rsapss_sign_bn_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> m:lbignum t len\n -> m':lbignum t len\n -> s:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h skey /\\ live h m /\\ live h s /\\ live h m' /\\\n disjoint s m /\\ disjoint s skey /\\ disjoint m skey /\\\n disjoint m m' /\\ disjoint m' s /\\ disjoint m' skey /\\\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n bn_v h m < bn_v h (gsub skey 0ul len))\n (ensures fun h0 r h1 -> modifies (loc s |+| loc m') h0 h1 /\\\n (r, as_seq h1 s) == LS.rsapss_sign_bn (v modBits) (v eBits) (v dBits) (as_seq h0 skey) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_sign_bn: #t:limb_t -> ke:BE.exp t -> modBits:modBits_t t -> rsapss_sign_bn_st t ke modBits\nlet rsapss_sign_bn #t ke modBits eBits dBits skey m m' s =\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let eLen = blocks eBits (size bits) in\n let dLen = blocks dBits (size bits) in\n\n let n = sub skey 0ul nLen in\n let r2 = sub skey nLen nLen in\n let e = sub skey (nLen +! nLen) eLen in\n let d = sub skey (nLen +! nLen +! eLen) dLen in\n\n Math.Lemmas.pow2_le_compat (bits * v nLen) (v modBits);\n let h0 = ST.get () in\n SM.bn_precomp_r2_mod_n_lemma (v modBits - 1) (as_seq h0 n);\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_ct_precomp n r2 m dBits d s;\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_vt_precomp n r2 s eBits e m';\n let h1 = ST.get () in\n SD.bn_eval_inj (v nLen) (as_seq h1 s)\n (SE.bn_mod_exp_consttime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h0 m) (v dBits) (as_seq h0 d));\n SD.bn_eval_inj (v nLen) (as_seq h1 m')\n (SE.bn_mod_exp_vartime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h1 s) (v eBits) (as_seq h0 e));\n let eq_m = BN.bn_eq_mask nLen m m' in\n mapT nLen s (logand eq_m) s;\n BB.unsafe_bool_of_limb eq_m\n\nPartial implementation:\nlet rsapss_sign_msg_to_bn_st\n (t: limb_t)\n (a: Hash.hash_alg{S.hash_is_supported a})\n (modBits: modBits_t t)\n =\n \n"
},
{
"role": "assistant",
"content": "let len = blocks modBits (size (bits t)) in\n\n saltLen: size_t ->\n salt: lbuffer uint8 saltLen ->\n msgLen: size_t ->\n msg: lbuffer uint8 msgLen ->\n m: lbignum t len\n -> Stack unit\n (requires\n fun h ->\n live h salt /\\ live h msg /\\ live h m /\\ disjoint salt msg /\\ disjoint m msg /\\\n disjoint m salt /\\ as_seq h m == LSeq.create (v len) (uint #t 0) /\\\n LS.rsapss_sign_pre a (v modBits) (v saltLen) (as_seq h salt) (v msgLen) (as_seq h msg))\n (ensures\n fun h0 _ h1 ->\n modifies (loc m) h0 h1 /\\\n as_seq h1 m ==\n LS.rsapss_sign_msg_to_bn a\n (v modBits)\n (v saltLen)\n (as_seq h0 salt)\n (v msgLen)\n (as_seq h0 msg))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n hp: LowParse.Spec.Base.parser hk ht ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n input: LowParse.Bytes.bytes\n -> FStar.Pervasives.Lemma\n (ensures\n LowParse.Spec.Base.parse (LowParse.Spec.DepLen.parse_deplen min max hp dlf ps) input ==\n (match LowParse.Spec.Base.parse hp input with\n | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None\n | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ h consumed) ->\n (match FStar.UInt32.v (dlf h) + consumed > FStar.Seq.Base.length input with\n | true -> FStar.Pervasives.Native.None\n | _ ->\n let input' = FStar.Seq.Base.slice input consumed (FStar.Seq.Base.length input) in\n (match\n LowParse.Spec.Base.parse (LowParse.Spec.DepLen.parse_deplen_payload min\n max\n dlf\n ps\n h)\n input'\n with\n | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None\n | FStar.Pervasives.Native.Some\n #_\n (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed') ->\n (match consumed' = FStar.UInt32.v (dlf h) with\n | true -> FStar.Pervasives.Native.Some (x, consumed + FStar.UInt32.v (dlf h))\n | _ -> FStar.Pervasives.Native.None)\n <:\n FStar.Pervasives.Native.option (LowParse.Spec.DepLen.parse_deplen_data_t min\n max\n dlf\n ps *\n LowParse.Spec.Base.consumed_length input))\n <:\n FStar.Pervasives.Native.option (LowParse.Spec.DepLen.parse_deplen_data_t min\n max\n dlf\n ps *\n LowParse.Spec.Base.consumed_length input))\n <:\n FStar.Pervasives.Native.option (LowParse.Spec.DepLen.parse_deplen_data_t min max dlf ps *\n LowParse.Spec.Base.consumed_length input)))\nEffect: FStar.Pervasives.Lemma\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*) \n\nlet parse_deplen_payload_unfold\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (input: bytes)\n: Lemma\n (parse (parse_deplen_payload min max dlf ps h) input == (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed)))\n = let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then ()\n else\n parse_synth_eq\n (parse_fldata_strong ps sz)\n (synth_deplen_data min max dlf ps h)\n input\n\n(* metadata for dependent length parser\n\n @min : \n @max : integer bounds\n @hk : header metadata\n @pk : payload metadata\n*)\n\nlet parse_deplen_kind\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (hk : parser_kind)\n (pk : parser_kind)\n= and_then_kind hk (parse_deplen_payload_kind min max pk)\n\n\n(* parse spec for dependent length structures *)\n\nlet parse_deplen\n (min: nat)\n (max: nat { min <= max /\\ max < 4294967296 } )\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: ht -> Tot (bounded_int32 min max))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n: Tot (parser (parse_deplen_kind min max hk pk) (parse_deplen_data_t min max dlf ps))\n= parse_tagged_union\n hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n\n(* This lemma says using the parser above is equivalent to using the header parser and then\n the deplen_payload parser\n*)\n\nPartial implementation:\nlet parse_deplen_unfold\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#hk: parser_kind)\n (#ht: Type)\n (hp: parser hk ht)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pt: Type)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (input: bytes)\n : Lemma\n (parse (parse_deplen min max hp dlf ps) input ==\n (match parse hp input with\n | None -> None\n | Some (h, consumed) ->\n if (U32.v (dlf h) + consumed) > (Seq.length input)\n then None\n else\n let input' = Seq.slice input consumed (Seq.length input) in\n match parse (parse_deplen_payload min max dlf ps h) input' with\n | None -> None\n | Some (x, consumed') ->\n if consumed' = U32.v (dlf h) then Some (x, consumed + (U32.v (dlf h))) else None)) =\n \n"
},
{
"role": "assistant",
"content": "parse_tagged_union_eq hp\n (calc_tag_of_deplen_data min max dlf ps)\n (parse_deplen_payload min max dlf ps)\n input;\nmatch parse hp input with\n| None -> ()\n| Some (h, consumed) ->\n let input' = Seq.slice input consumed (Seq.length input) in\n parse_deplen_payload_unfold min max dlf ps h input';\n let sz = (U32.v (dlf h)) in\n if Seq.length input < consumed + sz\n then ()\n else Seq.slice_slice input consumed (Seq.length input) 0 sz"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: a\n -> Prims.Tot (FStar.WellFoundedRelation.acc_classical FStar.WellFoundedRelation.empty_relation x)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nPartial implementation:\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y = empty_decreaser y in\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n min: Prims.nat ->\n max: Prims.nat{min <= max /\\ max < 4294967296} ->\n dlf: (_: ht -> LowParse.Spec.BoundedInt.bounded_int32 min max) ->\n ps: LowParse.Spec.Base.serializer pp ->\n h: ht ->\n input: LowParse.Bytes.bytes\n -> FStar.Pervasives.Lemma\n (ensures\n LowParse.Spec.Base.parse (LowParse.Spec.DepLen.parse_deplen_payload min max dlf ps h) input ==\n (match\n LowParse.Spec.Base.parse (LowParse.Spec.FLData.parse_fldata_strong ps\n (FStar.UInt32.v (dlf h)))\n input\n with\n | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None\n | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed) ->\n FStar.Pervasives.Native.Some\n (LowParse.Spec.DepLen.synth_deplen_data min max dlf ps h x,\n consumed)))\nEffect: FStar.Pervasives.Lemma\n\nContext:\nmodule LowParse.Spec.DepLen\n\n(* LowParse specification module for parsing structures with dependent length\n\n Example:\n\n struct {\n uint len;\n uint foo;\n uint buf[len];\n };\n\n*)\n\ninclude LowParse.Spec.Combinators\ninclude LowParse.Spec.AllIntegers\ninclude LowParse.Spec.VLGen\n\nmodule U32 = FStar.UInt32\nmodule Seq = FStar.Seq\n\n\n(* arguments\n\n @min :\n @max : integer bounds\n @ht : header type\n @hk : header parser metadata\n @hp : header parser\n @h : header data\n @dlf : dependent length function\n @pt : payload type\n @pk : payload parser metadata\n @pp : payload parser\n @ps : payload serializer\n @x : data\n\n*)\n\n(* data type of the dependent length parser, which is a pair of the header and the payload *)\n\nlet parse_deplen_data_t \n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n= x:(ht & pt) {U32.v (dlf (fst x)) == Seq.length (serialize ps (snd x) ) }\n\n\n(* the tag for a piece of dependent length data is just its header *)\n\nlet calc_tag_of_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (x : parse_deplen_data_t min max dlf ps)\n: GTot ht\n= fst x\n\n\n(* synth put the header and the payload together to get the data *)\n\nlet synth_deplen_data\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n (x : parse_fldata_strong_t ps (U32.v (dlf h)))\n: Tot (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h) \n= (h, x)\n\n\n(* metadata of the payload, reuse bounded_vlgen_payload *)\n\nlet parse_deplen_payload_kind = parse_bounded_vlgen_payload_kind\n\n\n(* parser spec for the dependent length payload which attaches the header to generate the data *)\n\nlet parse_deplen_payload\n (min : nat)\n (max : nat { min <= max /\\ max < 4294967296 } )\n (#ht : Type)\n (#pt : Type)\n (dlf : ht -> Tot (bounded_int32 min max) )\n (#pk : parser_kind)\n (#pp : parser pk pt)\n (ps : serializer pp)\n (h : ht)\n: Tot (parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)) \n= let sz = (U32.v (dlf h)) in\n let bounds_off =\n pk.parser_kind_low > sz || (\n match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz\n )\n in\n if bounds_off\n then fail_parser (parse_deplen_payload_kind min max pk) (refine_with_tag (calc_tag_of_deplen_data min max dlf ps) h)\n else\n weaken (parse_deplen_payload_kind min max pk)\n (parse_fldata_strong ps sz\n `parse_synth`\n synth_deplen_data min max dlf ps h)\n\n\n(* unfold is a more human readable version and do double-check of the definition\n\n This lemma says using the parser defined above is equivalent to using a fixed-length\n parser with the calculated size and then attach the header\n*)\n\nPartial implementation:\nlet parse_deplen_payload_unfold\n (min: nat)\n (max: nat{min <= max /\\ max < 4294967296})\n (#ht #pt: Type)\n (dlf: (ht -> Tot (bounded_int32 min max)))\n (#pk: parser_kind)\n (#pp: parser pk pt)\n (ps: serializer pp)\n (h: ht)\n (input: bytes)\n : Lemma\n (parse (parse_deplen_payload min max dlf ps h) input ==\n (match (parse (parse_fldata_strong ps (U32.v (dlf h))) input) with\n | None -> None\n | Some (x, consumed) -> Some (synth_deplen_data min max dlf ps h x, consumed))) =\n \n"
},
{
"role": "assistant",
"content": "let sz = (U32.v (dlf h)) in\nlet bounds_off =\n pk.parser_kind_low > sz ||\n (match pk.parser_kind_high with\n | None -> false\n | Some pkmax -> pkmax < sz)\nin\nif bounds_off\nthen ()\nelse parse_synth_eq (parse_fldata_strong ps sz) (synth_deplen_data min max dlf ps h) input"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: a\n -> Prims.Tot\n (FStar.WellFoundedRelation.acc_classical FStar.WellFoundedRelation.default_relation x)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nPartial implementation:\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\nin\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: a: Type\n -> wfr:\n FStar.WellFoundedRelation.wfr_t a\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.default_relation}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a {wfr.relation == default_relation}) =\n \n"
},
{
"role": "assistant",
"content": "let proof (x1 x2: a)\n : Lemma (requires default_relation x1 x2) (ensures default_decreaser x1 << default_decreaser x2)\n=\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\nin\n{ relation = default_relation; decreaser = default_decreaser; proof = proof }"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: a: Type\n -> wfr:\n FStar.WellFoundedRelation.wfr_t a\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.empty_relation}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a {wfr.relation == empty_relation}) =\n \n"
},
{
"role": "assistant",
"content": "let proof (x1 x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\nin\n{ relation = empty_relation; decreaser = empty_decreaser; proof = proof }"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: (_: a -> _: a -> Type0) ->\n f:\n FStar.WellFounded.well_founded r\n {forall (x1: a) (x2: a) (p: r x1 x2). AccIntro?.access_smaller (f x2) x1 p == f x1} ->\n x: a\n -> Prims.Tot\n (FStar.WellFoundedRelation.acc_classical (FStar.WellFoundedRelation.acc_relation r) x)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nPartial implementation:\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: (a -> a -> Type0))\n (f: WF.well_founded r {forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) =\n (eliminate exists (p: r y x).\n True\n returns f y << f x\n with _.\n assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y)\nin\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n t: Hacl.Bignum.Definitions.limb_t ->\n a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} ->\n modBits: Hacl.Impl.RSAPSS.modBits_t t\n -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Impl.RSAPSS\n\nopen FStar.HyperStack\nopen FStar.HyperStack.ST\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Buffer\n\nopen Hacl.Bignum.Definitions\n\nmodule ST = FStar.HyperStack.ST\n\nmodule Hash = Spec.Agile.Hash\nmodule SB = Hacl.Spec.Bignum\nmodule BB = Hacl.Spec.Bignum.Base\nmodule SD = Hacl.Spec.Bignum.Definitions\nmodule SM = Hacl.Spec.Bignum.Montgomery\nmodule SE = Hacl.Spec.Bignum.Exponentiation\n\nmodule BN = Hacl.Bignum\nmodule BE = Hacl.Bignum.Exponentiation\nmodule BM = Hacl.Bignum.Montgomery\n\nmodule S = Spec.RSAPSS\nmodule LS = Hacl.Spec.RSAPSS\nmodule LSeq = Lib.Sequence\n\nmodule RP = Hacl.Impl.RSAPSS.Padding\nmodule RM = Hacl.Impl.RSAPSS.MGF\nmodule RK = Hacl.Impl.RSAPSS.Keys\n\n#reset-options \"--z3rlimit 150 --fuel 0 --ifuel 0\"\n\ninline_for_extraction noextract\nlet modBits_t (t:limb_t) = modBits:size_t{1 < v modBits /\\ 2 * bits t * SD.blocks (v modBits) (bits t) <= max_size_t}\n\n\ninline_for_extraction noextract\nlet rsapss_sign_bn_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> m:lbignum t len\n -> m':lbignum t len\n -> s:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h skey /\\ live h m /\\ live h s /\\ live h m' /\\\n disjoint s m /\\ disjoint s skey /\\ disjoint m skey /\\\n disjoint m m' /\\ disjoint m' s /\\ disjoint m' skey /\\\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n bn_v h m < bn_v h (gsub skey 0ul len))\n (ensures fun h0 r h1 -> modifies (loc s |+| loc m') h0 h1 /\\\n (r, as_seq h1 s) == LS.rsapss_sign_bn (v modBits) (v eBits) (v dBits) (as_seq h0 skey) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_sign_bn: #t:limb_t -> ke:BE.exp t -> modBits:modBits_t t -> rsapss_sign_bn_st t ke modBits\nlet rsapss_sign_bn #t ke modBits eBits dBits skey m m' s =\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let eLen = blocks eBits (size bits) in\n let dLen = blocks dBits (size bits) in\n\n let n = sub skey 0ul nLen in\n let r2 = sub skey nLen nLen in\n let e = sub skey (nLen +! nLen) eLen in\n let d = sub skey (nLen +! nLen +! eLen) dLen in\n\n Math.Lemmas.pow2_le_compat (bits * v nLen) (v modBits);\n let h0 = ST.get () in\n SM.bn_precomp_r2_mod_n_lemma (v modBits - 1) (as_seq h0 n);\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_ct_precomp n r2 m dBits d s;\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_vt_precomp n r2 s eBits e m';\n let h1 = ST.get () in\n SD.bn_eval_inj (v nLen) (as_seq h1 s)\n (SE.bn_mod_exp_consttime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h0 m) (v dBits) (as_seq h0 d));\n SD.bn_eval_inj (v nLen) (as_seq h1 m')\n (SE.bn_mod_exp_vartime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h1 s) (v eBits) (as_seq h0 e));\n let eq_m = BN.bn_eq_mask nLen m m' in\n mapT nLen s (logand eq_m) s;\n BB.unsafe_bool_of_limb eq_m\n\n\ninline_for_extraction noextract\nlet rsapss_sign_msg_to_bn_st (t:limb_t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> m:lbignum t len ->\n Stack unit\n (requires fun h ->\n live h salt /\\ live h msg /\\ live h m /\\\n disjoint salt msg /\\ disjoint m msg /\\ disjoint m salt /\\\n as_seq h m == LSeq.create (v len) (uint #t 0) /\\\n LS.rsapss_sign_pre a (v modBits) (v saltLen) (as_seq h salt) (v msgLen) (as_seq h msg))\n (ensures fun h0 _ h1 -> modifies (loc m) h0 h1 /\\\n as_seq h1 m == LS.rsapss_sign_msg_to_bn a (v modBits) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg))\n\n\ninline_for_extraction noextract\nval rsapss_sign_msg_to_bn:\n #t:limb_t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_msg_to_bn_st t a modBits\n\nlet rsapss_sign_msg_to_bn #t a modBits saltLen salt msgLen msg m =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n\n let emBits = modBits -! 1ul in\n let emLen = blocks emBits 8ul in\n [@inline_let] let mLen = blocks emLen (size numb) in\n\n let em = create emLen (u8 0) in\n RP.pss_encode a saltLen salt msgLen msg emBits em;\n LS.blocks_bits_lemma t (v emBits);\n LS.blocks_numb_lemma t (v emBits);\n assert (SD.blocks (v emBits) bits = v mLen);\n assert (numb * v mLen <= max_size_t);\n assert (v mLen <= v nLen);\n\n let h' = ST.get () in\n update_sub_f h' m 0ul mLen\n (fun h -> SB.bn_from_bytes_be (v emLen) (as_seq h' em))\n (fun _ -> BN.bn_from_bytes_be emLen em (sub m 0ul mLen));\n pop_frame ()\n\n\ninline_for_extraction noextract\nlet rsapss_sign_compute_sgnt_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> m:lbignum t len\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h sgnt /\\ live h skey /\\ live h m /\\\n disjoint sgnt skey /\\ disjoint m sgnt /\\ disjoint m skey /\\\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n bn_v h m < bn_v h (gsub skey 0ul len))\n (ensures fun h0 eq_m h1 -> modifies (loc sgnt) h0 h1 /\\\n (eq_m, as_seq h1 sgnt) == LS.rsapss_sign_compute_sgnt (v modBits) (v eBits) (v dBits) (as_seq h0 skey) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_sign_compute_sgnt:\n #t:limb_t\n -> ke:BE.exp t\n -> modBits:modBits_t t ->\n rsapss_sign_compute_sgnt_st t ke modBits\n\nlet rsapss_sign_compute_sgnt #t ke modBits eBits dBits skey m sgnt =\n push_frame ();\n let h_init = ST.get () in\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n\n let k = blocks modBits 8ul in\n let s = create nLen (uint #t 0) in\n let m' = create nLen (uint #t 0) in\n let eq_b = rsapss_sign_bn ke modBits eBits dBits skey m m' s in\n LS.blocks_bits_lemma t (v modBits);\n LS.blocks_numb_lemma t (v modBits);\n assert (SD.blocks (v k) numb == v nLen);\n assert (numb * v nLen <= max_size_t);\n BN.bn_to_bytes_be k s sgnt;\n pop_frame ();\n eq_b\n\n\ninline_for_extraction noextract\nlet rsapss_sign_st1 (t:limb_t) (ke:BE.exp t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h salt /\\ live h msg /\\ live h sgnt /\\ live h skey /\\\n disjoint sgnt salt /\\ disjoint sgnt msg /\\ disjoint sgnt salt /\\ disjoint sgnt skey /\\\n disjoint salt msg /\\\n\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n LS.rsapss_sign_pre a (v modBits) (v saltLen) (as_seq h salt) (v msgLen) (as_seq h msg))\n (ensures fun h0 eq_m h1 -> modifies (loc sgnt) h0 h1 /\\\n (eq_m, as_seq h1 sgnt) == LS.rsapss_sign_ a (v modBits) (v eBits) (v dBits)\n (as_seq h0 skey) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg))\n\n\ninline_for_extraction noextract\nval rsapss_sign_:\n #t:limb_t\n -> ke:BE.exp t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_st1 t ke a modBits\n\nlet rsapss_sign_ #t ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let m = create nLen (uint #t 0) in\n rsapss_sign_msg_to_bn a modBits saltLen salt msgLen msg m;\n let eq_b = rsapss_sign_compute_sgnt ke modBits eBits dBits skey m sgnt in\n pop_frame ();\n eq_b\n\n\ninline_for_extraction noextract\nlet rsapss_sign_st (t:limb_t) (ke:BE.exp t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h salt /\\ live h msg /\\ live h sgnt /\\ live h skey /\\\n disjoint sgnt salt /\\ disjoint sgnt msg /\\ disjoint sgnt salt /\\ disjoint sgnt skey /\\\n disjoint salt msg /\\\n\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey))\n (ensures fun h0 b h1 -> modifies (loc sgnt) h0 h1 /\\\n (b, as_seq h1 sgnt) == LS.rsapss_sign a (v modBits) (v eBits) (v dBits)\n (as_seq h0 skey) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg) (as_seq h0 sgnt))\n\n\ninline_for_extraction noextract\nval rsapss_sign:\n #t:limb_t\n -> ke:BE.exp t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_st t ke a modBits\n\nlet rsapss_sign #t ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt =\n let hLen = RM.hash_len a in\n Math.Lemmas.pow2_lt_compat 61 32;\n Math.Lemmas.pow2_lt_compat 125 32;\n //assert (max_size_t < Hash.max_input_length a);\n\n let b =\n saltLen <=. 0xfffffffful -! hLen -! 8ul &&\n saltLen +! hLen +! 2ul <=. blocks (modBits -! 1ul) 8ul in\n\n if b then\n rsapss_sign_ ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt\n else\n false\n\n\n\ninline_for_extraction noextract\nval bn_lt_pow2:\n #t:limb_t\n -> modBits:size_t{1 < v modBits}\n -> m:lbignum t (blocks modBits (size (bits t))) ->\n Stack bool\n (requires fun h -> live h m)\n (ensures fun h0 r h1 -> h0 == h1 /\\\n r == LS.bn_lt_pow2 (v modBits) (as_seq h0 m))\n\nlet bn_lt_pow2 #t modBits m =\n if not ((modBits -! 1ul) %. 8ul =. 0ul) then true\n else begin\n let get_bit = BN.bn_get_ith_bit (blocks modBits (size (bits t))) m (modBits -! 1ul) in\n BB.unsafe_bool_of_limb0 get_bit end\n\n\ninline_for_extraction noextract\nlet rsapss_verify_bn_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t{LS.pkey_len_pre t (v modBits) (v eBits)}\n -> pkey:lbignum t (2ul *! len +! blocks eBits (size (bits t)))\n -> m_def:lbignum t len\n -> s:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h pkey /\\ live h m_def /\\ live h s /\\\n disjoint m_def pkey /\\ disjoint m_def s /\\ disjoint s pkey /\\\n LS.rsapss_pkey_pre (v modBits) (v eBits) (as_seq h pkey))\n (ensures fun h0 r h1 -> modifies (loc m_def) h0 h1 /\\\n (r, as_seq h1 m_def) == LS.rsapss_verify_bn (v modBits) (v eBits) (as_seq h0 pkey) (as_seq h0 m_def) (as_seq h0 s))\n\n\ninline_for_extraction noextract\nval rsapss_verify_bn: #t:limb_t -> ke:BE.exp t -> modBits:modBits_t t -> rsapss_verify_bn_st t ke modBits\nlet rsapss_verify_bn #t ke modBits eBits pkey m_def s =\n [@inline_let] let bits = size (bits t) in\n let nLen = blocks modBits bits in\n let eLen = blocks eBits bits in\n\n let n = sub pkey 0ul nLen in\n let r2 = sub pkey nLen nLen in\n let e = sub pkey (nLen +! nLen) eLen in\n\n let mask = BN.bn_lt_mask nLen s n in\n let h = ST.get () in\n SB.bn_lt_mask_lemma (as_seq h s) (as_seq h n);\n\n let res =\n if BB.unsafe_bool_of_limb mask then begin\n Math.Lemmas.pow2_le_compat (v bits * v nLen) (v modBits);\n SM.bn_precomp_r2_mod_n_lemma (v modBits - 1) (as_seq h n);\n\n let h0 = ST.get () in\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_vt_precomp n r2 s eBits e m_def;\n let h1 = ST.get () in\n SD.bn_eval_inj (v nLen) (as_seq h1 m_def)\n (SE.bn_mod_exp_vartime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h1 s) (v eBits) (as_seq h0 e));\n\n if bn_lt_pow2 modBits m_def then true\n else false end\n else false in\n res\n\nPartial implementation:\nlet rsapss_verify_bn_to_msg_st\n (t: limb_t)\n (a: Hash.hash_alg{S.hash_is_supported a})\n (modBits: modBits_t t)\n =\n \n"
},
{
"role": "assistant",
"content": "\n saltLen: size_t ->\n msgLen: size_t ->\n msg: lbuffer uint8 msgLen ->\n m: lbignum t (blocks modBits (size (bits t)))\n -> Stack bool\n (requires\n fun h ->\n live h msg /\\ live h m /\\ disjoint m msg /\\\n LS.rsapss_verify_pre a (v saltLen) (v msgLen) (as_seq h msg))\n (ensures\n fun h0 r h1 ->\n modifies0 h0 h1 /\\\n r ==\n LS.rsapss_verify_bn_to_msg a\n (v modBits)\n (v saltLen)\n (v msgLen)\n (as_seq h0 msg)\n (as_seq h0 m))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: x: t -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term\nEffect: FStar.Tactics.Effect.Tac\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 Normalization\n\nopen FStar.Tactics.V2\n\n(* A tactic that returns its argument after some steps of normalization *)\n(* NOTE: This is relying on our unusual quote, which can inspect the shape of `x`\n * when the function is applied. This could be avoided by taking a `term` instead\n * and calling the tactic it with `quote` *)\nlet normalize (#t:Type) (steps : list norm_step) (x:t) : Tac unit =\n dup ();\n exact (quote x);\n norm steps;\n trefl ()\n\nPartial implementation:\nlet def_of (#t: Type) (x: t) : Tac term =\n \n"
},
{
"role": "assistant",
"content": "let e = cur_env () in\nlet t = quote x in\nmatch inspect t with\n| Tv_UInst fv _\n| Tv_FVar fv ->\n let se =\n match lookup_typ e (inspect_fv fv) with\n | None -> fail \"Not found..?\"\n | Some se -> se\n in\n (match inspect_sigelt se with\n | Sg_Let { lbs = lbs } ->\n let lbv = lookup_lb lbs (inspect_fv fv) in\n lbv.lb_def\n | _ -> fail \"not a sig_let\")\n| _ -> fail \"not an fvar\""
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.Base.td\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n\nPartial implementation:\nlet t64_no_mod =\n \n"
},
{
"role": "assistant",
"content": "TD_Buffer TUInt64 TUInt64 ({ modified = false; strict_disjointness = false; taint = MS.Secret })"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: _ -> Prims.bool\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nPartial implementation:\nlet add1_xmms_modified =\n \n"
},
{
"role": "assistant",
"content": "fun _ -> false"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.eqtype\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nPartial implementation:\nlet uint64 =\n \n"
},
{
"role": "assistant",
"content": "UInt64.t"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.Base.td\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n\nPartial implementation:\nlet tuint64 =\n \n"
},
{
"role": "assistant",
"content": "TD_Base TUInt64"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: r: Vale.X64.Machine_s.reg_64 -> FStar.Pervasives.Native.option (Vale.Interop.X64.reg_nat 3)\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nlet code_add1 = FU.va_code_Fast_add1 ()\n\nPartial implementation:\nlet of_reg (r: MS.reg_64) : option (IX64.reg_nat 3) =\n \n"
},
{
"role": "assistant",
"content": "match r with\n| 5 -> Some 0\n| 4 -> Some 1\n| 3 -> Some 2\n| _ -> None"
}
] |
[
{
"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 FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\nPartial implementation:\nlet b64 =\n \n"
},
{
"role": "assistant",
"content": "buf_t TUInt64 TUInt64"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: r: (_: a -> _: a -> Type0) -> f: FStar.WellFounded.well_founded r\n -> wfr:\n FStar.WellFoundedRelation.wfr_t a\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.acc_relation r}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nPartial implementation:\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a {wfr.relation == acc_relation r}) =\n \n"
},
{
"role": "assistant",
"content": "let f = eta_expand_well_founded r f in\nlet proof (x1 x2: a)\n : Lemma (requires acc_relation r x1 x2) (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\nin\n{ relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof }"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: (_: a -> _: a -> Type0) ->\n wfr:\n FStar.WellFoundedRelation.wfr_t a\n {forall (x1: a) (x2: a). r x1 x2 ==> Mkwfr_t?.relation wfr x1 x2}\n -> wfr': FStar.WellFoundedRelation.wfr_t a {Mkwfr_t?.relation wfr' == r}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet subrelation_to_wfr\n (#a: Type u#a)\n (r: (a -> a -> Type0))\n (wfr: wfr_t a {forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a {wfr'.relation == r}) =\n \n"
},
{
"role": "assistant",
"content": "let proof (x1 x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\nin\n{ relation = r; decreaser = subrelation_decreaser r wfr; proof = proof }"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.X64.Decls.va_code\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nPartial implementation:\nlet code_add1 =\n \n"
},
{
"role": "assistant",
"content": "FU.va_code_Fast_add1 ()"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.Interop.Base.td\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n\nPartial implementation:\nlet t64_mod =\n \n"
},
{
"role": "assistant",
"content": "TD_Buffer TUInt64 TUInt64 default_bq"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: (_: a -> _: a -> Type0) ->\n wfr:\n FStar.WellFoundedRelation.wfr_t a\n {forall (x1: a) (x2: a). r x1 x2 ==> Mkwfr_t?.relation wfr x1 x2} ->\n x: a\n -> Prims.Tot (FStar.WellFoundedRelation.acc_classical r x)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nPartial implementation:\nlet rec subrelation_decreaser\n (#a: Type u#a)\n (r: (a -> a -> Type0))\n (wfr: wfr_t a {forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (y: a{r y x}) : (acc_classical r y) = subrelation_decreaser r wfr y in\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: (_: a -> _: a -> Type0) ->\n f: (_: a -> b) ->\n wfr:\n FStar.WellFoundedRelation.wfr_t b\n {forall (x1: a) (x2: a). r x1 x2 ==> Mkwfr_t?.relation wfr (f x1) (f x2)}\n -> wfr': FStar.WellFoundedRelation.wfr_t a {Mkwfr_t?.relation wfr' == r}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet inverse_image_to_wfr\n (#a: Type u#a)\n (#b: Type u#b)\n (r: (a -> a -> Type0))\n (f: (a -> b))\n (wfr: wfr_t b {forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a {wfr'.relation == r}) =\n \n"
},
{
"role": "assistant",
"content": "let proof (x1 x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\nin\n{ relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof }"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n r: (_: a -> _: a -> Type0) ->\n f: (_: a -> b) ->\n wfr:\n FStar.WellFoundedRelation.wfr_t b\n {forall (x1: a) (x2: a). r x1 x2 ==> Mkwfr_t?.relation wfr (f x1) (f x2)} ->\n x: a\n -> Prims.Tot (FStar.WellFoundedRelation.acc_classical r x)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nPartial implementation:\nlet rec inverse_image_decreaser\n (#a: Type u#a)\n (#b: Type u#b)\n (r: (a -> a -> Type0))\n (f: (a -> b))\n (wfr: wfr_t b {forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (y: a{r y x}) : (acc_classical r y) = inverse_image_decreaser r f wfr y in\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: wfr_a: FStar.WellFoundedRelation.wfr_t a -> wfr_b: FStar.WellFoundedRelation.wfr_t b\n -> wfr:\n FStar.WellFoundedRelation.wfr_t (a * b)\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.lex_nondep_relation wfr_a wfr_b}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nlet inverse_image_to_wfr (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\n in\n { relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof; }\n\nlet rec lex_nondep_decreaser (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n (xy: a * b)\n : Tot (acc_classical (lex_nondep_relation wfr_a wfr_b) xy)\n (decreases %[wfr_a.decreaser (fst xy); wfr_b.decreaser (snd xy)]) =\n let smaller (xy': a * b{lex_nondep_relation wfr_a wfr_b xy' xy})\n : (acc_classical (lex_nondep_relation wfr_a wfr_b) xy') =\n lex_nondep_decreaser wfr_a wfr_b xy'\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n : wfr: wfr_t (a * b) {wfr.relation == lex_nondep_relation wfr_a wfr_b} =\n \n"
},
{
"role": "assistant",
"content": "let proof (xy1 xy2: a * b)\n : Lemma (requires lex_nondep_relation wfr_a wfr_b xy1 xy2)\n (ensures lex_nondep_decreaser wfr_a wfr_b xy1 << lex_nondep_decreaser wfr_a wfr_b xy2) =\n assert ((lex_nondep_decreaser wfr_a wfr_b xy2).access_smaller xy1 ==\n lex_nondep_decreaser wfr_a wfr_b xy1)\nin\n{\n relation = lex_nondep_relation wfr_a wfr_b;\n decreaser = lex_nondep_decreaser wfr_a wfr_b;\n proof = proof\n}"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: _: _ -> Prims.bool\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nlet code_add1 = FU.va_code_Fast_add1 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the add1 wrapper *)\n[@__reduce__]\nlet lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\n(* And here's the add1 wrapper itself *)\nlet lowstar_add1 : lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.wrap_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\nlet lowstar_add1_normal_t : normal lowstar_add1_t\n = as_normal_t #lowstar_add1_t lowstar_add1\n\nopen Vale.AsLowStar.MemoryHelpers\n\nlet add_scalar out f1 f2\n = DV.length_eq (get_downview out);\n DV.length_eq (get_downview f1);\n let (x, _) = lowstar_add1_normal_t out f1 f2 () in\n x\n\nlet add1_comments : list string =\n [\"Computes the addition of four-element f1 with value in f2\"; \"and returns the carry (if any)\"]\n\nlet add1_names (n:nat) =\n match n with\n | 0 -> \"out\"\n | 1 -> \"f1\"\n | 2 -> \"f2\"\n | _ -> \"\"\n\nlet add1_code_inline () : FStar.All.ML int =\n PR.print_inline \"add_scalar\" 0 None (List.length dom) dom add1_names code_add1 of_arg add1_regs_modified add1_comments\n\n\n[@__reduce__]\nlet fadd_dom: IX64.arity_ok_stdcall td =\n let y = [t64_mod; t64_no_mod; t64_no_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet fadd_pre : VSig.vale_pre fadd_dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:b64)\n (va_s0:V.va_state) ->\n FH.va_req_Fadd c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (as_vale_buffer f2)\n\n[@__reduce__]\nlet fadd_post : VSig.vale_post fadd_dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:b64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FH.va_ens_Fadd c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (as_vale_buffer f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet fadd_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRcx || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nPartial implementation:\nlet fadd_xmms_modified =\n \n"
},
{
"role": "assistant",
"content": "fun _ -> false"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: n: Prims.nat -> Prims.string\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nlet code_add1 = FU.va_code_Fast_add1 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the add1 wrapper *)\n[@__reduce__]\nlet lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\n(* And here's the add1 wrapper itself *)\nlet lowstar_add1 : lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.wrap_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\nlet lowstar_add1_normal_t : normal lowstar_add1_t\n = as_normal_t #lowstar_add1_t lowstar_add1\n\nopen Vale.AsLowStar.MemoryHelpers\n\nlet add_scalar out f1 f2\n = DV.length_eq (get_downview out);\n DV.length_eq (get_downview f1);\n let (x, _) = lowstar_add1_normal_t out f1 f2 () in\n x\n\nlet add1_comments : list string =\n [\"Computes the addition of four-element f1 with value in f2\"; \"and returns the carry (if any)\"]\n\nPartial implementation:\nlet add1_names (n: nat) =\n \n"
},
{
"role": "assistant",
"content": "match n with\n| 0 -> \"out\"\n| 1 -> \"f1\"\n| 2 -> \"f2\"\n| _ -> \"\""
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: wfr_a: FStar.WellFoundedRelation.wfr_t a -> wfr_b: FStar.WellFoundedRelation.wfr_t b -> xy: (a * b)\n -> Prims.Tot\n (FStar.WellFoundedRelation.acc_classical (FStar.WellFoundedRelation.lex_nondep_relation wfr_a\n wfr_b)\n xy)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nlet inverse_image_to_wfr (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\n in\n { relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof; }\n\nPartial implementation:\nlet rec lex_nondep_decreaser\n (#a: Type u#a)\n (#b: Type u#b)\n (wfr_a: wfr_t a)\n (wfr_b: wfr_t b)\n (xy: a * b)\n : Tot (acc_classical (lex_nondep_relation wfr_a wfr_b) xy)\n (decreases %[wfr_a.decreaser (fst xy);wfr_b.decreaser (snd xy)]) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (xy': (a * b) {lex_nondep_relation wfr_a wfr_b xy' xy})\n : (acc_classical (lex_nondep_relation wfr_a wfr_b) xy') =\n lex_nondep_decreaser wfr_a wfr_b xy'\nin\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Prims.list Prims.string\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nlet code_add1 = FU.va_code_Fast_add1 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the add1 wrapper *)\n[@__reduce__]\nlet lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\n(* And here's the add1 wrapper itself *)\nlet lowstar_add1 : lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.wrap_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\nlet lowstar_add1_normal_t : normal lowstar_add1_t\n = as_normal_t #lowstar_add1_t lowstar_add1\n\nopen Vale.AsLowStar.MemoryHelpers\n\nlet add_scalar out f1 f2\n = DV.length_eq (get_downview out);\n DV.length_eq (get_downview f1);\n let (x, _) = lowstar_add1_normal_t out f1 f2 () in\n x\n\nPartial implementation:\nlet add1_comments:list string =\n \n"
},
{
"role": "assistant",
"content": "[\"Computes the addition of four-element f1 with value in f2\"; \"and returns the carry (if any)\"]"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: wfr:\nFStar.WellFoundedRelation.wfr_t Prims.bool\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.bool_relation}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nlet inverse_image_to_wfr (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\n in\n { relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof; }\n\nlet rec lex_nondep_decreaser (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n (xy: a * b)\n : Tot (acc_classical (lex_nondep_relation wfr_a wfr_b) xy)\n (decreases %[wfr_a.decreaser (fst xy); wfr_b.decreaser (snd xy)]) =\n let smaller (xy': a * b{lex_nondep_relation wfr_a wfr_b xy' xy})\n : (acc_classical (lex_nondep_relation wfr_a wfr_b) xy') =\n lex_nondep_decreaser wfr_a wfr_b xy'\n in\n AccClassicalIntro smaller\n\nlet lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n : wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b} =\n let proof (xy1: a * b) (xy2: a * b)\n : Lemma (requires lex_nondep_relation wfr_a wfr_b xy1 xy2)\n (ensures lex_nondep_decreaser wfr_a wfr_b xy1 <<\n lex_nondep_decreaser wfr_a wfr_b xy2) =\n assert ((lex_nondep_decreaser wfr_a wfr_b xy2).access_smaller xy1 ==\n lex_nondep_decreaser wfr_a wfr_b xy1)\n in\n { relation = lex_nondep_relation wfr_a wfr_b;\n decreaser = lex_nondep_decreaser wfr_a wfr_b;\n proof = proof; }\n\nlet rec lex_dep_decreaser (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)\n (a_to_wfr_b: (x: a -> wfr_t (b x))) (xy: (x: a & b x))\n : Tot (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy)\n (decreases %[wfr_a.decreaser (dfst xy); (a_to_wfr_b (dfst xy)).decreaser (dsnd xy)]) =\n let smaller (xy': (x: a & b x){lex_dep_relation wfr_a a_to_wfr_b xy' xy})\n : (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy') =\n lex_dep_decreaser wfr_a a_to_wfr_b xy'\n in\n AccClassicalIntro smaller\n\nlet lex_dep_wfr (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)\n (a_to_wfr_b: (x: a -> wfr_t (b x)))\n : wfr: wfr_t (x: a & b x){wfr.relation == lex_dep_relation wfr_a a_to_wfr_b} =\n let proof (xy1: (x: a & b x)) (xy2: (x: a & b x))\n : Lemma (requires lex_dep_relation wfr_a a_to_wfr_b xy1 xy2)\n (ensures lex_dep_decreaser wfr_a a_to_wfr_b xy1 <<\n lex_dep_decreaser wfr_a a_to_wfr_b xy2) =\n assert ((lex_dep_decreaser wfr_a a_to_wfr_b xy2).access_smaller xy1 ==\n lex_dep_decreaser wfr_a a_to_wfr_b xy1)\n in\n { relation = lex_dep_relation wfr_a a_to_wfr_b;\n decreaser = lex_dep_decreaser wfr_a a_to_wfr_b;\n proof = proof; }\n\nPartial implementation:\nlet bool_wfr:(wfr: wfr_t bool {wfr.relation == bool_relation}) =\n \n"
},
{
"role": "assistant",
"content": "inverse_image_to_wfr #bool #nat bool_relation (fun b -> if b then 1 else 0) (default_wfr nat)"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n wfr_a: FStar.WellFoundedRelation.wfr_t a ->\n a_to_wfr_b: (x: a -> FStar.WellFoundedRelation.wfr_t (b x)) ->\n xy: Prims.dtuple2 a (fun x -> b x)\n -> Prims.Tot\n (FStar.WellFoundedRelation.acc_classical (FStar.WellFoundedRelation.lex_dep_relation wfr_a\n a_to_wfr_b)\n xy)\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nlet inverse_image_to_wfr (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\n in\n { relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof; }\n\nlet rec lex_nondep_decreaser (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n (xy: a * b)\n : Tot (acc_classical (lex_nondep_relation wfr_a wfr_b) xy)\n (decreases %[wfr_a.decreaser (fst xy); wfr_b.decreaser (snd xy)]) =\n let smaller (xy': a * b{lex_nondep_relation wfr_a wfr_b xy' xy})\n : (acc_classical (lex_nondep_relation wfr_a wfr_b) xy') =\n lex_nondep_decreaser wfr_a wfr_b xy'\n in\n AccClassicalIntro smaller\n\nlet lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n : wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b} =\n let proof (xy1: a * b) (xy2: a * b)\n : Lemma (requires lex_nondep_relation wfr_a wfr_b xy1 xy2)\n (ensures lex_nondep_decreaser wfr_a wfr_b xy1 <<\n lex_nondep_decreaser wfr_a wfr_b xy2) =\n assert ((lex_nondep_decreaser wfr_a wfr_b xy2).access_smaller xy1 ==\n lex_nondep_decreaser wfr_a wfr_b xy1)\n in\n { relation = lex_nondep_relation wfr_a wfr_b;\n decreaser = lex_nondep_decreaser wfr_a wfr_b;\n proof = proof; }\n\nPartial implementation:\nlet rec lex_dep_decreaser\n (#a: Type u#a)\n (#b: (a -> Type u#b))\n (wfr_a: wfr_t a)\n (a_to_wfr_b: (x: a -> wfr_t (b x)))\n (xy: (x: a & b x))\n : Tot (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy)\n (decreases %[wfr_a.decreaser (dfst xy);(a_to_wfr_b (dfst xy)).decreaser (dsnd xy)]) =\n \n"
},
{
"role": "assistant",
"content": "let smaller (xy': (x: a & b x){lex_dep_relation wfr_a a_to_wfr_b xy' xy})\n : (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy') =\n lex_dep_decreaser wfr_a a_to_wfr_b xy'\nin\nAccClassicalIntro smaller"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: Vale.AsLowStar.ValeSig.vale_post Vale.Inline.X64.Fadd_inline.fadd_dom\nEffect: Prims.Tot\n\nContext:\nmodule Vale.Inline.X64.Fadd_inline\n\nopen FStar.Mul\nopen FStar.HyperStack.ST\nmodule HS = FStar.HyperStack\nmodule B = LowStar.Buffer\nmodule DV = LowStar.BufferView.Down\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\nmodule PR = Vale.X64.Print_Inline_s\n\nmodule FU = Vale.Curve25519.X64.FastUtil\nmodule FH = Vale.Curve25519.X64.FastHybrid\nmodule FW = Vale.Curve25519.X64.FastWide\n\nlet uint64 = UInt64.t\n\n(* A little utility to trigger normalization in types *)\nlet as_t (#a:Type) (x:normal a) : a = x\nlet as_normal_t (#a:Type) (x:a) : normal a = x\n\n[@__reduce__]\nlet b64 = buf_t TUInt64 TUInt64\n[@__reduce__]\nlet t64_mod = TD_Buffer TUInt64 TUInt64 default_bq\n[@__reduce__]\nlet t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})\n[@__reduce__]\nlet tuint64 = TD_Base TUInt64\n\n[@__reduce__]\nlet dom: IX64.arity_ok 3 td =\n let y = [t64_mod; t64_no_mod; tuint64] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet add1_pre : VSig.vale_pre dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state) ->\n FU.va_req_Fast_add1 c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)\n\n[@__reduce__]\nlet add1_post : VSig.vale_post dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n (va_s1:V.va_state)\n (f:V.va_fuel) ->\n FU.va_ens_Fast_add1 c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f\n\n#set-options \"--z3rlimit 50\"\n\nlet add1_regs_modified: MS.reg_64 -> bool = fun (r:MS.reg_64) ->\n let open MS in\n if r = rRax || r = rRdx || r = rR8 || r = rR9 || r = rR10 || r = rR11 then true\n else false\n\nlet add1_xmms_modified = fun _ -> false\n\n[@__reduce__]\nlet add1_lemma'\n (code:V.va_code)\n (_win:bool)\n (out:b64)\n (f1:b64)\n (f2:uint64)\n (va_s0:V.va_state)\n : Ghost (V.va_state & V.va_fuel)\n (requires\n add1_pre code out f1 f2 va_s0)\n (ensures (fun (va_s1, f) ->\n V.eval_code code va_s0 f va_s1 /\\\n VSig.vale_calling_conventions va_s0 va_s1 add1_regs_modified add1_xmms_modified /\\\n add1_post code out f1 f2 va_s0 va_s1 f /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\\\n ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer out) /\\\n ME.buffer_writeable (as_vale_buffer f1) /\\\n ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))\n ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)\n )) =\n let va_s1, f = FU.va_lemma_Fast_add1 code va_s0 (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;\n Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;\n (va_s1, f)\n\n(* Prove that add1_lemma' has the required type *)\nlet add1_lemma = as_t #(VSig.vale_sig add1_regs_modified add1_xmms_modified add1_pre add1_post) add1_lemma'\n\nlet code_add1 = FU.va_code_Fast_add1 ()\n\nlet of_reg (r:MS.reg_64) : option (IX64.reg_nat 3) = match r with\n | 5 -> Some 0 // rdi\n | 4 -> Some 1 // rsi\n | 3 -> Some 2 // rdx\n | _ -> None\n\nlet of_arg (i:IX64.reg_nat 3) : MS.reg_64 = match i with\n | 0 -> MS.rRdi\n | 1 -> MS.rRsi\n | 2 -> MS.rRdx\n\nlet arg_reg : IX64.arg_reg_relation 3 = IX64.Rel of_reg of_arg\n\n(* Here's the type expected for the add1 wrapper *)\n[@__reduce__]\nlet lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.as_lowstar_sig_t_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n []\n _\n _\n // The boolean here doesn't matter\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\n(* And here's the add1 wrapper itself *)\nlet lowstar_add1 : lowstar_add1_t =\n assert_norm (List.length dom + List.length ([]<:list arg) <= 3);\n IX64.wrap_weak\n 3\n arg_reg\n add1_regs_modified\n add1_xmms_modified\n code_add1\n dom\n (W.mk_prediction code_add1 dom [] (add1_lemma code_add1 IA.win))\n\nlet lowstar_add1_normal_t : normal lowstar_add1_t\n = as_normal_t #lowstar_add1_t lowstar_add1\n\nopen Vale.AsLowStar.MemoryHelpers\n\nlet add_scalar out f1 f2\n = DV.length_eq (get_downview out);\n DV.length_eq (get_downview f1);\n let (x, _) = lowstar_add1_normal_t out f1 f2 () in\n x\n\nlet add1_comments : list string =\n [\"Computes the addition of four-element f1 with value in f2\"; \"and returns the carry (if any)\"]\n\nlet add1_names (n:nat) =\n match n with\n | 0 -> \"out\"\n | 1 -> \"f1\"\n | 2 -> \"f2\"\n | _ -> \"\"\n\nlet add1_code_inline () : FStar.All.ML int =\n PR.print_inline \"add_scalar\" 0 None (List.length dom) dom add1_names code_add1 of_arg add1_regs_modified add1_comments\n\n\n[@__reduce__]\nlet fadd_dom: IX64.arity_ok_stdcall td =\n let y = [t64_mod; t64_no_mod; t64_no_mod] in\n assert_norm (List.length y = 3);\n y\n\n(* Need to rearrange the order of arguments *)\n[@__reduce__]\nlet fadd_pre : VSig.vale_pre fadd_dom =\n fun (c:V.va_code)\n (out:b64)\n (f1:b64)\n (f2:b64)\n (va_s0:V.va_state) ->\n FH.va_req_Fadd c va_s0\n (as_vale_buffer out) (as_vale_buffer f1) (as_vale_buffer f2)\n\nPartial implementation:\nlet fadd_post:VSig.vale_post fadd_dom =\n \n"
},
{
"role": "assistant",
"content": "fun\n (c: V.va_code)\n (out: b64)\n (f1: b64)\n (f2: b64)\n (va_s0: V.va_state)\n (va_s1: V.va_state)\n (f: V.va_fuel)\n ->\n FH.va_ens_Fadd c va_s0 (as_vale_buffer out) (as_vale_buffer f1) (as_vale_buffer f2) va_s1 f"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n t: Hacl.Bignum.Definitions.limb_t ->\n ke: Hacl.Bignum.Exponentiation.exp t ->\n a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} ->\n modBits: Hacl.Impl.RSAPSS.modBits_t t\n -> Type0\nEffect: Prims.Tot\n\nContext:\nmodule Hacl.Impl.RSAPSS\n\nopen FStar.HyperStack\nopen FStar.HyperStack.ST\nopen FStar.Mul\n\nopen Lib.IntTypes\nopen Lib.Buffer\n\nopen Hacl.Bignum.Definitions\n\nmodule ST = FStar.HyperStack.ST\n\nmodule Hash = Spec.Agile.Hash\nmodule SB = Hacl.Spec.Bignum\nmodule BB = Hacl.Spec.Bignum.Base\nmodule SD = Hacl.Spec.Bignum.Definitions\nmodule SM = Hacl.Spec.Bignum.Montgomery\nmodule SE = Hacl.Spec.Bignum.Exponentiation\n\nmodule BN = Hacl.Bignum\nmodule BE = Hacl.Bignum.Exponentiation\nmodule BM = Hacl.Bignum.Montgomery\n\nmodule S = Spec.RSAPSS\nmodule LS = Hacl.Spec.RSAPSS\nmodule LSeq = Lib.Sequence\n\nmodule RP = Hacl.Impl.RSAPSS.Padding\nmodule RM = Hacl.Impl.RSAPSS.MGF\nmodule RK = Hacl.Impl.RSAPSS.Keys\n\n#reset-options \"--z3rlimit 150 --fuel 0 --ifuel 0\"\n\ninline_for_extraction noextract\nlet modBits_t (t:limb_t) = modBits:size_t{1 < v modBits /\\ 2 * bits t * SD.blocks (v modBits) (bits t) <= max_size_t}\n\n\ninline_for_extraction noextract\nlet rsapss_sign_bn_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> m:lbignum t len\n -> m':lbignum t len\n -> s:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h skey /\\ live h m /\\ live h s /\\ live h m' /\\\n disjoint s m /\\ disjoint s skey /\\ disjoint m skey /\\\n disjoint m m' /\\ disjoint m' s /\\ disjoint m' skey /\\\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n bn_v h m < bn_v h (gsub skey 0ul len))\n (ensures fun h0 r h1 -> modifies (loc s |+| loc m') h0 h1 /\\\n (r, as_seq h1 s) == LS.rsapss_sign_bn (v modBits) (v eBits) (v dBits) (as_seq h0 skey) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_sign_bn: #t:limb_t -> ke:BE.exp t -> modBits:modBits_t t -> rsapss_sign_bn_st t ke modBits\nlet rsapss_sign_bn #t ke modBits eBits dBits skey m m' s =\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let eLen = blocks eBits (size bits) in\n let dLen = blocks dBits (size bits) in\n\n let n = sub skey 0ul nLen in\n let r2 = sub skey nLen nLen in\n let e = sub skey (nLen +! nLen) eLen in\n let d = sub skey (nLen +! nLen +! eLen) dLen in\n\n Math.Lemmas.pow2_le_compat (bits * v nLen) (v modBits);\n let h0 = ST.get () in\n SM.bn_precomp_r2_mod_n_lemma (v modBits - 1) (as_seq h0 n);\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_ct_precomp n r2 m dBits d s;\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_vt_precomp n r2 s eBits e m';\n let h1 = ST.get () in\n SD.bn_eval_inj (v nLen) (as_seq h1 s)\n (SE.bn_mod_exp_consttime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h0 m) (v dBits) (as_seq h0 d));\n SD.bn_eval_inj (v nLen) (as_seq h1 m')\n (SE.bn_mod_exp_vartime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h1 s) (v eBits) (as_seq h0 e));\n let eq_m = BN.bn_eq_mask nLen m m' in\n mapT nLen s (logand eq_m) s;\n BB.unsafe_bool_of_limb eq_m\n\n\ninline_for_extraction noextract\nlet rsapss_sign_msg_to_bn_st (t:limb_t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> m:lbignum t len ->\n Stack unit\n (requires fun h ->\n live h salt /\\ live h msg /\\ live h m /\\\n disjoint salt msg /\\ disjoint m msg /\\ disjoint m salt /\\\n as_seq h m == LSeq.create (v len) (uint #t 0) /\\\n LS.rsapss_sign_pre a (v modBits) (v saltLen) (as_seq h salt) (v msgLen) (as_seq h msg))\n (ensures fun h0 _ h1 -> modifies (loc m) h0 h1 /\\\n as_seq h1 m == LS.rsapss_sign_msg_to_bn a (v modBits) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg))\n\n\ninline_for_extraction noextract\nval rsapss_sign_msg_to_bn:\n #t:limb_t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_msg_to_bn_st t a modBits\n\nlet rsapss_sign_msg_to_bn #t a modBits saltLen salt msgLen msg m =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n\n let emBits = modBits -! 1ul in\n let emLen = blocks emBits 8ul in\n [@inline_let] let mLen = blocks emLen (size numb) in\n\n let em = create emLen (u8 0) in\n RP.pss_encode a saltLen salt msgLen msg emBits em;\n LS.blocks_bits_lemma t (v emBits);\n LS.blocks_numb_lemma t (v emBits);\n assert (SD.blocks (v emBits) bits = v mLen);\n assert (numb * v mLen <= max_size_t);\n assert (v mLen <= v nLen);\n\n let h' = ST.get () in\n update_sub_f h' m 0ul mLen\n (fun h -> SB.bn_from_bytes_be (v emLen) (as_seq h' em))\n (fun _ -> BN.bn_from_bytes_be emLen em (sub m 0ul mLen));\n pop_frame ()\n\n\ninline_for_extraction noextract\nlet rsapss_sign_compute_sgnt_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> m:lbignum t len\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h sgnt /\\ live h skey /\\ live h m /\\\n disjoint sgnt skey /\\ disjoint m sgnt /\\ disjoint m skey /\\\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n bn_v h m < bn_v h (gsub skey 0ul len))\n (ensures fun h0 eq_m h1 -> modifies (loc sgnt) h0 h1 /\\\n (eq_m, as_seq h1 sgnt) == LS.rsapss_sign_compute_sgnt (v modBits) (v eBits) (v dBits) (as_seq h0 skey) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_sign_compute_sgnt:\n #t:limb_t\n -> ke:BE.exp t\n -> modBits:modBits_t t ->\n rsapss_sign_compute_sgnt_st t ke modBits\n\nlet rsapss_sign_compute_sgnt #t ke modBits eBits dBits skey m sgnt =\n push_frame ();\n let h_init = ST.get () in\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n\n let k = blocks modBits 8ul in\n let s = create nLen (uint #t 0) in\n let m' = create nLen (uint #t 0) in\n let eq_b = rsapss_sign_bn ke modBits eBits dBits skey m m' s in\n LS.blocks_bits_lemma t (v modBits);\n LS.blocks_numb_lemma t (v modBits);\n assert (SD.blocks (v k) numb == v nLen);\n assert (numb * v nLen <= max_size_t);\n BN.bn_to_bytes_be k s sgnt;\n pop_frame ();\n eq_b\n\n\ninline_for_extraction noextract\nlet rsapss_sign_st1 (t:limb_t) (ke:BE.exp t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h salt /\\ live h msg /\\ live h sgnt /\\ live h skey /\\\n disjoint sgnt salt /\\ disjoint sgnt msg /\\ disjoint sgnt salt /\\ disjoint sgnt skey /\\\n disjoint salt msg /\\\n\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey) /\\\n LS.rsapss_sign_pre a (v modBits) (v saltLen) (as_seq h salt) (v msgLen) (as_seq h msg))\n (ensures fun h0 eq_m h1 -> modifies (loc sgnt) h0 h1 /\\\n (eq_m, as_seq h1 sgnt) == LS.rsapss_sign_ a (v modBits) (v eBits) (v dBits)\n (as_seq h0 skey) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg))\n\n\ninline_for_extraction noextract\nval rsapss_sign_:\n #t:limb_t\n -> ke:BE.exp t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_st1 t ke a modBits\n\nlet rsapss_sign_ #t ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let m = create nLen (uint #t 0) in\n rsapss_sign_msg_to_bn a modBits saltLen salt msgLen msg m;\n let eq_b = rsapss_sign_compute_sgnt ke modBits eBits dBits skey m sgnt in\n pop_frame ();\n eq_b\n\n\ninline_for_extraction noextract\nlet rsapss_sign_st (t:limb_t) (ke:BE.exp t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t\n -> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}\n -> skey:lbignum t (2ul *! len +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t)))\n -> saltLen:size_t\n -> salt:lbuffer uint8 saltLen\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> sgnt:lbuffer uint8 (blocks modBits 8ul) ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h salt /\\ live h msg /\\ live h sgnt /\\ live h skey /\\\n disjoint sgnt salt /\\ disjoint sgnt msg /\\ disjoint sgnt salt /\\ disjoint sgnt skey /\\\n disjoint salt msg /\\\n\n LS.rsapss_skey_pre (v modBits) (v eBits) (v dBits) (as_seq h skey))\n (ensures fun h0 b h1 -> modifies (loc sgnt) h0 h1 /\\\n (b, as_seq h1 sgnt) == LS.rsapss_sign a (v modBits) (v eBits) (v dBits)\n (as_seq h0 skey) (v saltLen) (as_seq h0 salt) (v msgLen) (as_seq h0 msg) (as_seq h0 sgnt))\n\n\ninline_for_extraction noextract\nval rsapss_sign:\n #t:limb_t\n -> ke:BE.exp t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_sign_st t ke a modBits\n\nlet rsapss_sign #t ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt =\n let hLen = RM.hash_len a in\n Math.Lemmas.pow2_lt_compat 61 32;\n Math.Lemmas.pow2_lt_compat 125 32;\n //assert (max_size_t < Hash.max_input_length a);\n\n let b =\n saltLen <=. 0xfffffffful -! hLen -! 8ul &&\n saltLen +! hLen +! 2ul <=. blocks (modBits -! 1ul) 8ul in\n\n if b then\n rsapss_sign_ ke a modBits eBits dBits skey saltLen salt msgLen msg sgnt\n else\n false\n\n\n\ninline_for_extraction noextract\nval bn_lt_pow2:\n #t:limb_t\n -> modBits:size_t{1 < v modBits}\n -> m:lbignum t (blocks modBits (size (bits t))) ->\n Stack bool\n (requires fun h -> live h m)\n (ensures fun h0 r h1 -> h0 == h1 /\\\n r == LS.bn_lt_pow2 (v modBits) (as_seq h0 m))\n\nlet bn_lt_pow2 #t modBits m =\n if not ((modBits -! 1ul) %. 8ul =. 0ul) then true\n else begin\n let get_bit = BN.bn_get_ith_bit (blocks modBits (size (bits t))) m (modBits -! 1ul) in\n BB.unsafe_bool_of_limb0 get_bit end\n\n\ninline_for_extraction noextract\nlet rsapss_verify_bn_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t{LS.pkey_len_pre t (v modBits) (v eBits)}\n -> pkey:lbignum t (2ul *! len +! blocks eBits (size (bits t)))\n -> m_def:lbignum t len\n -> s:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h pkey /\\ live h m_def /\\ live h s /\\\n disjoint m_def pkey /\\ disjoint m_def s /\\ disjoint s pkey /\\\n LS.rsapss_pkey_pre (v modBits) (v eBits) (as_seq h pkey))\n (ensures fun h0 r h1 -> modifies (loc m_def) h0 h1 /\\\n (r, as_seq h1 m_def) == LS.rsapss_verify_bn (v modBits) (v eBits) (as_seq h0 pkey) (as_seq h0 m_def) (as_seq h0 s))\n\n\ninline_for_extraction noextract\nval rsapss_verify_bn: #t:limb_t -> ke:BE.exp t -> modBits:modBits_t t -> rsapss_verify_bn_st t ke modBits\nlet rsapss_verify_bn #t ke modBits eBits pkey m_def s =\n [@inline_let] let bits = size (bits t) in\n let nLen = blocks modBits bits in\n let eLen = blocks eBits bits in\n\n let n = sub pkey 0ul nLen in\n let r2 = sub pkey nLen nLen in\n let e = sub pkey (nLen +! nLen) eLen in\n\n let mask = BN.bn_lt_mask nLen s n in\n let h = ST.get () in\n SB.bn_lt_mask_lemma (as_seq h s) (as_seq h n);\n\n let res =\n if BB.unsafe_bool_of_limb mask then begin\n Math.Lemmas.pow2_le_compat (v bits * v nLen) (v modBits);\n SM.bn_precomp_r2_mod_n_lemma (v modBits - 1) (as_seq h n);\n\n let h0 = ST.get () in\n BE.mk_bn_mod_exp_precompr2 nLen ke.BE.exp_vt_precomp n r2 s eBits e m_def;\n let h1 = ST.get () in\n SD.bn_eval_inj (v nLen) (as_seq h1 m_def)\n (SE.bn_mod_exp_vartime_precompr2 (v nLen) (as_seq h0 n) (as_seq h0 r2)\n (as_seq h1 s) (v eBits) (as_seq h0 e));\n\n if bn_lt_pow2 modBits m_def then true\n else false end\n else false in\n res\n\n\ninline_for_extraction noextract\nlet rsapss_verify_bn_to_msg_st (t:limb_t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n saltLen:size_t\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen\n -> m:lbignum t (blocks modBits (size (bits t))) ->\n Stack bool\n (requires fun h ->\n live h msg /\\ live h m /\\ disjoint m msg /\\\n\n LS.rsapss_verify_pre a (v saltLen) (v msgLen) (as_seq h msg))\n (ensures fun h0 r h1 -> modifies0 h0 h1 /\\\n r == LS.rsapss_verify_bn_to_msg a (v modBits) (v saltLen) (v msgLen) (as_seq h0 msg) (as_seq h0 m))\n\n\ninline_for_extraction noextract\nval rsapss_verify_bn_to_msg:\n #t:limb_t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_verify_bn_to_msg_st t a modBits\n\nlet rsapss_verify_bn_to_msg #t a modBits saltLen msgLen msg m =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n\n let emBits = modBits -! 1ul in\n let emLen = blocks emBits 8ul in\n [@inline_let] let mLen = blocks emLen (size numb) in\n let em = create emLen (u8 0) in\n\n LS.blocks_bits_lemma t (v emBits);\n LS.blocks_numb_lemma t (v emBits);\n assert (SD.blocks (v emBits) bits == v mLen);\n assert (numb * v mLen <= max_size_t);\n assert (v mLen <= v nLen);\n\n let m1 = sub m 0ul mLen in\n BN.bn_to_bytes_be emLen m1 em;\n let res = RP.pss_verify a saltLen msgLen msg emBits em in\n pop_frame ();\n res\n\n\ninline_for_extraction noextract\nlet rsapss_verify_compute_msg_st (t:limb_t) (ke:BE.exp t) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t{LS.pkey_len_pre t (v modBits) (v eBits)}\n -> pkey:lbignum t (2ul *! len +! blocks eBits (size (bits t)))\n -> sgnt:lbuffer uint8 (blocks modBits 8ul)\n -> m:lbignum t len ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h sgnt /\\ live h pkey /\\ live h m /\\\n disjoint m sgnt /\\ disjoint m pkey /\\\n as_seq h m == LSeq.create (v len) (uint #t 0) /\\\n LS.rsapss_pkey_pre (v modBits) (v eBits) (as_seq h pkey))\n (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\\\n (r, as_seq h1 m) == LS.rsapss_verify_compute_msg (v modBits) (v eBits) (as_seq h0 pkey) (as_seq h0 sgnt))\n\n\ninline_for_extraction noextract\nval rsapss_verify_compute_msg:\n #t:limb_t\n -> ke:BE.exp t\n -> modBits:modBits_t t ->\n rsapss_verify_compute_msg_st t ke modBits\n\nlet rsapss_verify_compute_msg #t ke modBits eBits pkey sgnt m =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n [@inline_let] let numb : size_pos = numbytes t in\n let nLen = blocks modBits (size bits) in\n let k = blocks modBits 8ul in\n\n let s = create nLen (uint #t 0) in\n LS.blocks_bits_lemma t (v modBits);\n LS.blocks_numb_lemma t (v modBits);\n assert (SD.blocks (v k) numb == v nLen);\n assert (numb * v nLen <= max_size_t);\n BN.bn_from_bytes_be k sgnt s;\n\n let b = rsapss_verify_bn #t ke modBits eBits pkey m s in\n pop_frame ();\n b\n\n\ninline_for_extraction noextract\nlet rsapss_verify_st1 (t:limb_t) (ke:BE.exp t) (a:Hash.hash_alg{S.hash_is_supported a}) (modBits:modBits_t t) =\n let len = blocks modBits (size (bits t)) in\n eBits:size_t{LS.pkey_len_pre t (v modBits) (v eBits)}\n -> pkey:lbignum t (2ul *! len +! blocks eBits (size (bits t)))\n -> saltLen:size_t\n -> sgnt:lbuffer uint8 (blocks modBits 8ul)\n -> msgLen:size_t\n -> msg:lbuffer uint8 msgLen ->\n Stack bool\n (requires fun h -> len == ke.BE.bn.BN.len /\\\n live h msg /\\ live h sgnt /\\ live h pkey /\\\n disjoint msg sgnt /\\ disjoint msg pkey /\\\n\n LS.rsapss_pkey_pre (v modBits) (v eBits) (as_seq h pkey) /\\\n LS.rsapss_verify_pre a (v saltLen) (v msgLen) (as_seq h msg))\n (ensures fun h0 r h1 -> modifies0 h0 h1 /\\\n r == LS.rsapss_verify_ a (v modBits) (v eBits) (as_seq h0 pkey)\n (v saltLen) (as_seq h0 sgnt) (v msgLen) (as_seq h0 msg))\n\n\ninline_for_extraction noextract\nval rsapss_verify_:\n #t:limb_t\n -> ke:BE.exp t\n -> a:Hash.hash_alg{S.hash_is_supported a}\n -> modBits:modBits_t t ->\n rsapss_verify_st1 t ke a modBits\n\nlet rsapss_verify_ #t ke a modBits eBits pkey saltLen sgnt msgLen msg =\n push_frame ();\n [@inline_let] let bits : size_pos = bits t in\n let nLen = blocks modBits (size bits) in\n let m = create nLen (uint #t 0) in\n let b = rsapss_verify_compute_msg ke modBits eBits pkey sgnt m in\n let res = if b then rsapss_verify_bn_to_msg a modBits saltLen msgLen msg m else false in\n pop_frame ();\n res\n\nPartial implementation:\nlet rsapss_verify_st\n (t: limb_t)\n (ke: BE.exp t)\n (a: Hash.hash_alg{S.hash_is_supported a})\n (modBits: modBits_t t)\n =\n \n"
},
{
"role": "assistant",
"content": "let len = blocks modBits (size (bits t)) in\n\n eBits: size_t{LS.pkey_len_pre t (v modBits) (v eBits)} ->\n pkey: lbignum t (2ul *! len +! blocks eBits (size (bits t))) ->\n saltLen: size_t ->\n sgntLen: size_t ->\n sgnt: lbuffer uint8 sgntLen ->\n msgLen: size_t ->\n msg: lbuffer uint8 msgLen\n -> Stack bool\n (requires\n fun h ->\n len == ke.BE.bn.BN.len /\\ live h msg /\\ live h sgnt /\\ live h pkey /\\ disjoint msg sgnt /\\\n disjoint msg pkey /\\ LS.rsapss_pkey_pre (v modBits) (v eBits) (as_seq h pkey))\n (ensures\n fun h0 r h1 ->\n modifies0 h0 h1 /\\\n r ==\n LS.rsapss_verify a\n (v modBits)\n (v eBits)\n (as_seq h0 pkey)\n (v saltLen)\n (v sgntLen)\n (as_seq h0 sgnt)\n (v msgLen)\n (as_seq h0 msg))"
}
] |
[
{
"role": "user",
"content": "Complete this F* function with a correct proof.\n\nType: \n wfr_a: FStar.WellFoundedRelation.wfr_t a ->\n a_to_wfr_b: (x: a -> FStar.WellFoundedRelation.wfr_t (b x))\n -> wfr:\n FStar.WellFoundedRelation.wfr_t (Prims.dtuple2 a (fun x -> b x))\n {Mkwfr_t?.relation wfr == FStar.WellFoundedRelation.lex_dep_relation wfr_a a_to_wfr_b}\nEffect: Prims.Tot\n\nContext:\n(*\n Copyright 2022 Jay Lorch and Nikhil Swamy, 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\n(* This library is intended to simplify using well-founded relations\n in decreases clauses.\n*)\n\nmodule FStar.WellFoundedRelation\n\nopen FStar.Universe\nmodule WF = FStar.WellFounded\nmodule WFU = FStar.WellFounded.Util\n\nlet rec default_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (default_relation #a) x) (decreases x) =\n let smaller (y: a{default_relation y x}) : acc_classical (default_relation #a) y =\n default_decreaser y\n in\n AccClassicalIntro smaller\n\nlet default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires default_relation x1 x2)\n (ensures default_decreaser x1 << default_decreaser x2) =\n assert ((default_decreaser x2).access_smaller x1 == default_decreaser x1)\n in\n { relation = default_relation; decreaser = default_decreaser; proof = proof; }\n\nlet rec empty_decreaser (#a: Type u#a) (x: a)\n : Tot (acc_classical (empty_relation #a) x) (decreases x) =\n let smaller (y: a{empty_relation y x}) : acc_classical (empty_relation #a) y =\n empty_decreaser y\n in\n AccClassicalIntro smaller\n\nlet empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires empty_relation x1 x2) (ensures empty_decreaser x1 << empty_decreaser x2) =\n assert ((empty_decreaser x2).access_smaller x1 == empty_decreaser x1)\n in\n { relation = empty_relation; decreaser = empty_decreaser; proof = proof; }\n\nlet rec acc_decreaser\n (#a: Type u#a)\n (r: a -> a -> Type0)\n (f: WF.well_founded r{forall x1 x2 (p: r x1 x2). (f x2).access_smaller x1 p == f x1})\n (x: a)\n : Tot (acc_classical (acc_relation r) x) (decreases (f x)) =\n let smaller (y: a{(acc_relation r) y x}) : (acc_classical (acc_relation r) y) = (\n eliminate exists (p: r y x). True\n returns f y << f x\n with _. assert ((f x).access_smaller y p == f y);\n acc_decreaser r f y\n ) in\n AccClassicalIntro smaller\n\nlet rec eta_expand_well_founded (#a: Type) (r: WF.binrel a) (wf_r: WF.well_founded r) (x: a)\n : Tot (WF.acc r x)\n (decreases {:well-founded (WFU.lift_binrel_as_well_founded_relation wf_r) (| a, x |)})\n = WF.AccIntro (let g_smaller (y: a) (u: r y x) : WF.acc r y =\n WFU.intro_lift_binrel r y x;\n eta_expand_well_founded r wf_r y\n in g_smaller)\n\nlet acc_to_wfr (#a: Type u#a) (r: WF.binrel u#a u#0 a) (f: WF.well_founded r)\n : (wfr: wfr_t a{wfr.relation == acc_relation r}) =\n let f = eta_expand_well_founded r f in\n let proof (x1: a) (x2: a)\n : Lemma (requires acc_relation r x1 x2)\n (ensures acc_decreaser r f x1 << acc_decreaser r f x2) =\n assert ((acc_decreaser r f x2).access_smaller x1 == acc_decreaser r f x1)\n in\n { relation = acc_relation r; decreaser = acc_decreaser r f; proof = proof; }\n\nlet rec subrelation_decreaser (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2}) (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser x) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n subrelation_decreaser r wfr y\n in\n AccClassicalIntro smaller\n\nlet subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)\n (wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures subrelation_decreaser r wfr x1 << subrelation_decreaser r wfr x2) =\n assert ((subrelation_decreaser r wfr x2).access_smaller x1 == subrelation_decreaser r wfr x1)\n in\n { relation = r; decreaser = subrelation_decreaser r wfr; proof = proof; }\n\nlet rec inverse_image_decreaser (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n (x: a)\n : Tot (acc_classical r x) (decreases wfr.decreaser (f x)) =\n let smaller (y: a{r y x}) : (acc_classical r y) =\n inverse_image_decreaser r f wfr y\n in\n AccClassicalIntro smaller\n\nlet inverse_image_to_wfr (#a: Type u#a) (#b: Type u#b) (r: a -> a -> Type0) (f: a -> b)\n (wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})\n : (wfr': wfr_t a{wfr'.relation == r}) =\n let proof (x1: a) (x2: a)\n : Lemma (requires r x1 x2)\n (ensures inverse_image_decreaser r f wfr x1 << inverse_image_decreaser r f wfr x2) =\n assert ((inverse_image_decreaser r f wfr x2).access_smaller x1 ==\n inverse_image_decreaser r f wfr x1)\n in\n { relation = r; decreaser = inverse_image_decreaser r f wfr; proof = proof; }\n\nlet rec lex_nondep_decreaser (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n (xy: a * b)\n : Tot (acc_classical (lex_nondep_relation wfr_a wfr_b) xy)\n (decreases %[wfr_a.decreaser (fst xy); wfr_b.decreaser (snd xy)]) =\n let smaller (xy': a * b{lex_nondep_relation wfr_a wfr_b xy' xy})\n : (acc_classical (lex_nondep_relation wfr_a wfr_b) xy') =\n lex_nondep_decreaser wfr_a wfr_b xy'\n in\n AccClassicalIntro smaller\n\nlet lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)\n : wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b} =\n let proof (xy1: a * b) (xy2: a * b)\n : Lemma (requires lex_nondep_relation wfr_a wfr_b xy1 xy2)\n (ensures lex_nondep_decreaser wfr_a wfr_b xy1 <<\n lex_nondep_decreaser wfr_a wfr_b xy2) =\n assert ((lex_nondep_decreaser wfr_a wfr_b xy2).access_smaller xy1 ==\n lex_nondep_decreaser wfr_a wfr_b xy1)\n in\n { relation = lex_nondep_relation wfr_a wfr_b;\n decreaser = lex_nondep_decreaser wfr_a wfr_b;\n proof = proof; }\n\nlet rec lex_dep_decreaser (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)\n (a_to_wfr_b: (x: a -> wfr_t (b x))) (xy: (x: a & b x))\n : Tot (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy)\n (decreases %[wfr_a.decreaser (dfst xy); (a_to_wfr_b (dfst xy)).decreaser (dsnd xy)]) =\n let smaller (xy': (x: a & b x){lex_dep_relation wfr_a a_to_wfr_b xy' xy})\n : (acc_classical (lex_dep_relation wfr_a a_to_wfr_b) xy') =\n lex_dep_decreaser wfr_a a_to_wfr_b xy'\n in\n AccClassicalIntro smaller\n\nPartial implementation:\nlet lex_dep_wfr\n (#a: Type u#a)\n (#b: (a -> Type u#b))\n (wfr_a: wfr_t a)\n (a_to_wfr_b: (x: a -> wfr_t (b x)))\n : wfr: wfr_t (x: a & b x) {wfr.relation == lex_dep_relation wfr_a a_to_wfr_b} =\n \n"
},
{
"role": "assistant",
"content": "let proof (xy1 xy2: (x: a & b x))\n : Lemma (requires lex_dep_relation wfr_a a_to_wfr_b xy1 xy2)\n (ensures lex_dep_decreaser wfr_a a_to_wfr_b xy1 << lex_dep_decreaser wfr_a a_to_wfr_b xy2) =\n assert ((lex_dep_decreaser wfr_a a_to_wfr_b xy2).access_smaller xy1 ==\n lex_dep_decreaser wfr_a a_to_wfr_b xy1)\nin\n{\n relation = lex_dep_relation wfr_a a_to_wfr_b;\n decreaser = lex_dep_decreaser wfr_a a_to_wfr_b;\n proof = proof\n}"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.