file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.blob
val blob : Type0
let blob = string & R.term
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 1793, "start_col": 0, "start_line": 1793 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_ let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_ let ln (t:term) = ln' t (-1) let ln_comp (c:comp) = ln'_comp c (-1) // // term_ctxt is used to define the equiv relation later, // basically putting two equiv terms in a hole gives equiv terms // // The abs, arrow, refine, and let cases don't seem right here, // since to prove their equiv, we need to extend gamma for their bodies // // If this is useful only for app, then may be we should remove it, // and add app rules to the equiv relation itself [@@ no_auto_projectors] noeq type term_ctxt = | Ctxt_hole : term_ctxt | Ctxt_app_head : term_ctxt -> argv -> term_ctxt | Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt // | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt // | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt // | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt // | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt // | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt // | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt // | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt // | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt // | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt // | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt // and bv_ctxt = // | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt // and binder_ctxt = // | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt // and comp_ctxt = // | Ctxt_total : term_ctxt -> comp_ctxt // | Ctxt_gtotal : term_ctxt -> comp_ctxt let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) = match e with | Ctxt_hole -> t | Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg) | Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) // | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body) // | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t)) // | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c) // | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t)) // | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi) // | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t)) // | Ctxt_let_sort b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body) // | Ctxt_let_def b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body) // | Ctxt_let_body b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t)) // | Ctxt_match_scrutinee sc ret brs -> // pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs) // and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) = // let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in // pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t} // and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) = // match c with // | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t)) // | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t)) noeq type constant_typing: vconst -> term -> Type0 = | CT_Unit: constant_typing C_Unit unit_ty | CT_True: constant_typing C_True bool_ty | CT_False: constant_typing C_False bool_ty [@@ no_auto_projectors] noeq type univ_eq : universe -> universe -> Type0 = | UN_Refl : u:universe -> univ_eq u u | UN_MaxCongL : u:universe -> u':universe -> v:universe -> univ_eq u u' -> univ_eq (u_max u v) (u_max u' v) | UN_MaxCongR : u:universe -> v:universe -> v':universe -> univ_eq v v' -> univ_eq (u_max u v) (u_max u v') | UN_MaxComm: u:universe -> v:universe -> univ_eq (u_max u v) (u_max v u) | UN_MaxLeq: u:universe -> v:universe -> univ_leq u v -> univ_eq (u_max u v) v and univ_leq : universe -> universe -> Type0 = | UNLEQ_Refl: u:universe -> univ_leq u u | UNLEQ_Succ: u:universe -> v:universe -> univ_leq u v -> univ_leq u (u_succ v) | UNLEQ_Max: u:universe -> v:universe -> univ_leq u (u_max u v) let mk_if (scrutinee then_ else_:R.term) : R.term = pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) // effect and type type comp_typ = T.tot_or_ghost & typ let close_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) [ ND x i ] let close_comp_typ (c:comp_typ) (x:var) = close_comp_typ' c x 0 let open_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) (open_with_var x i) let open_comp_typ (c:comp_typ) (x:var) = open_comp_typ' c x 0 let freevars_comp_typ (c:comp_typ) = freevars (snd c) let mk_comp (c:comp_typ) : R.comp = match fst c with | T.E_Total -> mk_total (snd c) | T.E_Ghost -> mk_ghost (snd c) let mk_arrow_ct ty qual (c:comp_typ) : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c)) type relation = | R_Eq | R_Sub let binding = var & term let bindings = list binding let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs let rec extend_env_l (g:env) (bs:bindings) : env = match bs with | [] -> g | (x,t)::bs -> extend_env (extend_env_l g bs) x t // // TODO: support for erasable attribute // let is_non_informative_name (l:name) : bool = l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] let is_non_informative_fv (f:fv) : bool = is_non_informative_name (inspect_fv f) let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) = match vs with | [] -> t | v::vs -> subst_term (__close_term_vs (i+1) vs t) [ND v i] let close_term_vs (vs : list var) (t : term) : term = __close_term_vs 0 vs t let close_term_bs (bs : list binding) (t : term) : term = close_term_vs (List.Tot.map fst bs) t let bindings_to_refl_bindings (bs : list binding) : list R.binding = L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs let refl_bindings_to_bindings (bs : list R.binding) : list binding = L.map (fun b -> b.uniq, b.sort) bs [@@ no_auto_projectors] noeq type non_informative : env -> term -> Type0 = | Non_informative_type: g:env -> u:universe -> non_informative g (pack_ln (Tv_Type u)) | Non_informative_fv: g:env -> x:fv{is_non_informative_fv x} -> non_informative g (pack_ln (Tv_FVar x)) | Non_informative_uinst: g:env -> x:fv{is_non_informative_fv x} -> us:list universe -> non_informative g (pack_ln (Tv_UInst x us)) | Non_informative_app: g:env -> t:term -> arg:argv -> non_informative g t -> non_informative g (pack_ln (Tv_App t arg)) | Non_informative_total_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g t1 -> non_informative g (mk_arrow_ct t0 q (T.E_Total, t1)) | Non_informative_ghost_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1)) | Non_informative_token: g:env -> t:typ -> squash (T.non_informative_token g t) -> non_informative g t val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0 val bindings_ok_pat_constant : g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c)) let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 = bindings_ok_for_pat g bs (fst br) let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) = zip2prop (bindings_ok_for_branch g) bss brs let binding_to_namedv (b:R.binding) : Tot namedv = pack_namedv { RD.uniq = b.uniq; RD.sort = seal b.sort; RD.ppname = b.ppname; } (* Elaborates the p pattern into a term, using the bs bindings for the pattern variables. The resulting term is properly scoped only on an environment which contains all of bs. See for instance the branch_typing judg. Returns an option, since this can fail if e.g. there are not enough bindings, and returns the list of unused binders as well, which should be empty if the list of binding was indeed ok. *) let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) = match p, bs with | Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs) | Pat_Cons fv univs subpats, bs -> let head = pack_ln (Tv_FVar fv) in fold_left_dec (Some (head, bs)) subpats (fun st pi -> let (p,i) = pi in match st with | None -> None | Some (head, bs) -> match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs')) | Pat_Var _ _, b::bs -> Some (pack_ln (Tv_Var (binding_to_namedv b)), bs) | Pat_Dot_Term (Some t), _ -> Some (t, bs) | Pat_Dot_Term None, _ -> None | _ -> None [@@ no_auto_projectors] noeq type typing : env -> term -> comp_typ -> Type0 = | T_Token : g:env -> e:term -> c:comp_typ -> squash (T.typing_token g e c) -> typing g e c | T_Var : g:env -> x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } -> typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x))) | T_FVar : g:env -> x:fv { Some? (lookup_fvar g x) } -> typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x)) | T_UInst : g:env -> x:fv -> us:list universe { Some? (lookup_fvar_uinst g x us) } -> typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us)) | T_Const: g:env -> v:vconst -> t:term -> constant_typing v t -> typing g (constant_as_term v) (T.E_Total, t) | T_Abs : g:env -> x:var { None? (lookup_bvar g x) } -> ty:term -> body:term { ~(x `Set.mem` freevars body) } -> body_c:comp_typ -> u:universe -> pp_name:pp_name_t -> q:aqualv -> ty_eff:T.tot_or_ghost -> typing g ty (ty_eff, tm_type u) -> typing (extend_env g x ty) (open_term body x) body_c -> typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body)) (T.E_Total, pack_ln (Tv_Arrow (mk_binder pp_name ty q) (mk_comp (close_comp_typ body_c x)))) | T_App : g:env -> e1:term -> e2:term -> x:binder -> t:term -> eff:T.tot_or_ghost -> typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) -> typing g e2 (eff, binder_sort x) -> typing g (pack_ln (Tv_App e1 (e2, binder_qual x))) (eff, open_with t e2) | T_Let: g:env -> x:var { None? (lookup_bvar g x) } -> e1:term -> t1:typ -> e2:term -> t2:typ -> eff:T.tot_or_ghost -> pp_name:pp_name_t -> typing g e1 (eff, t1) -> typing (extend_env g x t1) (open_term e2 x) (eff, t2) -> typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1) | T_Arrow: g:env -> x:var { None? (lookup_bvar g x) } -> t1:term -> t2:term { ~(x `Set.mem` freevars t2) } -> u1:universe -> u2:universe -> pp_name:pp_name_t -> q:aqualv -> eff:T.tot_or_ghost -> t1_eff:T.tot_or_ghost -> t2_eff:T.tot_or_ghost -> typing g t1 (t1_eff, tm_type u1) -> typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) -> typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2)))) (T.E_Total, tm_type (u_max u1 u2)) | T_Refine: g:env -> x:var { None? (lookup_bvar g x) } -> t:term -> e:term { ~(x `Set.mem` freevars e) } -> u1:universe -> u2:universe -> t_eff:T.tot_or_ghost -> e_eff:T.tot_or_ghost -> typing g t (t_eff, tm_type u1) -> typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) -> typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1) | T_PropIrrelevance: g:env -> e:term -> t:term -> e_eff:T.tot_or_ghost -> t_eff:T.tot_or_ghost -> typing g e (e_eff, t) -> typing g t (t_eff, tm_prop) -> typing g (`()) (T.E_Total, t) | T_Sub: g:env -> e:term -> c:comp_typ -> c':comp_typ -> typing g e c -> sub_comp g c c' -> typing g e c' | T_If: g:env -> scrutinee:term -> then_:term -> else_:term -> ty:term -> u_ty:universe -> hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } -> eff:T.tot_or_ghost -> ty_eff:T.tot_or_ghost -> typing g scrutinee (eff, bool_ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) -> typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp typing g (mk_if scrutinee then_ else_) (eff, ty) | T_Match: g:env -> sc_u : universe -> sc_ty : typ -> sc : term -> ty_eff:T.tot_or_ghost -> typing g sc_ty (ty_eff, tm_type sc_u) -> eff:T.tot_or_ghost -> typing g sc (eff, sc_ty) -> branches:list branch -> ty:comp_typ -> bnds:list (list R.binding) -> complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type typing g (pack_ln (Tv_Match sc None branches)) ty and related : env -> term -> relation -> term -> Type0 = | Rel_refl: g:env -> t:term -> rel:relation -> related g t rel t | Rel_sym: g:env -> t0:term -> t1:term -> related g t0 R_Eq t1 -> related g t1 R_Eq t0 | Rel_trans: g:env -> t0:term -> t1:term -> t2:term -> rel:relation -> related g t0 rel t1 -> related g t1 rel t2 -> related g t0 rel t2 | Rel_univ: g:env -> u:universe -> v:universe -> univ_eq u v -> related g (tm_type u) R_Eq (tm_type v) | Rel_beta: g:env -> t:typ -> q:aqualv -> e:term { ln' e 0 } -> arg:term { ln arg } -> related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q))) R_Eq (subst_term e [ DT 0 arg ]) | Rel_eq_token: g:env -> t0:term -> t1:term -> squash (T.equiv_token g t0 t1) -> related g t0 R_Eq t1 | Rel_subtyping_token: g:env -> t0:term -> t1:term -> squash (T.subtyping_token g t0 t1) -> related g t0 R_Sub t1 | Rel_equiv: g:env -> t0:term -> t1:term -> rel:relation -> related g t0 R_Eq t1 -> related g t0 rel t1 | Rel_arrow: g:env -> t1:term -> t2:term -> q:aqualv -> c1:comp_typ -> c2:comp_typ -> rel:relation -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2)) } -> related g t2 rel t1 -> related_comp (extend_env g x t2) (open_comp_typ c1 x) rel (open_comp_typ c2 x) -> related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2) | Rel_abs: g:env -> t1:term -> t2:term -> q:aqualv -> e1:term -> e2:term -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2)) } -> related g t1 R_Eq t2 -> related (extend_env g x t1) (subst_term e1 (open_with_var x 0)) R_Eq (subst_term e2 (open_with_var x 0)) -> related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2) | Rel_ctxt: g:env -> t0:term -> t1:term -> ctxt:term_ctxt -> related g t0 R_Eq t1 -> related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1) and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 = | Relc_typ: g:env -> t0:term -> t1:term -> eff:T.tot_or_ghost -> rel:relation -> related g t0 rel t1 -> related_comp g (eff, t0) rel (eff, t1) | Relc_total_ghost: g:env -> t:term -> related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t) | Relc_ghost_total: g:env -> t:term -> non_informative g t -> related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t) and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (brs:list branch) -> (bnds : list (list R.binding)) -> Type0 = (* This judgement only enforces that branch_typing holds for every element of brs and its respective bnds (which must have the same length). *) | BT_Nil : branches_typing g sc_u sc_ty sc rty [] [] | BT_S : br : branch -> bnds : list R.binding -> pf : branch_typing g sc_u sc_ty sc rty br bnds -> rest_br : list branch -> rest_bnds : list (list R.binding) -> rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds -> branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds) and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (br : branch) -> (bnds : list R.binding) -> Type0 = | BO : pat : pattern -> bnds : list R.binding{bindings_ok_for_pat g bnds pat} -> hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} -> body:term -> _ : squash (Some? (elaborate_pat pat bnds)) -> typing (extend_env (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds)))) ) body rty -> branch_typing g sc_u sc_ty sc rty (pat, close_term_bs (refl_bindings_to_bindings bnds) body) bnds and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 = | MC_Tok : env:_ -> sc:_ -> ty:_ -> pats:_ -> bnds:_ -> squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2 and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2 and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2 type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t) type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t) val subtyping_token_renaming (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1) : T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0)) (rename t0 x y) (rename t1 x y) val subtyping_token_weakening (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1) : T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1 let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe) (d:typing g t (T.E_Total, tm_type (u_max u u))) : typing g t (T.E_Total, tm_type u) = let ue : univ_eq (u_max u u) u = UN_MaxLeq u u (UNLEQ_Refl u) in let du : related g (tm_type (u_max u u)) R_Eq (tm_type u) = Rel_univ g (u_max u u) u ue in let du : related g (tm_type (u_max u u)) R_Sub (tm_type u) = Rel_equiv _ _ _ _ du in T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du) val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : Lemma (ensures ln e /\ ln (snd c)) val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u)) val binder_offset_pattern_invariant (p:pattern) (ss:subst) : Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss)) val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst) : Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss)) val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var) : Lemma (ensures subst_term (subst_term t [ ND x i ]) (open_with_var x i) == t) val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var) : Lemma (ensures subst_binder (subst_binder b [ ND x i ]) (open_with_var x i) == b) val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var) : Lemma (ensures subst_terms (subst_terms ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var) : Lemma (ensures subst_comp (subst_comp c [ ND x i ]) (open_with_var x i) == c) val open_close_inverse'_args (i:nat) (ts:list argv { ln'_args ts (i - 1) }) (x:var) : Lemma (ensures subst_args (subst_args ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_patterns (i:nat) (ps:list (pattern & bool) { ln'_patterns ps (i - 1) }) (x:var) : Lemma (ensures subst_patterns (subst_patterns ps [ ND x i ]) (open_with_var x i) == ps) val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var) : Lemma (ensures subst_pattern (subst_pattern p [ ND x i ]) (open_with_var x i) == p) val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var) : Lemma (ensures subst_branch (subst_branch br [ ND x i ]) (open_with_var x i) == br) val open_close_inverse'_branches (i:nat) (brs:list branch { ln'_branches brs (i - 1) }) (x:var) : Lemma (ensures subst_branches (subst_branches brs [ ND x i ]) (open_with_var x i) == brs) val open_close_inverse'_match_returns (i:nat) (m:match_returns_ascription { ln'_match_returns m (i - 1) }) (x:var) : Lemma (ensures subst_match_returns (subst_match_returns m [ ND x i ]) (open_with_var x i) == m) val open_close_inverse (e:R.term { ln e }) (x:var) : Lemma (open_term (close_term e x) x == e) val close_open_inverse' (i:nat) (t:term) (x:var { ~(x `Set.mem` freevars t) }) : Lemma (ensures subst_term (subst_term t (open_with_var x i)) [ ND x i ] == t) val close_open_inverse'_comp (i:nat) (c:comp) (x:var{ ~(x `Set.mem` freevars_comp c) }) : Lemma (ensures subst_comp (subst_comp c (open_with_var x i)) [ ND x i ] == c) val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) }) : Lemma (ensures subst_args (subst_args args (open_with_var x i)) [ ND x i] == args) val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) }) : Lemma (ensures subst_binder (subst_binder b (open_with_var x i)) [ ND x i ] == b) val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) }) : Lemma (ensures subst_terms (subst_terms ts (open_with_var x i)) [ ND x i ] == ts) val close_open_inverse'_branches (i:nat) (brs:list branch) (x:var{ ~(x `Set.mem` freevars_branches brs) }) : Lemma (ensures subst_branches (subst_branches brs (open_with_var x i)) [ ND x i ] == brs) val close_open_inverse'_branch (i:nat) (br:branch) (x:var{ ~(x `Set.mem` freevars_branch br) }) : Lemma (ensures subst_branch (subst_branch br (open_with_var x i)) [ ND x i ] == br) val close_open_inverse'_pattern (i:nat) (p:pattern) (x:var{ ~(x `Set.mem` freevars_pattern p) }) : Lemma (ensures subst_pattern (subst_pattern p (open_with_var x i)) [ ND x i ] == p) val close_open_inverse'_patterns (i:nat) (ps:list (pattern & bool)) (x:var {~ (x `Set.mem` freevars_patterns ps) }) : Lemma (ensures subst_patterns (subst_patterns ps (open_with_var x i)) [ ND x i ] == ps) val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription) (x:var{ ~(x `Set.mem` freevars_match_returns m) }) : Lemma (ensures subst_match_returns (subst_match_returns m (open_with_var x i)) [ ND x i ] == m) val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) }) : Lemma (close_term (open_term e x) x == e) // // fst has corresponding lemmas for other syntax classes // val close_with_not_free_var (t:R.term) (x:var) (i:nat) : Lemma (requires ~ (Set.mem x (freevars t))) (ensures subst_term t [ ND x i ] == t) // this also requires x to be not in freevars e1 `Set.union` freevars e2 val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var { None? (lookup_bvar g x) }) (eq:equiv (extend_env g x ty) (subst_term e1 (open_with_var x 0)) (subst_term e2 (open_with_var x 0))) : equiv g (mk_arrow ty q e1) (mk_arrow ty q e2) // the proof for this requires e1 and e2 to be ln val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var{None? (lookup_bvar g x)}) (eq:equiv (extend_env g x ty) e1 e2) : equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ])) (mk_abs ty q (subst_term e2 [ ND x 0 ])) val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat) : Lemma (requires ln' e i /\ i < j) (ensures subst_term e [ DT j t ] == e) [SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])] // // Type of the top-level tactic that would splice-in the definitions // let fstar_env_fvs (g:R.env) = lookup_fvar g unit_fv == Some (tm_type u_zero) /\ lookup_fvar g bool_fv == Some (tm_type u_zero) /\ lookup_fvar g b2t_fv == Some b2t_ty type fstar_env = g:R.env{fstar_env_fvs g} type fstar_top_env = g:fstar_env { forall x. None? (lookup_bvar g x ) } // // This doesn't allow for universe polymorphic definitions // // May be we can change it to: // // g:fstar_top_env -> T.tac ((us, e, t):(univ_names & term & typ){typing (push g us) e t}) // noeq type sigelt_typing : env -> sigelt -> Type0 = | ST_Let : g : env -> fv : R.fv -> ty : R.typ -> tm : R.term -> squash (typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm })])) | ST_Let_Opaque : g : env -> fv : R.fv -> ty : R.typ -> (* no tm: only a proof of existence *) squash (exists (tm:R.term). typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) })])) (** * The type of the top-level tactic that would splice-in the definitions. * It returns a list of well typed definitions, via the judgment above. * * Each definition can have a 'blob' attached with a given name. * The blob can be used later, e.g., during extraction, and passed back to the * extension to perform additional processing. *) (* * It returns either: * - Some tm, blob, typ, with a proof that `typing g tm typ` * - None, blob, typ), with a proof that `exists tm. typing g tm typ` * The blob itself is optional and can store some additional metadata that * constructed by the tactic. If present, it will be stored in the * sigmeta_extension_data field of the enclosing sigelt. *
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Prims.string", "FStar.Stubs.Reflection.Types.term" ]
[]
false
false
false
true
true
let blob =
string & R.term
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_first_part
val normalize5_first_part : _: ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) -> Lib.IntTypes.uint64 * ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64)
let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 208, "start_col": 0, "start_line": 205 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) -> Lib.IntTypes.uint64 * ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64)
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.Mktuple5", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Field52.Definitions.felem5", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256", "Hacl.Spec.K256.Field52.normalize_weak5" ]
[]
false
false
false
true
false
let normalize5_first_part (f0, f1, f2, f3, f4) =
let t0, t1, t2, t3, t4 = normalize_weak5 (f0, f1, f2, f3, f4) in let x, (r0, r1, r2, r3, r4) = minus_x_mul_pow2_256 (t0, t1, t2, t3, t4) in x, (r0, r1, r2, r3, r4)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.bindings_to_refl_bindings
val bindings_to_refl_bindings (bs: list binding) : list R.binding
val bindings_to_refl_bindings (bs: list binding) : list R.binding
let bindings_to_refl_bindings (bs : list binding) : list R.binding = L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 71, "end_line": 1051, "start_col": 0, "start_line": 1050 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_ let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_ let ln (t:term) = ln' t (-1) let ln_comp (c:comp) = ln'_comp c (-1) // // term_ctxt is used to define the equiv relation later, // basically putting two equiv terms in a hole gives equiv terms // // The abs, arrow, refine, and let cases don't seem right here, // since to prove their equiv, we need to extend gamma for their bodies // // If this is useful only for app, then may be we should remove it, // and add app rules to the equiv relation itself [@@ no_auto_projectors] noeq type term_ctxt = | Ctxt_hole : term_ctxt | Ctxt_app_head : term_ctxt -> argv -> term_ctxt | Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt // | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt // | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt // | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt // | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt // | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt // | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt // | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt // | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt // | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt // | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt // and bv_ctxt = // | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt // and binder_ctxt = // | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt // and comp_ctxt = // | Ctxt_total : term_ctxt -> comp_ctxt // | Ctxt_gtotal : term_ctxt -> comp_ctxt let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) = match e with | Ctxt_hole -> t | Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg) | Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) // | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body) // | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t)) // | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c) // | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t)) // | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi) // | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t)) // | Ctxt_let_sort b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body) // | Ctxt_let_def b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body) // | Ctxt_let_body b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t)) // | Ctxt_match_scrutinee sc ret brs -> // pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs) // and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) = // let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in // pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t} // and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) = // match c with // | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t)) // | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t)) noeq type constant_typing: vconst -> term -> Type0 = | CT_Unit: constant_typing C_Unit unit_ty | CT_True: constant_typing C_True bool_ty | CT_False: constant_typing C_False bool_ty [@@ no_auto_projectors] noeq type univ_eq : universe -> universe -> Type0 = | UN_Refl : u:universe -> univ_eq u u | UN_MaxCongL : u:universe -> u':universe -> v:universe -> univ_eq u u' -> univ_eq (u_max u v) (u_max u' v) | UN_MaxCongR : u:universe -> v:universe -> v':universe -> univ_eq v v' -> univ_eq (u_max u v) (u_max u v') | UN_MaxComm: u:universe -> v:universe -> univ_eq (u_max u v) (u_max v u) | UN_MaxLeq: u:universe -> v:universe -> univ_leq u v -> univ_eq (u_max u v) v and univ_leq : universe -> universe -> Type0 = | UNLEQ_Refl: u:universe -> univ_leq u u | UNLEQ_Succ: u:universe -> v:universe -> univ_leq u v -> univ_leq u (u_succ v) | UNLEQ_Max: u:universe -> v:universe -> univ_leq u (u_max u v) let mk_if (scrutinee then_ else_:R.term) : R.term = pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) // effect and type type comp_typ = T.tot_or_ghost & typ let close_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) [ ND x i ] let close_comp_typ (c:comp_typ) (x:var) = close_comp_typ' c x 0 let open_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) (open_with_var x i) let open_comp_typ (c:comp_typ) (x:var) = open_comp_typ' c x 0 let freevars_comp_typ (c:comp_typ) = freevars (snd c) let mk_comp (c:comp_typ) : R.comp = match fst c with | T.E_Total -> mk_total (snd c) | T.E_Ghost -> mk_ghost (snd c) let mk_arrow_ct ty qual (c:comp_typ) : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c)) type relation = | R_Eq | R_Sub let binding = var & term let bindings = list binding let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs let rec extend_env_l (g:env) (bs:bindings) : env = match bs with | [] -> g | (x,t)::bs -> extend_env (extend_env_l g bs) x t // // TODO: support for erasable attribute // let is_non_informative_name (l:name) : bool = l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] let is_non_informative_fv (f:fv) : bool = is_non_informative_name (inspect_fv f) let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) = match vs with | [] -> t | v::vs -> subst_term (__close_term_vs (i+1) vs t) [ND v i] let close_term_vs (vs : list var) (t : term) : term = __close_term_vs 0 vs t let close_term_bs (bs : list binding) (t : term) : term = close_term_vs (List.Tot.map fst bs) t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
bs: Prims.list FStar.Reflection.Typing.binding -> Prims.list FStar.Stubs.Reflection.V2.Data.binding
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Reflection.Typing.binding", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.tuple2", "Prims.nat", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Data.binding", "FStar.Stubs.Reflection.V2.Data.Mkbinding", "FStar.Reflection.Typing.pp_name_default" ]
[]
false
false
false
true
false
let bindings_to_refl_bindings (bs: list binding) : list R.binding =
L.map (fun (v, ty) -> { uniq = v; sort = ty; ppname = pp_name_default }) bs
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_binder
val freevars_binder (b: binder) : Tot (Set.set var) (decreases b)
val freevars_binder (b: binder) : Tot (Set.set var) (decreases b)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Stubs.Reflection.Types.binder -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Set.union", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Reflection.Typing.freevars", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Reflection.Typing.freevars_terms", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Stubs.Reflection.V2.Data.binder_view", "Prims.precedes", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_binder (b: binder) : Tot (Set.set var) (decreases b) =
let bndr = inspect_binder b in (freevars bndr.sort) `Set.union` (freevars_terms bndr.attrs)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_args
val freevars_args (ts: list argv) : FStar.Set.set var
val freevars_args (ts: list argv) : FStar.Set.set var
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list FStar.Stubs.Reflection.V2.Data.argv -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var
Prims.Tot
[ "total" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.V2.Data.argv", "FStar.Set.empty", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Set.union", "FStar.Reflection.Typing.freevars", "FStar.Reflection.Typing.freevars_args", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_args (ts: list argv) : FStar.Set.set var =
match ts with | [] -> Set.empty | (t, q) :: ts -> (freevars t) `Set.union` (freevars_args ts)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars
val freevars (e: term) : FStar.Set.set var
val freevars (e: term) : FStar.Set.set var
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: FStar.Stubs.Reflection.Types.term -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var
Prims.Tot
[ "total" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.inspect_ln", "Prims.nat", "FStar.Stubs.Reflection.Types.ctx_uvar_and_subst", "FStar.Set.complement", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.empty", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.V2.Data.vconst", "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Reflection.Types.namedv", "FStar.Set.singleton", "FStar.Reflection.Typing.namedv_uniq", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Set.union", "FStar.Reflection.Typing.freevars", "FStar.Stubs.Reflection.Types.binder", "FStar.Reflection.Typing.freevars_binder", "FStar.Stubs.Reflection.Types.comp", "FStar.Reflection.Typing.freevars_comp", "FStar.Stubs.Reflection.V2.Data.simple_binder", "FStar.Reflection.Typing.binder_sort", "Prims.bool", "Prims.list", "FStar.Reflection.Typing.freevars_terms", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.match_returns_ascription", "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Reflection.Typing.freevars_opt", "FStar.Reflection.Typing.freevars_match_returns", "FStar.Reflection.Typing.freevars_branches", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars (e: term) : FStar.Set.set var =
match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> (freevars (binder_sort b)) `Set.union` (freevars f) | Tv_Let recf attrs b def body -> (((freevars_terms attrs) `Set.union` (freevars (binder_sort b))) `Set.union` (freevars def)) `Set.union` (freevars body) | Tv_Match scr ret brs -> ((freevars scr) `Set.union` (freevars_opt ret freevars_match_returns)) `Set.union` (freevars_branches brs) | Tv_AscribedT e t tac b -> ((freevars e) `Set.union` (freevars t)) `Set.union` (freevars_opt tac freevars) | Tv_AscribedC e c tac b -> ((freevars e) `Set.union` (freevars_comp c)) `Set.union` (freevars_opt tac freevars)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_branches
val ln'_branches (brs: list branch) (i: int) : Tot bool (decreases brs)
val ln'_branches (brs: list branch) (i: int) : Tot bool (decreases brs)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
brs: Prims.list FStar.Stubs.Reflection.V2.Data.branch -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.V2.Data.branch", "Prims.int", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'_branch", "FStar.Reflection.Typing.ln'_branches", "Prims.bool" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_branches (brs: list branch) (i: int) : Tot bool (decreases brs) =
match brs with | [] -> true | br :: brs -> ln'_branch br i && ln'_branches brs i
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.elaborate_pat
val elaborate_pat (p: pattern) (bs: list R.binding) : Tot (option (term & list R.binding)) (decreases p)
val elaborate_pat (p: pattern) (bs: list R.binding) : Tot (option (term & list R.binding)) (decreases p)
let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) = match p, bs with | Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs) | Pat_Cons fv univs subpats, bs -> let head = pack_ln (Tv_FVar fv) in fold_left_dec (Some (head, bs)) subpats (fun st pi -> let (p,i) = pi in match st with | None -> None | Some (head, bs) -> match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs')) | Pat_Var _ _, b::bs -> Some (pack_ln (Tv_Var (binding_to_namedv b)), bs) | Pat_Dot_Term (Some t), _ -> Some (t, bs) | Pat_Dot_Term None, _ -> None | _ -> None
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 1144, "start_col": 0, "start_line": 1127 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_ let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_ let ln (t:term) = ln' t (-1) let ln_comp (c:comp) = ln'_comp c (-1) // // term_ctxt is used to define the equiv relation later, // basically putting two equiv terms in a hole gives equiv terms // // The abs, arrow, refine, and let cases don't seem right here, // since to prove their equiv, we need to extend gamma for their bodies // // If this is useful only for app, then may be we should remove it, // and add app rules to the equiv relation itself [@@ no_auto_projectors] noeq type term_ctxt = | Ctxt_hole : term_ctxt | Ctxt_app_head : term_ctxt -> argv -> term_ctxt | Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt // | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt // | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt // | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt // | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt // | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt // | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt // | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt // | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt // | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt // | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt // and bv_ctxt = // | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt // and binder_ctxt = // | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt // and comp_ctxt = // | Ctxt_total : term_ctxt -> comp_ctxt // | Ctxt_gtotal : term_ctxt -> comp_ctxt let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) = match e with | Ctxt_hole -> t | Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg) | Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) // | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body) // | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t)) // | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c) // | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t)) // | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi) // | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t)) // | Ctxt_let_sort b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body) // | Ctxt_let_def b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body) // | Ctxt_let_body b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t)) // | Ctxt_match_scrutinee sc ret brs -> // pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs) // and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) = // let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in // pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t} // and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) = // match c with // | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t)) // | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t)) noeq type constant_typing: vconst -> term -> Type0 = | CT_Unit: constant_typing C_Unit unit_ty | CT_True: constant_typing C_True bool_ty | CT_False: constant_typing C_False bool_ty [@@ no_auto_projectors] noeq type univ_eq : universe -> universe -> Type0 = | UN_Refl : u:universe -> univ_eq u u | UN_MaxCongL : u:universe -> u':universe -> v:universe -> univ_eq u u' -> univ_eq (u_max u v) (u_max u' v) | UN_MaxCongR : u:universe -> v:universe -> v':universe -> univ_eq v v' -> univ_eq (u_max u v) (u_max u v') | UN_MaxComm: u:universe -> v:universe -> univ_eq (u_max u v) (u_max v u) | UN_MaxLeq: u:universe -> v:universe -> univ_leq u v -> univ_eq (u_max u v) v and univ_leq : universe -> universe -> Type0 = | UNLEQ_Refl: u:universe -> univ_leq u u | UNLEQ_Succ: u:universe -> v:universe -> univ_leq u v -> univ_leq u (u_succ v) | UNLEQ_Max: u:universe -> v:universe -> univ_leq u (u_max u v) let mk_if (scrutinee then_ else_:R.term) : R.term = pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) // effect and type type comp_typ = T.tot_or_ghost & typ let close_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) [ ND x i ] let close_comp_typ (c:comp_typ) (x:var) = close_comp_typ' c x 0 let open_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) (open_with_var x i) let open_comp_typ (c:comp_typ) (x:var) = open_comp_typ' c x 0 let freevars_comp_typ (c:comp_typ) = freevars (snd c) let mk_comp (c:comp_typ) : R.comp = match fst c with | T.E_Total -> mk_total (snd c) | T.E_Ghost -> mk_ghost (snd c) let mk_arrow_ct ty qual (c:comp_typ) : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c)) type relation = | R_Eq | R_Sub let binding = var & term let bindings = list binding let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs let rec extend_env_l (g:env) (bs:bindings) : env = match bs with | [] -> g | (x,t)::bs -> extend_env (extend_env_l g bs) x t // // TODO: support for erasable attribute // let is_non_informative_name (l:name) : bool = l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] let is_non_informative_fv (f:fv) : bool = is_non_informative_name (inspect_fv f) let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) = match vs with | [] -> t | v::vs -> subst_term (__close_term_vs (i+1) vs t) [ND v i] let close_term_vs (vs : list var) (t : term) : term = __close_term_vs 0 vs t let close_term_bs (bs : list binding) (t : term) : term = close_term_vs (List.Tot.map fst bs) t let bindings_to_refl_bindings (bs : list binding) : list R.binding = L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs let refl_bindings_to_bindings (bs : list R.binding) : list binding = L.map (fun b -> b.uniq, b.sort) bs [@@ no_auto_projectors] noeq type non_informative : env -> term -> Type0 = | Non_informative_type: g:env -> u:universe -> non_informative g (pack_ln (Tv_Type u)) | Non_informative_fv: g:env -> x:fv{is_non_informative_fv x} -> non_informative g (pack_ln (Tv_FVar x)) | Non_informative_uinst: g:env -> x:fv{is_non_informative_fv x} -> us:list universe -> non_informative g (pack_ln (Tv_UInst x us)) | Non_informative_app: g:env -> t:term -> arg:argv -> non_informative g t -> non_informative g (pack_ln (Tv_App t arg)) | Non_informative_total_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g t1 -> non_informative g (mk_arrow_ct t0 q (T.E_Total, t1)) | Non_informative_ghost_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1)) | Non_informative_token: g:env -> t:typ -> squash (T.non_informative_token g t) -> non_informative g t val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0 val bindings_ok_pat_constant : g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c)) let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 = bindings_ok_for_pat g bs (fst br) let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) = zip2prop (bindings_ok_for_branch g) bss brs let binding_to_namedv (b:R.binding) : Tot namedv = pack_namedv { RD.uniq = b.uniq; RD.sort = seal b.sort; RD.ppname = b.ppname; } (* Elaborates the p pattern into a term, using the bs bindings for the pattern variables. The resulting term is properly scoped only on an environment which contains all of bs. See for instance the branch_typing judg. Returns an option, since this can fail if e.g. there are not enough bindings, and returns the list of unused binders as well, which
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Stubs.Reflection.V2.Data.pattern -> bs: Prims.list FStar.Stubs.Reflection.V2.Data.binding -> Prims.Tot (FStar.Pervasives.Native.option (FStar.Stubs.Reflection.Types.term * Prims.list FStar.Stubs.Reflection.V2.Data.binding))
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Stubs.Reflection.V2.Data.pattern", "Prims.list", "FStar.Stubs.Reflection.V2.Data.binding", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.vconst", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_Const", "FStar.Stubs.Reflection.Types.fv", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.V2.Data.universes", "Prims.bool", "FStar.Reflection.Typing.fold_left_dec", "Prims.precedes", "FStar.Pervasives.Native.None", "FStar.Reflection.Typing.elaborate_pat", "FStar.Stubs.Reflection.V2.Data.Tv_App", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Sealed.sealed", "FStar.Stubs.Reflection.V2.Data.ppname_t", "FStar.Stubs.Reflection.V2.Data.Tv_Var", "FStar.Reflection.Typing.binding_to_namedv" ]
[ "recursion" ]
false
false
false
true
false
let rec elaborate_pat (p: pattern) (bs: list R.binding) : Tot (option (term & list R.binding)) (decreases p) =
match p, bs with | Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs) | Pat_Cons fv univs subpats, bs -> let head = pack_ln (Tv_FVar fv) in fold_left_dec (Some (head, bs)) subpats (fun st pi -> let p, i = pi in match st with | None -> None | Some (head, bs) -> match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs')) | Pat_Var _ _, b :: bs -> Some (pack_ln (Tv_Var (binding_to_namedv b)), bs) | Pat_Dot_Term (Some t), _ -> Some (t, bs) | Pat_Dot_Term None, _ -> None | _ -> None
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_match_returns
val freevars_match_returns (m: match_returns_ascription) : Tot (Set.set var) (decreases m)
val freevars_match_returns (m: match_returns_ascription) : Tot (Set.set var) (decreases m)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Stubs.Reflection.Types.match_returns_ascription -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.Types.match_returns_ascription", "FStar.Stubs.Reflection.Types.binder", "FStar.Pervasives.either", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.comp", "FStar.Pervasives.Native.option", "Prims.bool", "FStar.Set.union", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.set", "FStar.Reflection.Typing.freevars_opt", "FStar.Reflection.Typing.freevars", "FStar.Reflection.Typing.freevars_comp", "FStar.Reflection.Typing.freevars_binder" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_match_returns (m: match_returns_ascription) : Tot (Set.set var) (decreases m) =
let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in (b `Set.union` ret) `Set.union` as_
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_branches
val freevars_branches (brs: list branch) : Tot (Set.set var) (decreases brs)
val freevars_branches (brs: list branch) : Tot (Set.set var) (decreases brs)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
brs: Prims.list FStar.Stubs.Reflection.V2.Data.branch -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Set.empty", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.union", "FStar.Reflection.Typing.freevars_branch", "FStar.Reflection.Typing.freevars_branches", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_branches (brs: list branch) : Tot (Set.set var) (decreases brs) =
match brs with | [] -> Set.empty | hd :: tl -> (freevars_branch hd) `Set.union` (freevars_branches tl)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_comp
val ln'_comp (c: comp) (i: int) : Tot bool (decreases c)
val ln'_comp (c: comp) (i: int) : Tot bool (decreases c)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: FStar.Stubs.Reflection.Types.comp -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.Types.comp", "Prims.int", "FStar.Stubs.Reflection.V2.Builtins.inspect_comp", "FStar.Stubs.Reflection.Types.typ", "FStar.Reflection.Typing.ln'", "FStar.Stubs.Reflection.Types.term", "Prims.op_AmpAmp", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Stubs.Reflection.Types.name", "Prims.list", "FStar.Stubs.Reflection.V2.Data.argv", "FStar.Reflection.Typing.ln'_args", "FStar.Reflection.Typing.ln'_terms", "Prims.bool" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_comp (c: comp) (i: int) : Tot bool (decreases c) =
match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_branch
val ln'_branch (br: branch) (i: int) : Tot bool (decreases br)
val ln'_branch (br: branch) (i: int) : Tot bool (decreases br)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
br: FStar.Stubs.Reflection.V2.Data.branch -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.V2.Data.branch", "Prims.int", "FStar.Stubs.Reflection.V2.Data.pattern", "FStar.Stubs.Reflection.Types.term", "Prims.op_AmpAmp", "Prims.bool", "FStar.Reflection.Typing.ln'", "Prims.op_Addition", "Prims.nat", "FStar.Reflection.Typing.binder_offset_pattern", "FStar.Reflection.Typing.ln'_pattern" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_branch (br: branch) (i: int) : Tot bool (decreases br) =
let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b && b'
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_pattern
val ln'_pattern (p: pattern) (i: int) : Tot bool (decreases p)
val ln'_pattern (p: pattern) (i: int) : Tot bool (decreases p)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Stubs.Reflection.V2.Data.pattern -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.V2.Data.pattern", "Prims.int", "FStar.Stubs.Reflection.V2.Data.vconst", "FStar.Stubs.Reflection.Types.fv", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.V2.Data.universes", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.bool", "FStar.Reflection.Typing.ln'_patterns", "FStar.Sealed.sealed", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.ppname_t", "FStar.Reflection.Typing.ln'" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_pattern (p: pattern) (i: int) : Tot bool (decreases p) =
match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_terms
val freevars_terms (ts: list term) : FStar.Set.set var
val freevars_terms (ts: list term) : FStar.Set.set var
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list FStar.Stubs.Reflection.Types.term -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var
Prims.Tot
[ "total" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.Types.term", "FStar.Set.empty", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.union", "FStar.Reflection.Typing.freevars", "FStar.Reflection.Typing.freevars_terms", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_terms (ts: list term) : FStar.Set.set var =
match ts with | [] -> Set.empty | t :: ts -> (freevars t) `Set.union` (freevars_terms ts)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_match_returns
val ln'_match_returns (m: match_returns_ascription) (i: int) : Tot bool (decreases m)
val ln'_match_returns (m: match_returns_ascription) (i: int) : Tot bool (decreases m)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Stubs.Reflection.Types.match_returns_ascription -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.Types.match_returns_ascription", "Prims.int", "FStar.Stubs.Reflection.Types.binder", "FStar.Pervasives.either", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.comp", "FStar.Pervasives.Native.option", "Prims.bool", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'", "Prims.op_Addition", "FStar.Reflection.Typing.ln'_comp", "FStar.Reflection.Typing.ln'_binder" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_match_returns (m: match_returns_ascription) (i: int) : Tot bool (decreases m) =
let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_binder
val ln'_binder (b: binder) (n: int) : Tot bool (decreases b)
val ln'_binder (b: binder) (n: int) : Tot bool (decreases b)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Stubs.Reflection.Types.binder -> n: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.Types.binder", "Prims.int", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Reflection.Typing.ln'_terms", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Stubs.Reflection.V2.Data.binder_view", "Prims.precedes", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "Prims.bool" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_binder (b: binder) (n: int) : Tot bool (decreases b) =
let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_patterns
val ln'_patterns (ps: list (pattern & bool)) (i: int) : Tot bool (decreases ps)
val ln'_patterns (ps: list (pattern & bool)) (i: int) : Tot bool (decreases ps)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ps: Prims.list (FStar.Stubs.Reflection.V2.Data.pattern * Prims.bool) -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V2.Data.pattern", "Prims.bool", "Prims.int", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'_patterns", "Prims.op_Addition", "Prims.nat", "FStar.Reflection.Typing.binder_offset_pattern", "FStar.Reflection.Typing.ln'_pattern" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_patterns (ps: list (pattern & bool)) (i: int) : Tot bool (decreases ps) =
match ps with | [] -> true | (p, b) :: ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_opt
val freevars_opt (#a: Type0) (o: option a) (f: (x: a{x << o} -> FStar.Set.set var)) : FStar.Set.set var
val freevars_opt (#a: Type0) (o: option a) (f: (x: a{x << o} -> FStar.Set.set var)) : FStar.Set.set var
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Pervasives.Native.option a -> f: (x: a{x << o} -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var) -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var
Prims.Tot
[ "total" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Pervasives.Native.option", "Prims.precedes", "FStar.Set.set", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.empty" ]
[ "mutual recursion" ]
false
false
false
false
false
let rec freevars_opt (#a: Type0) (o: option a) (f: (x: a{x << o} -> FStar.Set.set var)) : FStar.Set.set var =
match o with | None -> Set.empty | Some x -> f x
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_patterns
val freevars_patterns (ps: list (pattern & bool)) : Tot (Set.set var) (decreases ps)
val freevars_patterns (ps: list (pattern & bool)) : Tot (Set.set var) (decreases ps)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ps: Prims.list (FStar.Stubs.Reflection.V2.Data.pattern * Prims.bool) -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V2.Data.pattern", "Prims.bool", "FStar.Set.empty", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Set.union", "FStar.Reflection.Typing.freevars_pattern", "FStar.Reflection.Typing.freevars_patterns", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_patterns (ps: list (pattern & bool)) : Tot (Set.set var) (decreases ps) =
match ps with | [] -> Set.empty | (p, b) :: ps -> (freevars_pattern p) `Set.union` (freevars_patterns ps)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_comp
val freevars_comp (c: comp) : FStar.Set.set var
val freevars_comp (c: comp) : FStar.Set.set var
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: FStar.Stubs.Reflection.Types.comp -> FStar.Set.set FStar.Stubs.Reflection.V2.Data.var
Prims.Tot
[ "total" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.Types.comp", "FStar.Stubs.Reflection.V2.Builtins.inspect_comp", "FStar.Stubs.Reflection.Types.typ", "FStar.Reflection.Typing.freevars", "FStar.Stubs.Reflection.Types.term", "FStar.Set.union", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Stubs.Reflection.Types.name", "Prims.list", "FStar.Stubs.Reflection.V2.Data.argv", "FStar.Reflection.Typing.freevars_args", "FStar.Reflection.Typing.freevars_terms", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_comp (c: comp) : FStar.Set.set var =
match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> ((freevars pre) `Set.union` (freevars post)) `Set.union` (freevars pats) | C_Eff us eff_name res args decrs -> ((freevars res) `Set.union` (freevars_args args)) `Set.union` (freevars_terms decrs)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_terms
val ln'_terms (ts: list term) (n: int) : Tot bool (decreases ts)
val ln'_terms (ts: list term) (n: int) : Tot bool (decreases ts)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list FStar.Stubs.Reflection.Types.term -> n: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.Types.term", "Prims.int", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'", "FStar.Reflection.Typing.ln'_terms", "Prims.bool" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_terms (ts: list term) (n: int) : Tot bool (decreases ts) =
match ts with | [] -> true | t :: ts -> ln' t n && ln'_terms ts n
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'_args
val ln'_args (ts: list argv) (i: int) : Tot bool (decreases ts)
val ln'_args (ts: list argv) (i: int) : Tot bool (decreases ts)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list FStar.Stubs.Reflection.V2.Data.argv -> i: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "Prims.list", "FStar.Stubs.Reflection.V2.Data.argv", "Prims.int", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'", "FStar.Reflection.Typing.ln'_args", "Prims.bool" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln'_args (ts: list argv) (i: int) : Tot bool (decreases ts) =
match ts with | [] -> true | (t, q) :: ts -> ln' t i && ln'_args ts i
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_pattern
val freevars_pattern (p: pattern) : Tot (Set.set var) (decreases p)
val freevars_pattern (p: pattern) : Tot (Set.set var) (decreases p)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Stubs.Reflection.V2.Data.pattern -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.V2.Data.pattern", "FStar.Stubs.Reflection.V2.Data.vconst", "FStar.Set.empty", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Stubs.Reflection.Types.fv", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.V2.Data.universes", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.bool", "FStar.Reflection.Typing.freevars_patterns", "FStar.Sealed.sealed", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.ppname_t", "FStar.Reflection.Typing.freevars_opt", "FStar.Reflection.Typing.freevars", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_pattern (p: pattern) : Tot (Set.set var) (decreases p) =
match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.freevars_branch
val freevars_branch (br: branch) : Tot (Set.set var) (decreases br)
val freevars_branch (br: branch) : Tot (Set.set var) (decreases br)
let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 705, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
br: FStar.Stubs.Reflection.V2.Data.branch -> Prims.Tot (FStar.Set.set FStar.Stubs.Reflection.V2.Data.var)
Prims.Tot
[ "total", "" ]
[ "freevars", "freevars_opt", "freevars_comp", "freevars_args", "freevars_terms", "freevars_binder", "freevars_pattern", "freevars_patterns", "freevars_branch", "freevars_branches", "freevars_match_returns" ]
[ "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Stubs.Reflection.V2.Data.pattern", "FStar.Stubs.Reflection.Types.term", "FStar.Set.union", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Reflection.Typing.freevars_pattern", "FStar.Reflection.Typing.freevars", "FStar.Set.set" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec freevars_branch (br: branch) : Tot (Set.set var) (decreases br) =
let p, t = br in (freevars_pattern p) `Set.union` (freevars t)
false
PulseCore.Action.fsti
PulseCore.Action.inames
val inames : Type0
let inames = Ghost.erased (FStar.Set.set iname)
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 10, "start_col": 0, "start_line": 10 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Set.set", "PulseCore.Action.iname" ]
[]
false
false
false
true
true
let inames =
Ghost.erased (FStar.Set.set iname)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.ln'
val ln' (e: term) (n: int) : Tot bool (decreases e)
val ln' (e: term) (n: int) : Tot bool (decreases e)
let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 855, "start_col": 0, "start_line": 708 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: FStar.Stubs.Reflection.Types.term -> n: Prims.int -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[ "ln'", "ln'_comp", "ln'_args", "ln'_binder", "ln'_terms", "ln'_patterns", "ln'_pattern", "ln'_branch", "ln'_branches", "ln'_match_returns" ]
[ "FStar.Stubs.Reflection.Types.term", "Prims.int", "FStar.Stubs.Reflection.V2.Builtins.inspect_ln", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.V2.Data.vconst", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.Types.bv", "Prims.op_LessThanOrEqual", "FStar.Reflection.Typing.bv_index", "FStar.Stubs.Reflection.V2.Data.aqualv", "Prims.op_AmpAmp", "FStar.Reflection.Typing.ln'", "FStar.Stubs.Reflection.Types.binder", "FStar.Reflection.Typing.ln'_binder", "Prims.op_Addition", "FStar.Stubs.Reflection.Types.comp", "FStar.Reflection.Typing.ln'_comp", "FStar.Stubs.Reflection.V2.Data.simple_binder", "Prims.nat", "FStar.Stubs.Reflection.Types.ctx_uvar_and_subst", "Prims.bool", "Prims.list", "FStar.Reflection.Typing.ln'_terms", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.match_returns_ascription", "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Reflection.Typing.ln'_match_returns", "FStar.Reflection.Typing.ln'_branches" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec ln' (e: term) (n: int) : Tot bool (decreases e) =
match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n)
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.psquash
val psquash (a: Type u#a) : prop
val psquash (a: Type u#a) : prop
let psquash (a:Type u#a) : prop = squash a
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 8, "start_col": 0, "start_line": 8 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p ()
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.prop" ]
[]
false
false
false
true
true
let psquash (a: Type u#a) : prop =
squash a
false
PulseCore.Action.fsti
PulseCore.Action.emp_inames
val emp_inames:inames
val emp_inames:inames
let emp_inames : inames = Ghost.hide Set.empty
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 12, "start_col": 0, "start_line": 12 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname)
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
PulseCore.Action.inames
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.hide", "FStar.Set.set", "PulseCore.Action.iname", "FStar.Set.empty" ]
[]
false
false
false
true
false
let emp_inames:inames =
Ghost.hide Set.empty
false
PulseCore.Action.fsti
PulseCore.Action.join_inames
val join_inames (is1 is2: inames) : inames
val join_inames (is1 is2: inames) : inames
let join_inames (is1 is2 : inames) : inames = Set.union is1 is2
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 15, "start_col": 0, "start_line": 14 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
is1: PulseCore.Action.inames -> is2: PulseCore.Action.inames -> PulseCore.Action.inames
Prims.Tot
[ "total" ]
[]
[ "PulseCore.Action.inames", "FStar.Ghost.hide", "FStar.Set.set", "PulseCore.Action.iname", "FStar.Set.union", "FStar.Ghost.reveal" ]
[]
false
false
false
true
false
let join_inames (is1 is2: inames) : inames =
Set.union is1 is2
false
PulseCore.Action.fsti
PulseCore.Action.inames_subset
val inames_subset (is1 is2: inames) : Type0
val inames_subset (is1 is2: inames) : Type0
let inames_subset (is1 is2 : inames) : Type0 = Set.subset is1 is2
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 20, "end_line": 18, "start_col": 0, "start_line": 17 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty let join_inames (is1 is2 : inames) : inames = Set.union is1 is2
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
is1: PulseCore.Action.inames -> is2: PulseCore.Action.inames -> Type0
Prims.Tot
[ "total" ]
[]
[ "PulseCore.Action.inames", "FStar.Set.subset", "PulseCore.Action.iname", "FStar.Ghost.reveal", "FStar.Set.set" ]
[]
false
false
false
true
true
let inames_subset (is1 is2: inames) : Type0 =
Set.subset is1 is2
false
PulseCore.Action.fsti
PulseCore.Action.add_inv
val add_inv (#p: _) (opens: inames) (i: inv p) : inames
val add_inv (#p: _) (opens: inames) (i: inv p) : inames
let add_inv (#p:_) (opens:inames) (i:inv p) : inames = Set.union (Set.singleton (name_of_inv i)) opens
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 103, "start_col": 0, "start_line": 101 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty let join_inames (is1 is2 : inames) : inames = Set.union is1 is2 let inames_subset (is1 is2 : inames) : Type0 = Set.subset is1 is2 let (/!) (is1 is2 : inames) : Type0 = Set.disjoint is1 is2 unfold let inames_disj (ictx:inames) : Type = is:inames{is /! ictx} val act (a:Type u#a) (opens:inames) (pre:slprop) (post:a -> slprop) : Type u#(max a 2) val return (#a:Type u#a) (#post:a -> slprop) (x:a) : act a emp_inames (post x) post val bind (#a:Type u#a) (#b:Type u#b) (#opens:inames) (#pre1 #post1 #post2:_) (f:act a opens pre1 post1) (g:(x:a -> act b opens (post1 x) post2)) : act b opens pre1 post2 val frame (#a:Type u#a) (#opens:inames) (#pre #post #frame:_) (f:act a opens pre post) : act a opens (pre ** frame) (fun x -> post x ** frame) val weaken (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens opens':inames) (f:act a opens pre post) : act a (Set.union opens opens') pre post val sub (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens:inames) (pre':slprop { slprop_equiv pre pre' }) (post':a -> slprop { forall x. slprop_equiv (post x) (post' x) }) (f:act a opens pre post) : act a opens pre' post' val lift (#a:Type u#100) #opens (#pre:slprop) (#post:a -> slprop) (m:act a opens pre post) : I.stt a pre post val lift0 (#a:Type u#0) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift1 (#a:Type u#1) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift2 (#a:Type u#2) #opens #pre #post (m:act a opens pre post) : I.stt a pre post ////////////////////////////////////////////////////////////////////// // Invariants ////////////////////////////////////////////////////////////////////// val inv (p:slprop) : Type0 val name_of_inv #p (i:inv p) : GTot iname let mem_inv (#p:_) (opens:inames) (i:inv p) : GTot bool = Set.mem (name_of_inv i) opens
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
opens: PulseCore.Action.inames -> i: PulseCore.Action.inv p -> PulseCore.Action.inames
Prims.Tot
[ "total" ]
[]
[ "PulseCore.InstantiatedSemantics.slprop", "PulseCore.Action.inames", "PulseCore.Action.inv", "FStar.Ghost.hide", "FStar.Set.set", "PulseCore.Action.iname", "FStar.Set.union", "FStar.Set.singleton", "PulseCore.Action.name_of_inv", "FStar.Ghost.reveal" ]
[]
false
false
false
false
false
let add_inv (#p: _) (opens: inames) (i: inv p) : inames =
Set.union (Set.singleton (name_of_inv i)) opens
false
PulseCore.Action.fsti
PulseCore.Action.mem_inv
val mem_inv (#p: _) (opens: inames) (i: inv p) : GTot bool
val mem_inv (#p: _) (opens: inames) (i: inv p) : GTot bool
let mem_inv (#p:_) (opens:inames) (i:inv p) : GTot bool = Set.mem (name_of_inv i) opens
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 99, "start_col": 0, "start_line": 97 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty let join_inames (is1 is2 : inames) : inames = Set.union is1 is2 let inames_subset (is1 is2 : inames) : Type0 = Set.subset is1 is2 let (/!) (is1 is2 : inames) : Type0 = Set.disjoint is1 is2 unfold let inames_disj (ictx:inames) : Type = is:inames{is /! ictx} val act (a:Type u#a) (opens:inames) (pre:slprop) (post:a -> slprop) : Type u#(max a 2) val return (#a:Type u#a) (#post:a -> slprop) (x:a) : act a emp_inames (post x) post val bind (#a:Type u#a) (#b:Type u#b) (#opens:inames) (#pre1 #post1 #post2:_) (f:act a opens pre1 post1) (g:(x:a -> act b opens (post1 x) post2)) : act b opens pre1 post2 val frame (#a:Type u#a) (#opens:inames) (#pre #post #frame:_) (f:act a opens pre post) : act a opens (pre ** frame) (fun x -> post x ** frame) val weaken (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens opens':inames) (f:act a opens pre post) : act a (Set.union opens opens') pre post val sub (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens:inames) (pre':slprop { slprop_equiv pre pre' }) (post':a -> slprop { forall x. slprop_equiv (post x) (post' x) }) (f:act a opens pre post) : act a opens pre' post' val lift (#a:Type u#100) #opens (#pre:slprop) (#post:a -> slprop) (m:act a opens pre post) : I.stt a pre post val lift0 (#a:Type u#0) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift1 (#a:Type u#1) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift2 (#a:Type u#2) #opens #pre #post (m:act a opens pre post) : I.stt a pre post ////////////////////////////////////////////////////////////////////// // Invariants ////////////////////////////////////////////////////////////////////// val inv (p:slprop) : Type0 val name_of_inv #p (i:inv p) : GTot iname
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
opens: PulseCore.Action.inames -> i: PulseCore.Action.inv p -> Prims.GTot Prims.bool
Prims.GTot
[ "sometrivial" ]
[]
[ "PulseCore.InstantiatedSemantics.slprop", "PulseCore.Action.inames", "PulseCore.Action.inv", "FStar.Set.mem", "PulseCore.Action.iname", "PulseCore.Action.name_of_inv", "FStar.Ghost.reveal", "FStar.Set.set", "Prims.bool" ]
[]
false
false
false
false
false
let mem_inv (#p: _) (opens: inames) (i: inv p) : GTot bool =
Set.mem (name_of_inv i) opens
false
PulseCore.Action.fsti
PulseCore.Action.property
val property : a: Type -> Type
let property (a:Type) = a -> prop
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 186, "start_col": 0, "start_line": 185 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty let join_inames (is1 is2 : inames) : inames = Set.union is1 is2 let inames_subset (is1 is2 : inames) : Type0 = Set.subset is1 is2 let (/!) (is1 is2 : inames) : Type0 = Set.disjoint is1 is2 unfold let inames_disj (ictx:inames) : Type = is:inames{is /! ictx} val act (a:Type u#a) (opens:inames) (pre:slprop) (post:a -> slprop) : Type u#(max a 2) val return (#a:Type u#a) (#post:a -> slprop) (x:a) : act a emp_inames (post x) post val bind (#a:Type u#a) (#b:Type u#b) (#opens:inames) (#pre1 #post1 #post2:_) (f:act a opens pre1 post1) (g:(x:a -> act b opens (post1 x) post2)) : act b opens pre1 post2 val frame (#a:Type u#a) (#opens:inames) (#pre #post #frame:_) (f:act a opens pre post) : act a opens (pre ** frame) (fun x -> post x ** frame) val weaken (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens opens':inames) (f:act a opens pre post) : act a (Set.union opens opens') pre post val sub (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens:inames) (pre':slprop { slprop_equiv pre pre' }) (post':a -> slprop { forall x. slprop_equiv (post x) (post' x) }) (f:act a opens pre post) : act a opens pre' post' val lift (#a:Type u#100) #opens (#pre:slprop) (#post:a -> slprop) (m:act a opens pre post) : I.stt a pre post val lift0 (#a:Type u#0) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift1 (#a:Type u#1) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift2 (#a:Type u#2) #opens #pre #post (m:act a opens pre post) : I.stt a pre post ////////////////////////////////////////////////////////////////////// // Invariants ////////////////////////////////////////////////////////////////////// val inv (p:slprop) : Type0 val name_of_inv #p (i:inv p) : GTot iname let mem_inv (#p:_) (opens:inames) (i:inv p) : GTot bool = Set.mem (name_of_inv i) opens let add_inv (#p:_) (opens:inames) (i:inv p) : inames = Set.union (Set.singleton (name_of_inv i)) opens val new_invariant (p:slprop) : act (inv p) emp_inames p (fun _ -> emp) val with_invariant (#a:Type) (#fp:slprop) (#fp':a -> slprop) (#f_opens:inames) (#p:slprop) (i:inv p{not (mem_inv f_opens i)}) (f:unit -> act a f_opens (p ** fp) (fun x -> p ** fp' x)) : act a (add_inv f_opens i) fp fp' //////////////////////////////////////////////////////////////////////// // References //////////////////////////////////////////////////////////////////////// val ref ([@@@unused] a:Type u#a) ([@@@unused] p:pcm a) : Type u#0 val ref_null (#a:Type u#a) (p:pcm a) : ref a p val is_ref_null (#a:Type) (#p:FStar.PCM.pcm a) (r:ref a p) : b:bool { b <==> r == ref_null p } val pts_to (#a:Type u#1) (#p:pcm a) (r:ref a p) (v:a) : slprop val pts_to_not_null (#a:Type) (#p:FStar.PCM.pcm a) (r:ref a p) (v:a) : act (squash (not (is_ref_null r))) emp_inames (pts_to r v) (fun _ -> pts_to r v) val alloc (#a:Type u#1) (#pcm:pcm a) (x:a{compatible pcm x x /\ pcm.refine x}) : act (ref a pcm) emp_inames emp (fun r -> pts_to r x) val read (#a:Type) (#p:pcm a) (r:ref a p) (x:erased a) (f:(v:a{compatible p x v} -> GTot (y:a{compatible p y v /\ FStar.PCM.frame_compatible p x v y}))) : act (v:a{compatible p x v /\ p.refine v}) emp_inames (pts_to r x) (fun v -> pts_to r (f v)) val write (#a:Type) (#p:pcm a) (r:ref a p) (x y:Ghost.erased a) (f:FStar.PCM.frame_preserving_upd p x y) : act unit emp_inames (pts_to r x) (fun _ -> pts_to r y) val share (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v0:FStar.Ghost.erased a) (v1:FStar.Ghost.erased a{composable pcm v0 v1}) : act unit emp_inames (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 ** pts_to r v1) val gather (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v0:FStar.Ghost.erased a) (v1:FStar.Ghost.erased a) : act (squash (composable pcm v0 v1)) emp_inames (pts_to r v0 ** pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.prop" ]
[]
false
false
false
true
true
let property (a: Type) =
a -> prop
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x
val normalize5_second_part_x : x: Lib.IntTypes.uint64 -> _: ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) -> Hacl.Spec.K256.Field52.Definitions.felem5
let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 217, "start_col": 0, "start_line": 211 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> _: ((((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) -> Hacl.Spec.K256.Field52.Definitions.felem5
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.uint64", "FStar.Pervasives.Native.tuple5", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.Definitions.felem5", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256", "Hacl.Spec.K256.Field52.plus_x_mul_pow2_256_minus_prime", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.u64", "Hacl.Spec.K256.Field52.is_felem_ge_prime5" ]
[]
false
false
false
true
false
let normalize5_second_part_x (x: uint64) (r0, r1, r2, r3, r4) : felem5 =
let is_ge_p_m = is_felem_ge_prime5 (r0, r1, r2, r3, r4) in let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let s0, s1, s2, s3, s4 = plus_x_mul_pow2_256_minus_prime x1 (r0, r1, r2, r3, r4) in let x2, (k0, k1, k2, k3, k4) = minus_x_mul_pow2_256 (s0, s1, s2, s3, s4) in (k0, k1, k2, k3, k4)
false
PulseCore.Action.fsti
PulseCore.Action.stable_property
val stable_property : pcm: FStar.PCM.pcm a -> Type
let stable_property (#a:Type) (pcm:pcm a) = fact:property a { FStar.Preorder.stable fact (PP.preorder_of_pcm pcm) }
{ "file_name": "lib/pulse_core/PulseCore.Action.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 197, "start_col": 0, "start_line": 194 }
module PulseCore.Action module I = PulseCore.InstantiatedSemantics module PP = PulseCore.Preorder open PulseCore.InstantiatedSemantics open FStar.PCM open FStar.Ghost val iname : eqtype let inames = Ghost.erased (FStar.Set.set iname) let emp_inames : inames = Ghost.hide Set.empty let join_inames (is1 is2 : inames) : inames = Set.union is1 is2 let inames_subset (is1 is2 : inames) : Type0 = Set.subset is1 is2 let (/!) (is1 is2 : inames) : Type0 = Set.disjoint is1 is2 unfold let inames_disj (ictx:inames) : Type = is:inames{is /! ictx} val act (a:Type u#a) (opens:inames) (pre:slprop) (post:a -> slprop) : Type u#(max a 2) val return (#a:Type u#a) (#post:a -> slprop) (x:a) : act a emp_inames (post x) post val bind (#a:Type u#a) (#b:Type u#b) (#opens:inames) (#pre1 #post1 #post2:_) (f:act a opens pre1 post1) (g:(x:a -> act b opens (post1 x) post2)) : act b opens pre1 post2 val frame (#a:Type u#a) (#opens:inames) (#pre #post #frame:_) (f:act a opens pre post) : act a opens (pre ** frame) (fun x -> post x ** frame) val weaken (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens opens':inames) (f:act a opens pre post) : act a (Set.union opens opens') pre post val sub (#a:Type) (#pre:slprop) (#post:a -> slprop) (#opens:inames) (pre':slprop { slprop_equiv pre pre' }) (post':a -> slprop { forall x. slprop_equiv (post x) (post' x) }) (f:act a opens pre post) : act a opens pre' post' val lift (#a:Type u#100) #opens (#pre:slprop) (#post:a -> slprop) (m:act a opens pre post) : I.stt a pre post val lift0 (#a:Type u#0) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift1 (#a:Type u#1) #opens #pre #post (m:act a opens pre post) : I.stt a pre post val lift2 (#a:Type u#2) #opens #pre #post (m:act a opens pre post) : I.stt a pre post ////////////////////////////////////////////////////////////////////// // Invariants ////////////////////////////////////////////////////////////////////// val inv (p:slprop) : Type0 val name_of_inv #p (i:inv p) : GTot iname let mem_inv (#p:_) (opens:inames) (i:inv p) : GTot bool = Set.mem (name_of_inv i) opens let add_inv (#p:_) (opens:inames) (i:inv p) : inames = Set.union (Set.singleton (name_of_inv i)) opens val new_invariant (p:slprop) : act (inv p) emp_inames p (fun _ -> emp) val with_invariant (#a:Type) (#fp:slprop) (#fp':a -> slprop) (#f_opens:inames) (#p:slprop) (i:inv p{not (mem_inv f_opens i)}) (f:unit -> act a f_opens (p ** fp) (fun x -> p ** fp' x)) : act a (add_inv f_opens i) fp fp' //////////////////////////////////////////////////////////////////////// // References //////////////////////////////////////////////////////////////////////// val ref ([@@@unused] a:Type u#a) ([@@@unused] p:pcm a) : Type u#0 val ref_null (#a:Type u#a) (p:pcm a) : ref a p val is_ref_null (#a:Type) (#p:FStar.PCM.pcm a) (r:ref a p) : b:bool { b <==> r == ref_null p } val pts_to (#a:Type u#1) (#p:pcm a) (r:ref a p) (v:a) : slprop val pts_to_not_null (#a:Type) (#p:FStar.PCM.pcm a) (r:ref a p) (v:a) : act (squash (not (is_ref_null r))) emp_inames (pts_to r v) (fun _ -> pts_to r v) val alloc (#a:Type u#1) (#pcm:pcm a) (x:a{compatible pcm x x /\ pcm.refine x}) : act (ref a pcm) emp_inames emp (fun r -> pts_to r x) val read (#a:Type) (#p:pcm a) (r:ref a p) (x:erased a) (f:(v:a{compatible p x v} -> GTot (y:a{compatible p y v /\ FStar.PCM.frame_compatible p x v y}))) : act (v:a{compatible p x v /\ p.refine v}) emp_inames (pts_to r x) (fun v -> pts_to r (f v)) val write (#a:Type) (#p:pcm a) (r:ref a p) (x y:Ghost.erased a) (f:FStar.PCM.frame_preserving_upd p x y) : act unit emp_inames (pts_to r x) (fun _ -> pts_to r y) val share (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v0:FStar.Ghost.erased a) (v1:FStar.Ghost.erased a{composable pcm v0 v1}) : act unit emp_inames (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 ** pts_to r v1) val gather (#a:Type) (#pcm:pcm a) (r:ref a pcm) (v0:FStar.Ghost.erased a) (v1:FStar.Ghost.erased a) : act (squash (composable pcm v0 v1)) emp_inames (pts_to r v0 ** pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1)) let property (a:Type) = a -> prop val witnessed (#a:Type u#1) (#pcm:pcm a) (r:ref a pcm) (fact:property a) : Type0
{ "checked_file": "/", "dependencies": [ "PulseCore.Preorder.fst.checked", "PulseCore.InstantiatedSemantics.fsti.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Action.fsti" }
[ { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": true, "full_module": "PulseCore.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "PulseCore.Semantics", "short_module": "Sem" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.InstantiatedSemantics", "short_module": null }, { "abbrev": true, "full_module": "PulseCore.Preorder", "short_module": "PP" }, { "abbrev": true, "full_module": "PulseCore.InstantiatedSemantics", "short_module": "I" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pcm: FStar.PCM.pcm a -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.PCM.pcm", "PulseCore.Action.property", "FStar.Preorder.stable", "PulseCore.Preorder.preorder_of_pcm" ]
[]
false
false
false
true
true
let stable_property (#a: Type) (pcm: pcm a) =
fact: property a {FStar.Preorder.stable fact (PP.preorder_of_pcm pcm)}
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.ghost_witness2
val ghost_witness2 (a:Type u#2) (_:squash a) : stt_ghost a emp (fun _ -> emp)
val ghost_witness2 (a:Type u#2) (_:squash a) : stt_ghost a emp (fun _ -> emp)
let ghost_witness2 = __ghost_witness2
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 40, "start_col": 0, "start_line": 40 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p () let psquash (a:Type u#a) : prop = squash a ```pulse ghost fn __ghost_witness (a:Type u#0) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i } ``` let ghost_witness = __ghost_witness ```pulse ghost fn __ghost_witness2 (a:Type u#2) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> _: Prims.squash a -> Pulse.Lib.Core.stt_ghost a Pulse.Lib.Core.emp (fun _ -> Pulse.Lib.Core.emp)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.GhostWitness.__ghost_witness2" ]
[]
false
false
false
false
false
let ghost_witness2 =
__ghost_witness2
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.ghost_witness
val ghost_witness (a:Type u#0) (_:squash a) : stt_ghost a emp (fun _ -> emp)
val ghost_witness (a:Type u#0) (_:squash a) : stt_ghost a emp (fun _ -> emp)
let ghost_witness = __ghost_witness
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 24, "start_col": 0, "start_line": 24 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p () let psquash (a:Type u#a) : prop = squash a ```pulse ghost fn __ghost_witness (a:Type u#0) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> _: Prims.squash a -> Pulse.Lib.Core.stt_ghost a Pulse.Lib.Core.emp (fun _ -> Pulse.Lib.Core.emp)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.GhostWitness.__ghost_witness" ]
[]
false
false
false
false
false
let ghost_witness =
__ghost_witness
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.ghost_witness_exists
val ghost_witness_exists (a:Type u#0) : stt_ghost a (pure (exists (x:a). True)) (fun _ -> emp)
val ghost_witness_exists (a:Type u#0) : stt_ghost a (pure (exists (x:a). True)) (fun _ -> emp)
let ghost_witness_exists = __ghost_witness_exists
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 52, "start_col": 0, "start_line": 52 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p () let psquash (a:Type u#a) : prop = squash a ```pulse ghost fn __ghost_witness (a:Type u#0) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i } ``` let ghost_witness = __ghost_witness ```pulse ghost fn __ghost_witness2 (a:Type u#2) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i } ``` let ghost_witness2 = __ghost_witness2 ```pulse ghost fn __ghost_witness_exists (a:Type u#0) requires pure (exists (x:a). True) returns i:a ensures emp { ghost_witness a (); }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> Pulse.Lib.Core.stt_ghost a (Pulse.Lib.Core.pure (exists (x: a). Prims.l_True)) (fun _ -> Pulse.Lib.Core.emp)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.GhostWitness.__ghost_witness_exists" ]
[]
false
false
false
false
false
let ghost_witness_exists =
__ghost_witness_exists
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.ghost_witness_exists2
val ghost_witness_exists2 (a:Type u#2) : stt_ghost a (pure (exists (x:a). True)) (fun _ -> emp)
val ghost_witness_exists2 (a:Type u#2) : stt_ghost a (pure (exists (x:a). True)) (fun _ -> emp)
let ghost_witness_exists2 = __ghost_witness_exists2
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 64, "start_col": 0, "start_line": 64 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p () let psquash (a:Type u#a) : prop = squash a ```pulse ghost fn __ghost_witness (a:Type u#0) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i } ``` let ghost_witness = __ghost_witness ```pulse ghost fn __ghost_witness2 (a:Type u#2) (_:squash a) requires emp returns i:a ensures emp { let pf = elim_pure_explicit (psquash a); let pf : squash a = FStar.Squash.join_squash pf; let i = sqeq a pf; let i = reveal i; i } ``` let ghost_witness2 = __ghost_witness2 ```pulse ghost fn __ghost_witness_exists (a:Type u#0) requires pure (exists (x:a). True) returns i:a ensures emp { ghost_witness a (); } ``` let ghost_witness_exists = __ghost_witness_exists ```pulse ghost fn __ghost_witness_exists2 (a:Type u#2) requires pure (exists (x:a). True) returns i:a ensures emp { ghost_witness2 a (); }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Pulse.Lib.Core.stt_ghost a (Pulse.Lib.Core.pure (exists (x: a). Prims.l_True)) (fun _ -> Pulse.Lib.Core.emp)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.GhostWitness.__ghost_witness_exists2" ]
[]
false
false
false
false
false
let ghost_witness_exists2 =
__ghost_witness_exists2
false
Vale.X64.BufferViewStore.fst
Vale.X64.BufferViewStore.get128_aux
val get128_aux (ptr: int) (heap: machine_heap) (v: quad32) (k: nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put128 v) k))
val get128_aux (ptr: int) (heap: machine_heap) (v: quad32) (k: nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put128 v) k))
let get128_aux (ptr:int) (heap:machine_heap) (v:quad32) (k:nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put128 v) k)) = get_heap_val128_reveal (); get_heap_val32_reveal (); put128_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; four_to_nat_8_injective ()
{ "file_name": "vale/code/arch/x64/Vale.X64.BufferViewStore.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 48, "start_col": 0, "start_line": 40 }
module Vale.X64.BufferViewStore open FStar.Mul open Vale.Interop.Views open Vale.Interop module MB = LowStar.Monotonic.Buffer module HS = FStar.HyperStack open Vale.Lib.BufferViewHelpers open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Two open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open Vale.Arch.Types open FStar.Calc friend LowStar.BufferView.Up #reset-options "--z3rlimit 10 --max_fuel 0 --initial_fuel 0 --max_ifuel 1 --initial_ifuel 1" let math_aux (a b c:int) : Lemma (a + b + (c - b) == a + c) = () let map_aux (ptr1 ptr2:int) (v:int) (m:machine_heap) : Lemma (requires ptr1 == ptr2 /\ m.[ptr1] == v) (ensures m.[ptr2] == v) = () let get64_aux (ptr:int) (heap:machine_heap) (v:nat64) (k:nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)) = get_heap_val64_reveal (); put64_reveal (); le_nat64_to_bytes_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); four_to_nat_8_injective (); two_to_nat_32_injective ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Two.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferView.Up.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.BufferViewStore.fst" }
[ { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> heap: Vale.Arch.MachineHeap_s.machine_heap -> v: Vale.Def.Types_s.quad32 -> k: Prims.nat{k < 16} -> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.get_heap_val128 ptr heap == v) (ensures heap.[ ptr + k ] == FStar.UInt8.v (FStar.Seq.Base.index (Vale.Interop.Views.put128 v) k))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Words.Seq.four_to_nat_8_injective", "Prims.unit", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.l_True", "Prims.eq2", "FStar.Seq.Base.length", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat8", "FStar.Mul.op_Star", "Vale.Def.Words.Seq_s.seq_four_to_seq_LE", "Vale.Interop.Views.put128_reveal", "Vale.Arch.MachineHeap_s.get_heap_val32_reveal", "Vale.Arch.MachineHeap_s.get_heap_val128_reveal", "Vale.Arch.MachineHeap_s.get_heap_val128", "Prims.squash", "Prims.l_or", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Vale.Def.Words_s.pow2_8", "FStar.UInt.size", "FStar.UInt8.n", "Vale.Interop.op_String_Access", "Prims.op_Addition", "FStar.UInt8.v", "FStar.Seq.Base.index", "FStar.UInt8.t", "Vale.Interop.Views.put128", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let get128_aux (ptr: int) (heap: machine_heap) (v: quad32) (k: nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put128 v) k)) =
get_heap_val128_reveal (); get_heap_val32_reveal (); put128_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; four_to_nat_8_injective ()
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize_weak5_lemma
val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 162, "start_col": 0, "start_line": 148 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 _ = _ in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 f m) <: Type0)) (ensures (let r = Hacl.Spec.K256.Field52.normalize_weak5 f in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ t4 = _ in Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f - (Lib.IntTypes.v t4 / Prims.pow2 48) * Spec.K256.PointOps.prime /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 2) /\ Lib.IntTypes.v r4 < Lib.IntTypes.v t4 + Prims.pow2 12 /\ (Lib.IntTypes.v r4 >= Prims.pow2 48 ==> Lib.IntTypes.v r4 % Prims.pow2 48 < Prims.pow2 12)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Spec.K256.PointOps.prime", "Prims.unit", "FStar.Math.Lemmas.distributivity_sub_right", "Prims.pow2", "Hacl.Spec.K256.Field52.normalize_weak5", "Hacl.Spec.K256.Field52.Definitions.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.op_Addition", "Hacl.Spec.K256.Field52.Lemmas2.plus_x_mul_pow2_256_minus_prime_lemma", "Hacl.Spec.K256.Field52.plus_x_mul_pow2_256_minus_prime", "Hacl.Spec.K256.Field52.Lemmas2.minus_x_mul_pow2_256_lemma", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256" ]
[]
false
false
true
false
false
let normalize_weak5_lemma m f =
let m0, m1, m2, m3, m4 = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0, m1, m2, m3, 1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0, m1, m2, m3, 1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1, 1, 1, 1, 2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.mk_checked_let
val mk_checked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ{typing g tm (T.E_Total, ty)}) : T.Tac (sigelt_for g)
val mk_checked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ{typing g tm (T.E_Total, ty)}) : T.Tac (sigelt_for g)
let mk_checked_let (g:R.env) (nm:string) (tm:R.term) (ty:R.typ{typing g tm (T.E_Total, ty)}) : T.Tac (sigelt_for g) = let fv = pack_fv (T.cur_module () @ [nm]) in let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm }) in let se = R.pack_sigelt (R.Sg_Let false [lb]) in let pf : sigelt_typing g se = ST_Let g fv ty tm () in ( true, se, None )
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 1839, "start_col": 0, "start_line": 1832 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_ let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_ let ln (t:term) = ln' t (-1) let ln_comp (c:comp) = ln'_comp c (-1) // // term_ctxt is used to define the equiv relation later, // basically putting two equiv terms in a hole gives equiv terms // // The abs, arrow, refine, and let cases don't seem right here, // since to prove their equiv, we need to extend gamma for their bodies // // If this is useful only for app, then may be we should remove it, // and add app rules to the equiv relation itself [@@ no_auto_projectors] noeq type term_ctxt = | Ctxt_hole : term_ctxt | Ctxt_app_head : term_ctxt -> argv -> term_ctxt | Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt // | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt // | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt // | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt // | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt // | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt // | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt // | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt // | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt // | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt // | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt // and bv_ctxt = // | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt // and binder_ctxt = // | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt // and comp_ctxt = // | Ctxt_total : term_ctxt -> comp_ctxt // | Ctxt_gtotal : term_ctxt -> comp_ctxt let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) = match e with | Ctxt_hole -> t | Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg) | Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) // | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body) // | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t)) // | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c) // | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t)) // | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi) // | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t)) // | Ctxt_let_sort b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body) // | Ctxt_let_def b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body) // | Ctxt_let_body b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t)) // | Ctxt_match_scrutinee sc ret brs -> // pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs) // and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) = // let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in // pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t} // and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) = // match c with // | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t)) // | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t)) noeq type constant_typing: vconst -> term -> Type0 = | CT_Unit: constant_typing C_Unit unit_ty | CT_True: constant_typing C_True bool_ty | CT_False: constant_typing C_False bool_ty [@@ no_auto_projectors] noeq type univ_eq : universe -> universe -> Type0 = | UN_Refl : u:universe -> univ_eq u u | UN_MaxCongL : u:universe -> u':universe -> v:universe -> univ_eq u u' -> univ_eq (u_max u v) (u_max u' v) | UN_MaxCongR : u:universe -> v:universe -> v':universe -> univ_eq v v' -> univ_eq (u_max u v) (u_max u v') | UN_MaxComm: u:universe -> v:universe -> univ_eq (u_max u v) (u_max v u) | UN_MaxLeq: u:universe -> v:universe -> univ_leq u v -> univ_eq (u_max u v) v and univ_leq : universe -> universe -> Type0 = | UNLEQ_Refl: u:universe -> univ_leq u u | UNLEQ_Succ: u:universe -> v:universe -> univ_leq u v -> univ_leq u (u_succ v) | UNLEQ_Max: u:universe -> v:universe -> univ_leq u (u_max u v) let mk_if (scrutinee then_ else_:R.term) : R.term = pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) // effect and type type comp_typ = T.tot_or_ghost & typ let close_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) [ ND x i ] let close_comp_typ (c:comp_typ) (x:var) = close_comp_typ' c x 0 let open_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) (open_with_var x i) let open_comp_typ (c:comp_typ) (x:var) = open_comp_typ' c x 0 let freevars_comp_typ (c:comp_typ) = freevars (snd c) let mk_comp (c:comp_typ) : R.comp = match fst c with | T.E_Total -> mk_total (snd c) | T.E_Ghost -> mk_ghost (snd c) let mk_arrow_ct ty qual (c:comp_typ) : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c)) type relation = | R_Eq | R_Sub let binding = var & term let bindings = list binding let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs let rec extend_env_l (g:env) (bs:bindings) : env = match bs with | [] -> g | (x,t)::bs -> extend_env (extend_env_l g bs) x t // // TODO: support for erasable attribute // let is_non_informative_name (l:name) : bool = l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] let is_non_informative_fv (f:fv) : bool = is_non_informative_name (inspect_fv f) let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) = match vs with | [] -> t | v::vs -> subst_term (__close_term_vs (i+1) vs t) [ND v i] let close_term_vs (vs : list var) (t : term) : term = __close_term_vs 0 vs t let close_term_bs (bs : list binding) (t : term) : term = close_term_vs (List.Tot.map fst bs) t let bindings_to_refl_bindings (bs : list binding) : list R.binding = L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs let refl_bindings_to_bindings (bs : list R.binding) : list binding = L.map (fun b -> b.uniq, b.sort) bs [@@ no_auto_projectors] noeq type non_informative : env -> term -> Type0 = | Non_informative_type: g:env -> u:universe -> non_informative g (pack_ln (Tv_Type u)) | Non_informative_fv: g:env -> x:fv{is_non_informative_fv x} -> non_informative g (pack_ln (Tv_FVar x)) | Non_informative_uinst: g:env -> x:fv{is_non_informative_fv x} -> us:list universe -> non_informative g (pack_ln (Tv_UInst x us)) | Non_informative_app: g:env -> t:term -> arg:argv -> non_informative g t -> non_informative g (pack_ln (Tv_App t arg)) | Non_informative_total_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g t1 -> non_informative g (mk_arrow_ct t0 q (T.E_Total, t1)) | Non_informative_ghost_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1)) | Non_informative_token: g:env -> t:typ -> squash (T.non_informative_token g t) -> non_informative g t val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0 val bindings_ok_pat_constant : g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c)) let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 = bindings_ok_for_pat g bs (fst br) let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) = zip2prop (bindings_ok_for_branch g) bss brs let binding_to_namedv (b:R.binding) : Tot namedv = pack_namedv { RD.uniq = b.uniq; RD.sort = seal b.sort; RD.ppname = b.ppname; } (* Elaborates the p pattern into a term, using the bs bindings for the pattern variables. The resulting term is properly scoped only on an environment which contains all of bs. See for instance the branch_typing judg. Returns an option, since this can fail if e.g. there are not enough bindings, and returns the list of unused binders as well, which should be empty if the list of binding was indeed ok. *) let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) = match p, bs with | Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs) | Pat_Cons fv univs subpats, bs -> let head = pack_ln (Tv_FVar fv) in fold_left_dec (Some (head, bs)) subpats (fun st pi -> let (p,i) = pi in match st with | None -> None | Some (head, bs) -> match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs')) | Pat_Var _ _, b::bs -> Some (pack_ln (Tv_Var (binding_to_namedv b)), bs) | Pat_Dot_Term (Some t), _ -> Some (t, bs) | Pat_Dot_Term None, _ -> None | _ -> None [@@ no_auto_projectors] noeq type typing : env -> term -> comp_typ -> Type0 = | T_Token : g:env -> e:term -> c:comp_typ -> squash (T.typing_token g e c) -> typing g e c | T_Var : g:env -> x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } -> typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x))) | T_FVar : g:env -> x:fv { Some? (lookup_fvar g x) } -> typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x)) | T_UInst : g:env -> x:fv -> us:list universe { Some? (lookup_fvar_uinst g x us) } -> typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us)) | T_Const: g:env -> v:vconst -> t:term -> constant_typing v t -> typing g (constant_as_term v) (T.E_Total, t) | T_Abs : g:env -> x:var { None? (lookup_bvar g x) } -> ty:term -> body:term { ~(x `Set.mem` freevars body) } -> body_c:comp_typ -> u:universe -> pp_name:pp_name_t -> q:aqualv -> ty_eff:T.tot_or_ghost -> typing g ty (ty_eff, tm_type u) -> typing (extend_env g x ty) (open_term body x) body_c -> typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body)) (T.E_Total, pack_ln (Tv_Arrow (mk_binder pp_name ty q) (mk_comp (close_comp_typ body_c x)))) | T_App : g:env -> e1:term -> e2:term -> x:binder -> t:term -> eff:T.tot_or_ghost -> typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) -> typing g e2 (eff, binder_sort x) -> typing g (pack_ln (Tv_App e1 (e2, binder_qual x))) (eff, open_with t e2) | T_Let: g:env -> x:var { None? (lookup_bvar g x) } -> e1:term -> t1:typ -> e2:term -> t2:typ -> eff:T.tot_or_ghost -> pp_name:pp_name_t -> typing g e1 (eff, t1) -> typing (extend_env g x t1) (open_term e2 x) (eff, t2) -> typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1) | T_Arrow: g:env -> x:var { None? (lookup_bvar g x) } -> t1:term -> t2:term { ~(x `Set.mem` freevars t2) } -> u1:universe -> u2:universe -> pp_name:pp_name_t -> q:aqualv -> eff:T.tot_or_ghost -> t1_eff:T.tot_or_ghost -> t2_eff:T.tot_or_ghost -> typing g t1 (t1_eff, tm_type u1) -> typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) -> typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2)))) (T.E_Total, tm_type (u_max u1 u2)) | T_Refine: g:env -> x:var { None? (lookup_bvar g x) } -> t:term -> e:term { ~(x `Set.mem` freevars e) } -> u1:universe -> u2:universe -> t_eff:T.tot_or_ghost -> e_eff:T.tot_or_ghost -> typing g t (t_eff, tm_type u1) -> typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) -> typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1) | T_PropIrrelevance: g:env -> e:term -> t:term -> e_eff:T.tot_or_ghost -> t_eff:T.tot_or_ghost -> typing g e (e_eff, t) -> typing g t (t_eff, tm_prop) -> typing g (`()) (T.E_Total, t) | T_Sub: g:env -> e:term -> c:comp_typ -> c':comp_typ -> typing g e c -> sub_comp g c c' -> typing g e c' | T_If: g:env -> scrutinee:term -> then_:term -> else_:term -> ty:term -> u_ty:universe -> hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } -> eff:T.tot_or_ghost -> ty_eff:T.tot_or_ghost -> typing g scrutinee (eff, bool_ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) -> typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp typing g (mk_if scrutinee then_ else_) (eff, ty) | T_Match: g:env -> sc_u : universe -> sc_ty : typ -> sc : term -> ty_eff:T.tot_or_ghost -> typing g sc_ty (ty_eff, tm_type sc_u) -> eff:T.tot_or_ghost -> typing g sc (eff, sc_ty) -> branches:list branch -> ty:comp_typ -> bnds:list (list R.binding) -> complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type typing g (pack_ln (Tv_Match sc None branches)) ty and related : env -> term -> relation -> term -> Type0 = | Rel_refl: g:env -> t:term -> rel:relation -> related g t rel t | Rel_sym: g:env -> t0:term -> t1:term -> related g t0 R_Eq t1 -> related g t1 R_Eq t0 | Rel_trans: g:env -> t0:term -> t1:term -> t2:term -> rel:relation -> related g t0 rel t1 -> related g t1 rel t2 -> related g t0 rel t2 | Rel_univ: g:env -> u:universe -> v:universe -> univ_eq u v -> related g (tm_type u) R_Eq (tm_type v) | Rel_beta: g:env -> t:typ -> q:aqualv -> e:term { ln' e 0 } -> arg:term { ln arg } -> related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q))) R_Eq (subst_term e [ DT 0 arg ]) | Rel_eq_token: g:env -> t0:term -> t1:term -> squash (T.equiv_token g t0 t1) -> related g t0 R_Eq t1 | Rel_subtyping_token: g:env -> t0:term -> t1:term -> squash (T.subtyping_token g t0 t1) -> related g t0 R_Sub t1 | Rel_equiv: g:env -> t0:term -> t1:term -> rel:relation -> related g t0 R_Eq t1 -> related g t0 rel t1 | Rel_arrow: g:env -> t1:term -> t2:term -> q:aqualv -> c1:comp_typ -> c2:comp_typ -> rel:relation -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2)) } -> related g t2 rel t1 -> related_comp (extend_env g x t2) (open_comp_typ c1 x) rel (open_comp_typ c2 x) -> related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2) | Rel_abs: g:env -> t1:term -> t2:term -> q:aqualv -> e1:term -> e2:term -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2)) } -> related g t1 R_Eq t2 -> related (extend_env g x t1) (subst_term e1 (open_with_var x 0)) R_Eq (subst_term e2 (open_with_var x 0)) -> related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2) | Rel_ctxt: g:env -> t0:term -> t1:term -> ctxt:term_ctxt -> related g t0 R_Eq t1 -> related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1) and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 = | Relc_typ: g:env -> t0:term -> t1:term -> eff:T.tot_or_ghost -> rel:relation -> related g t0 rel t1 -> related_comp g (eff, t0) rel (eff, t1) | Relc_total_ghost: g:env -> t:term -> related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t) | Relc_ghost_total: g:env -> t:term -> non_informative g t -> related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t) and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (brs:list branch) -> (bnds : list (list R.binding)) -> Type0 = (* This judgement only enforces that branch_typing holds for every element of brs and its respective bnds (which must have the same length). *) | BT_Nil : branches_typing g sc_u sc_ty sc rty [] [] | BT_S : br : branch -> bnds : list R.binding -> pf : branch_typing g sc_u sc_ty sc rty br bnds -> rest_br : list branch -> rest_bnds : list (list R.binding) -> rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds -> branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds) and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (br : branch) -> (bnds : list R.binding) -> Type0 = | BO : pat : pattern -> bnds : list R.binding{bindings_ok_for_pat g bnds pat} -> hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} -> body:term -> _ : squash (Some? (elaborate_pat pat bnds)) -> typing (extend_env (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds)))) ) body rty -> branch_typing g sc_u sc_ty sc rty (pat, close_term_bs (refl_bindings_to_bindings bnds) body) bnds and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 = | MC_Tok : env:_ -> sc:_ -> ty:_ -> pats:_ -> bnds:_ -> squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2 and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2 and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2 type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t) type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t) val subtyping_token_renaming (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1) : T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0)) (rename t0 x y) (rename t1 x y) val subtyping_token_weakening (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1) : T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1 let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe) (d:typing g t (T.E_Total, tm_type (u_max u u))) : typing g t (T.E_Total, tm_type u) = let ue : univ_eq (u_max u u) u = UN_MaxLeq u u (UNLEQ_Refl u) in let du : related g (tm_type (u_max u u)) R_Eq (tm_type u) = Rel_univ g (u_max u u) u ue in let du : related g (tm_type (u_max u u)) R_Sub (tm_type u) = Rel_equiv _ _ _ _ du in T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du) val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : Lemma (ensures ln e /\ ln (snd c)) val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u)) val binder_offset_pattern_invariant (p:pattern) (ss:subst) : Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss)) val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst) : Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss)) val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var) : Lemma (ensures subst_term (subst_term t [ ND x i ]) (open_with_var x i) == t) val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var) : Lemma (ensures subst_binder (subst_binder b [ ND x i ]) (open_with_var x i) == b) val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var) : Lemma (ensures subst_terms (subst_terms ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var) : Lemma (ensures subst_comp (subst_comp c [ ND x i ]) (open_with_var x i) == c) val open_close_inverse'_args (i:nat) (ts:list argv { ln'_args ts (i - 1) }) (x:var) : Lemma (ensures subst_args (subst_args ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_patterns (i:nat) (ps:list (pattern & bool) { ln'_patterns ps (i - 1) }) (x:var) : Lemma (ensures subst_patterns (subst_patterns ps [ ND x i ]) (open_with_var x i) == ps) val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var) : Lemma (ensures subst_pattern (subst_pattern p [ ND x i ]) (open_with_var x i) == p) val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var) : Lemma (ensures subst_branch (subst_branch br [ ND x i ]) (open_with_var x i) == br) val open_close_inverse'_branches (i:nat) (brs:list branch { ln'_branches brs (i - 1) }) (x:var) : Lemma (ensures subst_branches (subst_branches brs [ ND x i ]) (open_with_var x i) == brs) val open_close_inverse'_match_returns (i:nat) (m:match_returns_ascription { ln'_match_returns m (i - 1) }) (x:var) : Lemma (ensures subst_match_returns (subst_match_returns m [ ND x i ]) (open_with_var x i) == m) val open_close_inverse (e:R.term { ln e }) (x:var) : Lemma (open_term (close_term e x) x == e) val close_open_inverse' (i:nat) (t:term) (x:var { ~(x `Set.mem` freevars t) }) : Lemma (ensures subst_term (subst_term t (open_with_var x i)) [ ND x i ] == t) val close_open_inverse'_comp (i:nat) (c:comp) (x:var{ ~(x `Set.mem` freevars_comp c) }) : Lemma (ensures subst_comp (subst_comp c (open_with_var x i)) [ ND x i ] == c) val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) }) : Lemma (ensures subst_args (subst_args args (open_with_var x i)) [ ND x i] == args) val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) }) : Lemma (ensures subst_binder (subst_binder b (open_with_var x i)) [ ND x i ] == b) val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) }) : Lemma (ensures subst_terms (subst_terms ts (open_with_var x i)) [ ND x i ] == ts) val close_open_inverse'_branches (i:nat) (brs:list branch) (x:var{ ~(x `Set.mem` freevars_branches brs) }) : Lemma (ensures subst_branches (subst_branches brs (open_with_var x i)) [ ND x i ] == brs) val close_open_inverse'_branch (i:nat) (br:branch) (x:var{ ~(x `Set.mem` freevars_branch br) }) : Lemma (ensures subst_branch (subst_branch br (open_with_var x i)) [ ND x i ] == br) val close_open_inverse'_pattern (i:nat) (p:pattern) (x:var{ ~(x `Set.mem` freevars_pattern p) }) : Lemma (ensures subst_pattern (subst_pattern p (open_with_var x i)) [ ND x i ] == p) val close_open_inverse'_patterns (i:nat) (ps:list (pattern & bool)) (x:var {~ (x `Set.mem` freevars_patterns ps) }) : Lemma (ensures subst_patterns (subst_patterns ps (open_with_var x i)) [ ND x i ] == ps) val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription) (x:var{ ~(x `Set.mem` freevars_match_returns m) }) : Lemma (ensures subst_match_returns (subst_match_returns m (open_with_var x i)) [ ND x i ] == m) val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) }) : Lemma (close_term (open_term e x) x == e) // // fst has corresponding lemmas for other syntax classes // val close_with_not_free_var (t:R.term) (x:var) (i:nat) : Lemma (requires ~ (Set.mem x (freevars t))) (ensures subst_term t [ ND x i ] == t) // this also requires x to be not in freevars e1 `Set.union` freevars e2 val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var { None? (lookup_bvar g x) }) (eq:equiv (extend_env g x ty) (subst_term e1 (open_with_var x 0)) (subst_term e2 (open_with_var x 0))) : equiv g (mk_arrow ty q e1) (mk_arrow ty q e2) // the proof for this requires e1 and e2 to be ln val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var{None? (lookup_bvar g x)}) (eq:equiv (extend_env g x ty) e1 e2) : equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ])) (mk_abs ty q (subst_term e2 [ ND x 0 ])) val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat) : Lemma (requires ln' e i /\ i < j) (ensures subst_term e [ DT j t ] == e) [SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])] // // Type of the top-level tactic that would splice-in the definitions // let fstar_env_fvs (g:R.env) = lookup_fvar g unit_fv == Some (tm_type u_zero) /\ lookup_fvar g bool_fv == Some (tm_type u_zero) /\ lookup_fvar g b2t_fv == Some b2t_ty type fstar_env = g:R.env{fstar_env_fvs g} type fstar_top_env = g:fstar_env { forall x. None? (lookup_bvar g x ) } // // This doesn't allow for universe polymorphic definitions // // May be we can change it to: // // g:fstar_top_env -> T.tac ((us, e, t):(univ_names & term & typ){typing (push g us) e t}) // noeq type sigelt_typing : env -> sigelt -> Type0 = | ST_Let : g : env -> fv : R.fv -> ty : R.typ -> tm : R.term -> squash (typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm })])) | ST_Let_Opaque : g : env -> fv : R.fv -> ty : R.typ -> (* no tm: only a proof of existence *) squash (exists (tm:R.term). typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) })])) (** * The type of the top-level tactic that would splice-in the definitions. * It returns a list of well typed definitions, via the judgment above. * * Each definition can have a 'blob' attached with a given name. * The blob can be used later, e.g., during extraction, and passed back to the * extension to perform additional processing. *) (* * It returns either: * - Some tm, blob, typ, with a proof that `typing g tm typ` * - None, blob, typ), with a proof that `exists tm. typing g tm typ` * The blob itself is optional and can store some additional metadata that * constructed by the tactic. If present, it will be stored in the * sigmeta_extension_data field of the enclosing sigelt. * *) let blob = string & R.term (* If checked is true, this sigelt is properly typed for the environment. If not, we don't know and let F* re-typecheck the sigelt. *) let sigelt_for (g:env) = tup:(bool & sigelt & option blob) { let (checked, se, _) = tup in checked ==> sigelt_typing g se } let dsl_tac_result_t (g:env) = list (sigelt_for g) type dsl_tac_t = g:fstar_top_env -> T.Tac (dsl_tac_result_t g) val if_complete_match (g:env) (t:term) : T.match_complete_token g t bool_ty [ Pat_Constant C_True; Pat_Constant C_False; ] [[]; []] // Derived rule for if val mkif (g:fstar_env) (scrutinee:term) (then_:term) (else_:term) (ty:term) (u_ty:universe) (hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) }) (eff:T.tot_or_ghost) (ty_eff:T.tot_or_ghost) (ts : typing g scrutinee (eff, bool_ty)) (tt : typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty)) (te : typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty)) (tr : typing g ty (ty_eff, tm_type u_ty)) : typing g (mk_if scrutinee then_ else_) (eff, ty)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: FStar.Stubs.Reflection.Types.env -> nm: Prims.string -> tm: FStar.Stubs.Reflection.Types.term -> ty: FStar.Stubs.Reflection.Types.typ {FStar.Reflection.Typing.typing g tm (FStar.Stubs.TypeChecker.Core.E_Total, ty)} -> FStar.Tactics.Effect.Tac (FStar.Reflection.Typing.sigelt_for g)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.env", "Prims.string", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.typ", "FStar.Reflection.Typing.typing", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.TypeChecker.Core.tot_or_ghost", "FStar.Stubs.TypeChecker.Core.E_Total", "FStar.Pervasives.Native.Mktuple3", "Prims.bool", "FStar.Stubs.Reflection.Types.sigelt", "FStar.Pervasives.Native.option", "FStar.Reflection.Typing.blob", "FStar.Pervasives.Native.None", "FStar.Reflection.Typing.sigelt_typing", "FStar.Reflection.Typing.ST_Let", "FStar.Stubs.Reflection.V2.Builtins.pack_sigelt", "FStar.Stubs.Reflection.V2.Data.Sg_Let", "Prims.Cons", "FStar.Stubs.Reflection.Types.letbinding", "Prims.Nil", "FStar.Stubs.Reflection.V2.Builtins.pack_lb", "FStar.Stubs.Reflection.V2.Data.Mklb_view", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Reflection.Typing.sigelt_for", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Stubs.Reflection.Types.name", "FStar.List.Tot.Base.op_At", "Prims.list", "FStar.Tactics.V2.Derived.cur_module" ]
[]
false
true
false
false
false
let mk_checked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ{typing g tm (T.E_Total, ty)}) : T.Tac (sigelt_for g) =
let fv = pack_fv (T.cur_module () @ [nm]) in let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm }) in let se = R.pack_sigelt (R.Sg_Let false [lb]) in let pf:sigelt_typing g se = ST_Let g fv ty tm () in (true, se, None)
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.plus_x_mul_pow2_256_minus_prime_lemma
val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime))
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 134, "start_col": 0, "start_line": 115 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> x: Lib.IntTypes.uint64 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 m4 = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ _ = _ in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 f m /\ Lib.IntTypes.v x < Prims.pow2 16 ) <: Type0) <: Type0)) (ensures (let r = Hacl.Spec.K256.Field52.plus_x_mul_pow2_256_minus_prime x f in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ t4 = _ in Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f + Lib.IntTypes.v x * (Prims.pow2 256 - Spec.K256.PointOps.prime) /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 2) /\ Lib.IntTypes.v r4 < Lib.IntTypes.v t4 + Prims.pow2 12 /\ (Lib.IntTypes.v r4 >= Prims.pow2 48 ==> Lib.IntTypes.v r4 % Prims.pow2 48 < Prims.pow2 12)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Lib.IntTypes.uint64", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.op_Subtraction", "Prims.pow2", "Spec.K256.PointOps.prime", "Prims.unit", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_pow2_256_minus_prime", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.Lemmas2.carry_round_after_last_carry_mod_prime5_lemma", "Hacl.Spec.K256.Field52.carry_round5", "Prims.b2t", "Hacl.Spec.K256.Field52.Definitions.felem_fits1", "Prims.op_Equality", "FStar.Math.Lemmas.small_mod", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Hacl.Spec.K256.Field52.Definitions.max52", "FStar.Math.Lemmas.lemma_mult_le_right", "FStar.Math.Lemmas.lemma_mult_lt_right", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.u64" ]
[]
false
false
true
false
false
let plus_x_mul_pow2_256_minus_prime_lemma m x f =
let t0, t1, t2, t3, t4 = f in let m0, m1, m2, m3, m4 = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0', t1, t2, t3, t4) in carry_round_after_last_carry_mod_prime5_lemma (m0 + 1, m1, m2, m3, m4) (t0', t1, t2, t3, t4); assert (as_nat5 r == as_nat5 (t0', t1, t2, t3, t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime))
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.carry_round_after_last_carry_mod_prime5_lemma
val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 99, "start_col": 0, "start_line": 63 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 m4 = _ in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 f (m0, m1, m2, m3, 1)) <: Type0)) (ensures (let r = Hacl.Spec.K256.Field52.carry_round5 f in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ t4 = _ in Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 2) /\ Lib.IntTypes.v r4 < Lib.IntTypes.v t4 + Prims.pow2 12 /\ (Lib.IntTypes.v r4 >= Prims.pow2 48 ==> Lib.IntTypes.v r4 % Prims.pow2 48 < Prims.pow2 12)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.unit", "FStar.Pervasives.Native.tuple5", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.carry_round5", "Hacl.Spec.K256.MathLemmas.lemma_simplify_carry_round", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Field52.Definitions.Lemmas.carry_last_small_mod_lemma", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "Prims.op_Division", "Prims.pow2", "Prims.op_Modulus", "Hacl.Spec.K256.Field52.Definitions.felem_fits1", "Hacl.Spec.K256.Field52.Definitions.felem_fits_last1", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_carry_last52", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "Hacl.Spec.K256.Field52.Definitions.mask52", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_carry52" ]
[]
false
false
true
false
false
let carry_round_after_last_carry_mod_prime5_lemma m f =
let m0, m1, m2, m3, m4 = m in let t0, t1, t2, t3, t4 = f in let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0', t1'', t2'', t3'', t4') == r); assert (as_nat5 r == as_nat5 f)
false
FStar.Reflection.Typing.fsti
FStar.Reflection.Typing.mk_unchecked_let
val mk_unchecked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ) : T.Tac (sigelt_for g)
val mk_unchecked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ) : T.Tac (sigelt_for g)
let mk_unchecked_let (g:R.env) (nm:string) (tm:R.term) (ty:R.typ) : T.Tac (sigelt_for g) = let fv = pack_fv (T.cur_module () @ [nm]) in let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm }) in let se = R.pack_sigelt (R.Sg_Let false [lb]) in ( false, se, None )
{ "file_name": "ulib/experimental/FStar.Reflection.Typing.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 1845, "start_col": 0, "start_line": 1841 }
(* Copyright 2008-2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Reflection.Typing (** This module defines a typing judgment for (parts of) the total and ghost fragment of F*. We are using it in the meta DSL framework as an official specification for the F* type system. We expect it to grow to cover more of the F* language. IT IS HIGHLY EXPERIMENTAL AND NOT YET READY TO USE. *) open FStar.List.Tot open FStar.Reflection.V2 module L = FStar.List.Tot module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RD = FStar.Stubs.Reflection.V2.Data (* MOVE to some helper module *) let rec fold_left_dec #a #b (acc : a) (l : list b) (f : a -> (x:b{x << l}) -> a) : Tot a (decreases l) = match l with | [] -> acc | x::xs -> fold_left_dec (f acc x) xs f let rec map_dec #a #b (l : list a) (f : (x:a{x << l}) -> b) : Tot (list b) (decreases l) = match l with | [] -> [] | x::xs -> f x :: map_dec xs f let rec zip2prop #a #b (f : a -> b -> Type0) (xs : list a) (ys : list b) : Type0 = match xs, ys with | [], [] -> True | x::xx, y::yy -> f x y /\ zip2prop f xx yy | _ -> False (* / MOVE *) val inspect_pack (t:R.term_view) : Lemma (ensures R.(inspect_ln (pack_ln t) == t)) [SMTPat R.(inspect_ln (pack_ln t))] val pack_inspect (t:R.term) : Lemma (requires ~(Tv_Unsupp? (inspect_ln t))) (ensures R.(pack_ln (inspect_ln t) == t)) [SMTPat R.(pack_ln (inspect_ln t))] val inspect_pack_namedv (t:R.namedv_view) : Lemma (ensures R.(inspect_namedv (pack_namedv t) == t)) [SMTPat R.(inspect_namedv (pack_namedv t))] val pack_inspect_namedv (t:R.namedv) : Lemma (ensures R.(pack_namedv (inspect_namedv t) == t)) [SMTPat R.(pack_namedv (inspect_namedv t))] val inspect_pack_bv (t:R.bv_view) : Lemma (ensures R.(inspect_bv (pack_bv t) == t)) [SMTPat R.(inspect_bv (pack_bv t))] val pack_inspect_bv (t:R.bv) : Lemma (ensures R.(pack_bv (inspect_bv t) == t)) [SMTPat R.(pack_bv (inspect_bv t))] val inspect_pack_binder (bview:R.binder_view) : Lemma (ensures R.(R.inspect_binder (R.pack_binder bview) == bview)) [SMTPat R.(inspect_binder (pack_binder bview))] val pack_inspect_binder (t:R.binder) : Lemma (ensures (R.pack_binder (R.inspect_binder t) == t)) [SMTPat (R.pack_binder (R.inspect_binder t))] val inspect_pack_comp (t:R.comp_view) : Lemma (ensures (R.inspect_comp (R.pack_comp t) == t)) [SMTPat (R.inspect_comp (R.pack_comp t))] val pack_inspect_comp (t:R.comp) : Lemma (ensures (R.pack_comp (R.inspect_comp t) == t)) [SMTPat (R.pack_comp (R.inspect_comp t))] val inspect_pack_fv (nm:R.name) : Lemma (ensures R.inspect_fv (R.pack_fv nm) == nm) [SMTPat (R.inspect_fv (R.pack_fv nm))] val pack_inspect_fv (fv:R.fv) : Lemma (ensures R.pack_fv (R.inspect_fv fv) == fv) [SMTPat (R.pack_fv (R.inspect_fv fv))] val inspect_pack_universe (u:R.universe_view) : Lemma (ensures R.inspect_universe (R.pack_universe u) == u) [SMTPat (R.inspect_universe (R.pack_universe u))] val pack_inspect_universe (u:R.universe) : Lemma (requires ~(Uv_Unk? (inspect_universe u))) (ensures R.pack_universe (R.inspect_universe u) == u) [SMTPat (R.pack_universe (R.inspect_universe u))] val lookup_bvar (e:env) (x:int) : option term val lookup_fvar_uinst (e:R.env) (x:R.fv) (us:list R.universe) : option R.term let lookup_fvar (e:env) (x:fv) : option term = lookup_fvar_uinst e x [] let pp_name_t = FStar.Sealed.Inhabited.sealed "x" let pp_name_default : pp_name_t = FStar.Sealed.Inhabited.seal "x" let seal_pp_name x : pp_name_t = FStar.Sealed.Inhabited.seal x let tun = pack_ln Tv_Unknown let sort_t = FStar.Sealed.Inhabited.sealed tun let sort_default : sort_t = FStar.Sealed.Inhabited.seal tun let seal_sort x : sort_t = FStar.Sealed.Inhabited.seal x let mk_binder (pp_name:pp_name_t) (ty:term) (q:aqualv) : binder = pack_binder { ppname = pp_name; qual = q; attrs = []; sort = ty} let mk_simple_binder (pp_name:pp_name_t) (ty:term) : simple_binder = pack_binder { ppname = pp_name; qual = Q_Explicit; attrs = []; sort = ty} let extend_env (e:env) (x:var) (ty:term) : env = R.push_binding e ({ ppname = seal_pp_name "x"; uniq = x; sort = ty; }) val lookup_bvar_extend_env (g:env) (x y:var) (ty:term) : Lemma (ensures ( if x = y then lookup_bvar (extend_env g x ty) y == Some ty else lookup_bvar (extend_env g x ty) y == lookup_bvar g y)) [SMTPat (lookup_bvar (extend_env g x ty) y)] val lookup_fvar_extend_env (g:env) (x:fv) (us:universes) (y:var) (ty:term) : Lemma (ensures lookup_fvar_uinst (extend_env g y ty) x us == lookup_fvar_uinst g x us) [SMTPat (lookup_fvar_uinst (extend_env g y ty) x us)] let bv_index (x:bv) : var = (inspect_bv x).index let namedv_uniq (x:namedv) : var = (inspect_namedv x).uniq let binder_sort (b:binder) = (inspect_binder b).sort let binder_qual (b:binder) = let { qual = q } = inspect_binder b in q noeq type subst_elt = | DT : nat -> term -> subst_elt | NT : var -> term -> subst_elt | ND : var -> nat -> subst_elt let shift_subst_elt (n:nat) = function | DT i t -> DT (i + n) t | NT x t -> NT x t | ND x i -> ND x (i + n) let subst = list subst_elt let shift_subst_n (n:nat) = L.map (shift_subst_elt n) let shift_subst = shift_subst_n 1 let maybe_uniq_of_term (x:term) = match inspect_ln x with | Tv_Var namedv -> Some (namedv_uniq namedv) | _ -> None let rec find_matching_subst_elt_bv (s:subst) (bv:bv) : option subst_elt = match s with | [] -> None | (DT j t)::ss -> if j = bv_index bv then Some (DT j t) else find_matching_subst_elt_bv ss bv | _::ss -> find_matching_subst_elt_bv ss bv let subst_db (bv:bv) (s:subst) : term = match find_matching_subst_elt_bv s bv with | Some (DT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> //if we're substituting a name j for a name k, retain the pp_name of j let v : namedv = pack_namedv { sort = (inspect_bv bv).sort; ppname = (inspect_bv bv).ppname; uniq = k; } in pack_ln (Tv_Var v)) | _ -> pack_ln (Tv_BVar bv) let rec find_matching_subst_elt_var (s:subst) (v:namedv) : option subst_elt = match s with | [] -> None | (NT y _)::rest | (ND y _)::rest -> if y = namedv_uniq v then Some (L.hd s) else find_matching_subst_elt_var rest v | _::rest -> find_matching_subst_elt_var rest v let subst_var (v:namedv) (s:subst) : term = match find_matching_subst_elt_var s v with | Some (NT _ t) -> (match maybe_uniq_of_term t with | None -> t | Some k -> pack_ln (Tv_Var (pack_namedv { inspect_namedv v with uniq = k }))) | Some (ND _ i) -> let bv = pack_bv { sort = (inspect_namedv v).sort; ppname = (inspect_namedv v).ppname; index = i; } in pack_ln (Tv_BVar bv) | _ -> pack_ln (Tv_Var v) let make_bv (n:nat) : bv_view = { ppname = pp_name_default; index = n; sort = sort_default; } let make_bv_with_name (s:pp_name_t) (n:nat) : bv_view = { ppname = s; index = n; sort = sort_default; } let var_as_bv (v:nat) = pack_bv (make_bv v) let make_namedv (n:nat) : namedv_view = { ppname = pp_name_default; uniq = n; sort = sort_default; } let make_namedv_with_name (s:pp_name_t) (n:nat) : namedv_view = { ppname = s; uniq = n; sort = sort_default; } let var_as_namedv (v:nat) : namedv = pack_namedv { uniq = v; sort = sort_default; ppname = pp_name_default; } let var_as_term (v:var) = pack_ln (Tv_Var (var_as_namedv v)) let binder_of_t_q t q = mk_binder pp_name_default t q let mk_abs ty qual t : R.term = R.pack_ln (R.Tv_Abs (binder_of_t_q ty qual) t) let mk_total t = pack_comp (C_Total t) let mk_ghost t = pack_comp (C_GTotal t) let mk_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_total t)) let mk_ghost_arrow ty qual t : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_ghost t)) let bound_var i : R.term = R.pack_ln (R.Tv_BVar (R.pack_bv (make_bv i))) let mk_let ppname (e1 t1 e2:R.term) = R.pack_ln (R.Tv_Let false [] (mk_simple_binder ppname t1) e1 e2) let open_with_var_elt (x:var) (i:nat) : subst_elt = DT i (pack_ln (Tv_Var (var_as_namedv x))) let open_with_var (x:var) (i:nat) : subst = [open_with_var_elt x i] val subst_ctx_uvar_and_subst (c:ctx_uvar_and_subst) (ss:subst) : ctx_uvar_and_subst let rec binder_offset_patterns (ps:list (pattern & bool)) : nat = match ps with | [] -> 0 | (p, b)::ps -> let n = binder_offset_pattern p in let m = binder_offset_patterns ps in n + m and binder_offset_pattern (p:pattern) : nat = match p with | Pat_Constant _ | Pat_Dot_Term _ -> 0 | Pat_Var _ _ -> 1 | Pat_Cons head univs subpats -> binder_offset_patterns subpats let rec subst_term (t:term) (ss:subst) : Tot term (decreases t) = match inspect_ln t with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unsupp | Tv_Unknown -> t | Tv_Var x -> subst_var x ss | Tv_BVar j -> subst_db j ss | Tv_App hd argv -> pack_ln (Tv_App (subst_term hd ss) (subst_term (fst argv) ss, snd argv)) | Tv_Abs b body -> let b' = subst_binder b ss in pack_ln (Tv_Abs b' (subst_term body (shift_subst ss))) | Tv_Arrow b c -> let b' = subst_binder b ss in pack_ln (Tv_Arrow b' (subst_comp c (shift_subst ss))) | Tv_Refine b f -> let b = subst_binder b ss in pack_ln (Tv_Refine b (subst_term f (shift_subst ss))) | Tv_Uvar j c -> pack_ln (Tv_Uvar j (subst_ctx_uvar_and_subst c ss)) | Tv_Let recf attrs b def body -> let b = subst_binder b ss in pack_ln (Tv_Let recf (subst_terms attrs ss) b (if recf then subst_term def (shift_subst ss) else subst_term def ss) (subst_term body (shift_subst ss))) | Tv_Match scr ret brs -> pack_ln (Tv_Match (subst_term scr ss) (match ret with | None -> None | Some m -> Some (subst_match_returns m ss)) (subst_branches brs ss)) | Tv_AscribedT e t tac b -> pack_ln (Tv_AscribedT (subst_term e ss) (subst_term t ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) | Tv_AscribedC e c tac b -> pack_ln (Tv_AscribedC (subst_term e ss) (subst_comp c ss) (match tac with | None -> None | Some tac -> Some (subst_term tac ss)) b) and subst_binder (b:binder) (ss:subst) : Tot (b':binder{binder_is_simple b ==> binder_is_simple b'}) (decreases b) = let bndr = inspect_binder b in pack_binder { ppname = bndr.ppname; qual = bndr.qual; attrs = subst_terms bndr.attrs ss; sort = subst_term bndr.sort ss } and subst_comp (c:comp) (ss:subst) : Tot comp (decreases c) = match inspect_comp c with | C_Total t -> pack_comp (C_Total (subst_term t ss)) | C_GTotal t -> pack_comp (C_GTotal (subst_term t ss)) | C_Lemma pre post pats -> pack_comp (C_Lemma (subst_term pre ss) (subst_term post ss) (subst_term pats ss)) | C_Eff us eff_name res args decrs -> pack_comp (C_Eff us eff_name (subst_term res ss) (subst_args args ss) (subst_terms decrs ss)) and subst_terms (ts:list term) (ss:subst) : Tot (ts':list term{Nil? ts ==> Nil? ts'}) // property useful for subst_binder (decreases ts) = match ts with | [] -> [] | t::ts -> subst_term t ss :: subst_terms ts ss and subst_args (ts:list argv) (ss:subst) : Tot (list argv) (decreases ts) = match ts with | [] -> [] | (t,q)::ts -> (subst_term t ss,q) :: subst_args ts ss and subst_patterns (ps:list (pattern & bool)) (ss:subst) : Tot (list (pattern & bool)) (decreases ps) = match ps with | [] -> ps | (p, b)::ps -> let n = binder_offset_pattern p in let p = subst_pattern p ss in let ps = subst_patterns ps (shift_subst_n n ss) in (p,b)::ps and subst_pattern (p:pattern) (ss:subst) : Tot pattern (decreases p) = match p with | Pat_Constant _ -> p | Pat_Cons fv us pats -> let pats = subst_patterns pats ss in Pat_Cons fv us pats | Pat_Var bv s -> Pat_Var bv s | Pat_Dot_Term topt -> Pat_Dot_Term (match topt with | None -> None | Some t -> Some (subst_term t ss)) and subst_branch (br:branch) (ss:subst) : Tot branch (decreases br) = let p, t = br in let p = subst_pattern p ss in let j = binder_offset_pattern p in let t = subst_term t (shift_subst_n j ss) in p, t and subst_branches (brs:list branch) (ss:subst) : Tot (list branch) (decreases brs) = match brs with | [] -> [] | br::brs -> subst_branch br ss :: subst_branches brs ss and subst_match_returns (m:match_returns_ascription) (ss:subst) : Tot match_returns_ascription (decreases m) = let b, (ret, as_, eq) = m in let b = subst_binder b ss in let ret = match ret with | Inl t -> Inl (subst_term t (shift_subst ss)) | Inr c -> Inr (subst_comp c (shift_subst ss)) in let as_ = match as_ with | None -> None | Some t -> Some (subst_term t (shift_subst ss)) in b, (ret, as_, eq) val open_with (t:term) (v:term) : term val open_with_spec (t v:term) : Lemma (open_with t v == subst_term t [ DT 0 v ]) val open_term (t:term) (v:var) : term val open_term_spec (t:term) (v:var) : Lemma (open_term t v == subst_term t (open_with_var v 0)) val close_term (t:term) (v:var) : term val close_term_spec (t:term) (v:var) : Lemma (close_term t v == subst_term t [ ND v 0 ]) val rename (t:term) (x y:var) : term val rename_spec (t:term) (x y:var) : Lemma (rename t x y == subst_term t [ NT x (var_as_term y)]) val bv_index_of_make_bv (n:nat) : Lemma (ensures bv_index (pack_bv (make_bv n)) == n) [SMTPat (bv_index (pack_bv (make_bv n)))] val namedv_uniq_of_make_namedv (n:nat) : Lemma (ensures namedv_uniq (pack_namedv (make_namedv n)) == n) [SMTPat (namedv_uniq (pack_namedv (make_namedv n)))] let constant_as_term (v:vconst) = pack_ln (Tv_Const v) let unit_exp = constant_as_term C_Unit let unit_fv = pack_fv unit_lid let unit_ty = pack_ln (Tv_FVar unit_fv) let bool_fv = pack_fv bool_lid let bool_ty = pack_ln (Tv_FVar bool_fv) let u_zero = pack_universe Uv_Zero let u_max u1 u2 = pack_universe (Uv_Max [u1; u2]) let u_succ u = pack_universe (Uv_Succ u) let tm_type u = pack_ln (Tv_Type u) let tm_prop = let prop_fv = R.pack_fv R.prop_qn in R.pack_ln (Tv_FVar prop_fv) let eqtype_lid : R.name = ["Prims"; "eqtype"] let true_bool = pack_ln (Tv_Const C_True) let false_bool = pack_ln (Tv_Const C_False) let eq2 (u:universe) (t v0 v1:term) : term = let eq2 = pack_fv eq2_qn in let eq2 = pack_ln (Tv_UInst eq2 [u]) in let h = pack_ln (Tv_App eq2 (t, Q_Implicit)) in let h1 = pack_ln (Tv_App h (v0, Q_Explicit)) in let h2 = pack_ln (Tv_App h1 (v1, Q_Explicit)) in h2 let b2t_lid : R.name = ["Prims"; "b2t"] let b2t_fv : R.fv = R.pack_fv b2t_lid let b2t_ty : R.term = R.pack_ln (R.Tv_Arrow (mk_binder (seal "x") bool_ty Q_Explicit) (mk_total (tm_type u_zero))) //////////////////////////////////////////////////////////////////////////////// // freevars //////////////////////////////////////////////////////////////////////////////// let rec freevars (e:term) : FStar.Set.set var = match inspect_ln e with | Tv_Uvar _ _ -> Set.complement Set.empty | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_BVar _ -> Set.empty | Tv_Var x -> Set.singleton (namedv_uniq x) | Tv_App e1 (e2, _) -> Set.union (freevars e1) (freevars e2) | Tv_Abs b body -> Set.union (freevars_binder b) (freevars body) | Tv_Arrow b c -> Set.union (freevars_binder b) (freevars_comp c) | Tv_Refine b f -> freevars (binder_sort b) `Set.union` freevars f | Tv_Let recf attrs b def body -> freevars_terms attrs `Set.union` freevars (binder_sort b) `Set.union` freevars def `Set.union` freevars body | Tv_Match scr ret brs -> freevars scr `Set.union` freevars_opt ret freevars_match_returns `Set.union` freevars_branches brs | Tv_AscribedT e t tac b -> freevars e `Set.union` freevars t `Set.union` freevars_opt tac freevars | Tv_AscribedC e c tac b -> freevars e `Set.union` freevars_comp c `Set.union` freevars_opt tac freevars and freevars_opt (#a:Type0) (o:option a) (f: (x:a { x << o } -> FStar.Set.set var)) : FStar.Set.set var = match o with | None -> Set.empty | Some x -> f x and freevars_comp (c:comp) : FStar.Set.set var = match inspect_comp c with | C_Total t | C_GTotal t -> freevars t | C_Lemma pre post pats -> freevars pre `Set.union` freevars post `Set.union` freevars pats | C_Eff us eff_name res args decrs -> freevars res `Set.union` freevars_args args `Set.union` freevars_terms decrs and freevars_args (ts:list argv) : FStar.Set.set var = match ts with | [] -> Set.empty | (t,q)::ts -> freevars t `Set.union` freevars_args ts and freevars_terms (ts:list term) : FStar.Set.set var = match ts with | [] -> Set.empty | t::ts -> freevars t `Set.union` freevars_terms ts and freevars_binder (b:binder) : Tot (Set.set var) (decreases b) = let bndr = inspect_binder b in freevars bndr.sort `Set.union` freevars_terms bndr.attrs and freevars_pattern (p:pattern) : Tot (Set.set var) (decreases p) = match p with | Pat_Constant _ -> Set.empty | Pat_Cons head univs subpats -> freevars_patterns subpats | Pat_Var bv s -> Set.empty | Pat_Dot_Term topt -> freevars_opt topt freevars and freevars_patterns (ps:list (pattern & bool)) : Tot (Set.set var) (decreases ps) = match ps with | [] -> Set.empty | (p, b)::ps -> freevars_pattern p `Set.union` freevars_patterns ps and freevars_branch (br:branch) : Tot (Set.set var) (decreases br) = let p, t = br in freevars_pattern p `Set.union` freevars t and freevars_branches (brs:list branch) : Tot (Set.set var) (decreases brs) = match brs with | [] -> Set.empty | hd::tl -> freevars_branch hd `Set.union` freevars_branches tl and freevars_match_returns (m:match_returns_ascription) : Tot (Set.set var) (decreases m) = let b, (ret, as_, eq) = m in let b = freevars_binder b in let ret = match ret with | Inl t -> freevars t | Inr c -> freevars_comp c in let as_ = freevars_opt as_ freevars in b `Set.union` ret `Set.union` as_ let rec ln' (e:term) (n:int) : Tot bool (decreases e) = match inspect_ln e with | Tv_UInst _ _ | Tv_FVar _ | Tv_Type _ | Tv_Const _ | Tv_Unknown | Tv_Unsupp | Tv_Var _ -> true | Tv_BVar m -> bv_index m <= n | Tv_App e1 (e2, _) -> ln' e1 n && ln' e2 n | Tv_Abs b body -> ln'_binder b n && ln' body (n + 1) | Tv_Arrow b c -> ln'_binder b n && ln'_comp c (n + 1) | Tv_Refine b f -> ln'_binder b n && ln' f (n + 1) | Tv_Uvar _ _ -> false | Tv_Let recf attrs b def body -> ln'_terms attrs n && ln'_binder b n && (if recf then ln' def (n + 1) else ln' def n) && ln' body (n + 1) | Tv_Match scr ret brs -> ln' scr n && (match ret with | None -> true | Some m -> ln'_match_returns m n) && ln'_branches brs n | Tv_AscribedT e t tac b -> ln' e n && ln' t n && (match tac with | None -> true | Some tac -> ln' tac n) | Tv_AscribedC e c tac b -> ln' e n && ln'_comp c n && (match tac with | None -> true | Some tac -> ln' tac n) and ln'_comp (c:comp) (i:int) : Tot bool (decreases c) = match inspect_comp c with | C_Total t | C_GTotal t -> ln' t i | C_Lemma pre post pats -> ln' pre i && ln' post i && ln' pats i | C_Eff us eff_name res args decrs -> ln' res i && ln'_args args i && ln'_terms decrs i and ln'_args (ts:list argv) (i:int) : Tot bool (decreases ts) = match ts with | [] -> true | (t,q)::ts -> ln' t i && ln'_args ts i and ln'_binder (b:binder) (n:int) : Tot bool (decreases b) = let bndr = inspect_binder b in ln' bndr.sort n && ln'_terms bndr.attrs n and ln'_terms (ts:list term) (n:int) : Tot bool (decreases ts) = match ts with | [] -> true | t::ts -> ln' t n && ln'_terms ts n and ln'_patterns (ps:list (pattern & bool)) (i:int) : Tot bool (decreases ps) = match ps with | [] -> true | (p, b)::ps -> let b0 = ln'_pattern p i in let n = binder_offset_pattern p in let b1 = ln'_patterns ps (i + n) in b0 && b1 and ln'_pattern (p:pattern) (i:int) : Tot bool (decreases p) = match p with | Pat_Constant _ -> true | Pat_Cons head univs subpats -> ln'_patterns subpats i | Pat_Var bv s -> true | Pat_Dot_Term topt -> (match topt with | None -> true | Some t -> ln' t i) and ln'_branch (br:branch) (i:int) : Tot bool (decreases br) = let p, t = br in let b = ln'_pattern p i in let j = binder_offset_pattern p in let b' = ln' t (i + j) in b&&b' and ln'_branches (brs:list branch) (i:int) : Tot bool (decreases brs) = match brs with | [] -> true | br::brs -> ln'_branch br i && ln'_branches brs i and ln'_match_returns (m:match_returns_ascription) (i:int) : Tot bool (decreases m) = let b, (ret, as_, eq) = m in let b = ln'_binder b i in let ret = match ret with | Inl t -> ln' t (i + 1) | Inr c -> ln'_comp c (i + 1) in let as_ = match as_ with | None -> true | Some t -> ln' t (i + 1) in b && ret && as_ let ln (t:term) = ln' t (-1) let ln_comp (c:comp) = ln'_comp c (-1) // // term_ctxt is used to define the equiv relation later, // basically putting two equiv terms in a hole gives equiv terms // // The abs, arrow, refine, and let cases don't seem right here, // since to prove their equiv, we need to extend gamma for their bodies // // If this is useful only for app, then may be we should remove it, // and add app rules to the equiv relation itself [@@ no_auto_projectors] noeq type term_ctxt = | Ctxt_hole : term_ctxt | Ctxt_app_head : term_ctxt -> argv -> term_ctxt | Ctxt_app_arg : term -> aqualv -> term_ctxt -> term_ctxt // | Ctxt_abs_binder : binder_ctxt -> term -> term_ctxt // | Ctxt_abs_body : binder -> term_ctxt -> term_ctxt // | Ctxt_arrow_binder : binder_ctxt -> comp -> term_ctxt // | Ctxt_arrow_comp : binder -> comp_ctxt -> term_ctxt // | Ctxt_refine_sort : bv -> term_ctxt -> term -> term_ctxt // | Ctxt_refine_ref : bv -> typ -> term_ctxt -> term_ctxt // | Ctxt_let_sort : bool -> list term -> bv -> term_ctxt -> term -> term -> term_ctxt // | Ctxt_let_def : bool -> list term -> bv -> term -> term_ctxt -> term -> term_ctxt // | Ctxt_let_body : bool -> list term -> bv -> term -> term -> term_ctxt -> term_ctxt // | Ctxt_match_scrutinee : term_ctxt -> option match_returns_ascription -> list branch -> term_ctxt // and bv_ctxt = // | Ctxt_bv : sealed string -> nat -> term_ctxt -> bv_ctxt // and binder_ctxt = // | Ctxt_binder : bv -> aqualv -> list term -> term_ctxt -> binder_ctxt // and comp_ctxt = // | Ctxt_total : term_ctxt -> comp_ctxt // | Ctxt_gtotal : term_ctxt -> comp_ctxt let rec apply_term_ctxt (e:term_ctxt) (t:term) : Tot term (decreases e) = match e with | Ctxt_hole -> t | Ctxt_app_head e arg -> pack_ln (Tv_App (apply_term_ctxt e t) arg) | Ctxt_app_arg hd q e -> pack_ln (Tv_App hd (apply_term_ctxt e t, q)) // | Ctxt_abs_binder b body -> pack_ln (Tv_Abs (apply_binder_ctxt b t) body) // | Ctxt_abs_body b e -> pack_ln (Tv_Abs b (apply_term_ctxt e t)) // | Ctxt_arrow_binder b c -> pack_ln (Tv_Arrow (apply_binder_ctxt b t) c) // | Ctxt_arrow_comp b c -> pack_ln (Tv_Arrow b (apply_comp_ctxt c t)) // | Ctxt_refine_sort b sort phi -> pack_ln (Tv_Refine b (apply_term_ctxt sort t) phi) // | Ctxt_refine_ref b sort phi -> pack_ln (Tv_Refine b sort (apply_term_ctxt phi t)) // | Ctxt_let_sort b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv (apply_term_ctxt sort t) def body) // | Ctxt_let_def b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort (apply_term_ctxt def t) body) // | Ctxt_let_body b attrs bv sort def body -> // pack_ln (Tv_Let b attrs bv sort def (apply_term_ctxt body t)) // | Ctxt_match_scrutinee sc ret brs -> // pack_ln (Tv_Match (apply_term_ctxt sc t) ret brs) // and apply_binder_ctxt (b:binder_ctxt) (t:term) : Tot binder (decreases b) = // let Ctxt_binder binder_bv binder_qual binder_attrs ctxt = b in // pack_binder {binder_bv; binder_qual; binder_attrs; binder_sort=apply_term_ctxt ctxt t} // and apply_comp_ctxt (c:comp_ctxt) (t:term) : Tot comp (decreases c) = // match c with // | Ctxt_total e -> pack_comp (C_Total (apply_term_ctxt e t)) // | Ctxt_gtotal e -> pack_comp (C_GTotal (apply_term_ctxt e t)) noeq type constant_typing: vconst -> term -> Type0 = | CT_Unit: constant_typing C_Unit unit_ty | CT_True: constant_typing C_True bool_ty | CT_False: constant_typing C_False bool_ty [@@ no_auto_projectors] noeq type univ_eq : universe -> universe -> Type0 = | UN_Refl : u:universe -> univ_eq u u | UN_MaxCongL : u:universe -> u':universe -> v:universe -> univ_eq u u' -> univ_eq (u_max u v) (u_max u' v) | UN_MaxCongR : u:universe -> v:universe -> v':universe -> univ_eq v v' -> univ_eq (u_max u v) (u_max u v') | UN_MaxComm: u:universe -> v:universe -> univ_eq (u_max u v) (u_max v u) | UN_MaxLeq: u:universe -> v:universe -> univ_leq u v -> univ_eq (u_max u v) v and univ_leq : universe -> universe -> Type0 = | UNLEQ_Refl: u:universe -> univ_leq u u | UNLEQ_Succ: u:universe -> v:universe -> univ_leq u v -> univ_leq u (u_succ v) | UNLEQ_Max: u:universe -> v:universe -> univ_leq u (u_max u v) let mk_if (scrutinee then_ else_:R.term) : R.term = pack_ln (Tv_Match scrutinee None [(Pat_Constant C_True, then_); (Pat_Constant C_False, else_)]) // effect and type type comp_typ = T.tot_or_ghost & typ let close_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) [ ND x i ] let close_comp_typ (c:comp_typ) (x:var) = close_comp_typ' c x 0 let open_comp_typ' (c:comp_typ) (x:var) (i:nat) = fst c, subst_term (snd c) (open_with_var x i) let open_comp_typ (c:comp_typ) (x:var) = open_comp_typ' c x 0 let freevars_comp_typ (c:comp_typ) = freevars (snd c) let mk_comp (c:comp_typ) : R.comp = match fst c with | T.E_Total -> mk_total (snd c) | T.E_Ghost -> mk_ghost (snd c) let mk_arrow_ct ty qual (c:comp_typ) : R.term = R.pack_ln (R.Tv_Arrow (binder_of_t_q ty qual) (mk_comp c)) type relation = | R_Eq | R_Sub let binding = var & term let bindings = list binding let rename_bindings bs x y = FStar.List.Tot.map (fun (v, t) -> (v, rename t x y)) bs let rec extend_env_l (g:env) (bs:bindings) : env = match bs with | [] -> g | (x,t)::bs -> extend_env (extend_env_l g bs) x t // // TODO: support for erasable attribute // let is_non_informative_name (l:name) : bool = l = R.unit_lid || l = R.squash_qn || l = ["FStar"; "Ghost"; "erased"] let is_non_informative_fv (f:fv) : bool = is_non_informative_name (inspect_fv f) let rec __close_term_vs (i:nat) (vs : list var) (t : term) : Tot term (decreases vs) = match vs with | [] -> t | v::vs -> subst_term (__close_term_vs (i+1) vs t) [ND v i] let close_term_vs (vs : list var) (t : term) : term = __close_term_vs 0 vs t let close_term_bs (bs : list binding) (t : term) : term = close_term_vs (List.Tot.map fst bs) t let bindings_to_refl_bindings (bs : list binding) : list R.binding = L.map (fun (v, ty) -> {uniq=v; sort=ty; ppname = pp_name_default}) bs let refl_bindings_to_bindings (bs : list R.binding) : list binding = L.map (fun b -> b.uniq, b.sort) bs [@@ no_auto_projectors] noeq type non_informative : env -> term -> Type0 = | Non_informative_type: g:env -> u:universe -> non_informative g (pack_ln (Tv_Type u)) | Non_informative_fv: g:env -> x:fv{is_non_informative_fv x} -> non_informative g (pack_ln (Tv_FVar x)) | Non_informative_uinst: g:env -> x:fv{is_non_informative_fv x} -> us:list universe -> non_informative g (pack_ln (Tv_UInst x us)) | Non_informative_app: g:env -> t:term -> arg:argv -> non_informative g t -> non_informative g (pack_ln (Tv_App t arg)) | Non_informative_total_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g t1 -> non_informative g (mk_arrow_ct t0 q (T.E_Total, t1)) | Non_informative_ghost_arrow: g:env -> t0:term -> q:aqualv -> t1:term -> non_informative g (mk_arrow_ct t0 q (T.E_Ghost, t1)) | Non_informative_token: g:env -> t:typ -> squash (T.non_informative_token g t) -> non_informative g t val bindings_ok_for_pat : env -> list R.binding -> pattern -> Type0 val bindings_ok_pat_constant : g:env -> c:R.vconst -> Lemma (bindings_ok_for_pat g [] (Pat_Constant c)) let bindings_ok_for_branch (g:env) (bs : list R.binding) (br : branch) : Type0 = bindings_ok_for_pat g bs (fst br) let bindings_ok_for_branch_N (g:env) (bss : list (list R.binding)) (brs : list branch) = zip2prop (bindings_ok_for_branch g) bss brs let binding_to_namedv (b:R.binding) : Tot namedv = pack_namedv { RD.uniq = b.uniq; RD.sort = seal b.sort; RD.ppname = b.ppname; } (* Elaborates the p pattern into a term, using the bs bindings for the pattern variables. The resulting term is properly scoped only on an environment which contains all of bs. See for instance the branch_typing judg. Returns an option, since this can fail if e.g. there are not enough bindings, and returns the list of unused binders as well, which should be empty if the list of binding was indeed ok. *) let rec elaborate_pat (p : pattern) (bs : list R.binding) : Tot (option (term & list R.binding)) (decreases p) = match p, bs with | Pat_Constant c, _ -> Some (pack_ln (Tv_Const c), bs) | Pat_Cons fv univs subpats, bs -> let head = pack_ln (Tv_FVar fv) in fold_left_dec (Some (head, bs)) subpats (fun st pi -> let (p,i) = pi in match st with | None -> None | Some (head, bs) -> match elaborate_pat p bs with | None -> None | Some (t, bs') -> Some (pack_ln (Tv_App head (t, (if i then Q_Implicit else Q_Explicit))), bs')) | Pat_Var _ _, b::bs -> Some (pack_ln (Tv_Var (binding_to_namedv b)), bs) | Pat_Dot_Term (Some t), _ -> Some (t, bs) | Pat_Dot_Term None, _ -> None | _ -> None [@@ no_auto_projectors] noeq type typing : env -> term -> comp_typ -> Type0 = | T_Token : g:env -> e:term -> c:comp_typ -> squash (T.typing_token g e c) -> typing g e c | T_Var : g:env -> x:namedv { Some? (lookup_bvar g (namedv_uniq x)) } -> typing g (pack_ln (Tv_Var x)) (T.E_Total, Some?.v (lookup_bvar g (namedv_uniq x))) | T_FVar : g:env -> x:fv { Some? (lookup_fvar g x) } -> typing g (pack_ln (Tv_FVar x)) (T.E_Total, Some?.v (lookup_fvar g x)) | T_UInst : g:env -> x:fv -> us:list universe { Some? (lookup_fvar_uinst g x us) } -> typing g (pack_ln (Tv_UInst x us)) (T.E_Total, Some?.v (lookup_fvar_uinst g x us)) | T_Const: g:env -> v:vconst -> t:term -> constant_typing v t -> typing g (constant_as_term v) (T.E_Total, t) | T_Abs : g:env -> x:var { None? (lookup_bvar g x) } -> ty:term -> body:term { ~(x `Set.mem` freevars body) } -> body_c:comp_typ -> u:universe -> pp_name:pp_name_t -> q:aqualv -> ty_eff:T.tot_or_ghost -> typing g ty (ty_eff, tm_type u) -> typing (extend_env g x ty) (open_term body x) body_c -> typing g (pack_ln (Tv_Abs (mk_binder pp_name ty q) body)) (T.E_Total, pack_ln (Tv_Arrow (mk_binder pp_name ty q) (mk_comp (close_comp_typ body_c x)))) | T_App : g:env -> e1:term -> e2:term -> x:binder -> t:term -> eff:T.tot_or_ghost -> typing g e1 (eff, pack_ln (Tv_Arrow x (mk_comp (eff, t)))) -> typing g e2 (eff, binder_sort x) -> typing g (pack_ln (Tv_App e1 (e2, binder_qual x))) (eff, open_with t e2) | T_Let: g:env -> x:var { None? (lookup_bvar g x) } -> e1:term -> t1:typ -> e2:term -> t2:typ -> eff:T.tot_or_ghost -> pp_name:pp_name_t -> typing g e1 (eff, t1) -> typing (extend_env g x t1) (open_term e2 x) (eff, t2) -> typing g (mk_let pp_name e1 t1 e2) (eff, open_with (close_term t2 x) e1) | T_Arrow: g:env -> x:var { None? (lookup_bvar g x) } -> t1:term -> t2:term { ~(x `Set.mem` freevars t2) } -> u1:universe -> u2:universe -> pp_name:pp_name_t -> q:aqualv -> eff:T.tot_or_ghost -> t1_eff:T.tot_or_ghost -> t2_eff:T.tot_or_ghost -> typing g t1 (t1_eff, tm_type u1) -> typing (extend_env g x t1) (open_term t2 x) (t2_eff, tm_type u2) -> typing g (pack_ln (Tv_Arrow (mk_binder pp_name t1 q) (mk_comp (eff, t2)))) (T.E_Total, tm_type (u_max u1 u2)) | T_Refine: g:env -> x:var { None? (lookup_bvar g x) } -> t:term -> e:term { ~(x `Set.mem` freevars e) } -> u1:universe -> u2:universe -> t_eff:T.tot_or_ghost -> e_eff:T.tot_or_ghost -> typing g t (t_eff, tm_type u1) -> typing (extend_env g x t) (open_term e x) (e_eff, tm_type u2) -> typing g (pack_ln (Tv_Refine (mk_simple_binder pp_name_default t) e)) (T.E_Total, tm_type u1) | T_PropIrrelevance: g:env -> e:term -> t:term -> e_eff:T.tot_or_ghost -> t_eff:T.tot_or_ghost -> typing g e (e_eff, t) -> typing g t (t_eff, tm_prop) -> typing g (`()) (T.E_Total, t) | T_Sub: g:env -> e:term -> c:comp_typ -> c':comp_typ -> typing g e c -> sub_comp g c c' -> typing g e c' | T_If: g:env -> scrutinee:term -> then_:term -> else_:term -> ty:term -> u_ty:universe -> hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) } -> eff:T.tot_or_ghost -> ty_eff:T.tot_or_ghost -> typing g scrutinee (eff, bool_ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty) -> typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty) -> typing g ty (ty_eff, tm_type u_ty) -> //typedness of ty cannot rely on hyp typing g (mk_if scrutinee then_ else_) (eff, ty) | T_Match: g:env -> sc_u : universe -> sc_ty : typ -> sc : term -> ty_eff:T.tot_or_ghost -> typing g sc_ty (ty_eff, tm_type sc_u) -> eff:T.tot_or_ghost -> typing g sc (eff, sc_ty) -> branches:list branch -> ty:comp_typ -> bnds:list (list R.binding) -> complet : match_is_complete g sc sc_ty (List.Tot.map fst branches) bnds -> // complete patterns branches_typing g sc_u sc_ty sc ty branches bnds -> // each branch has proper type typing g (pack_ln (Tv_Match sc None branches)) ty and related : env -> term -> relation -> term -> Type0 = | Rel_refl: g:env -> t:term -> rel:relation -> related g t rel t | Rel_sym: g:env -> t0:term -> t1:term -> related g t0 R_Eq t1 -> related g t1 R_Eq t0 | Rel_trans: g:env -> t0:term -> t1:term -> t2:term -> rel:relation -> related g t0 rel t1 -> related g t1 rel t2 -> related g t0 rel t2 | Rel_univ: g:env -> u:universe -> v:universe -> univ_eq u v -> related g (tm_type u) R_Eq (tm_type v) | Rel_beta: g:env -> t:typ -> q:aqualv -> e:term { ln' e 0 } -> arg:term { ln arg } -> related g (R.pack_ln (R.Tv_App (mk_abs t q e) (arg, q))) R_Eq (subst_term e [ DT 0 arg ]) | Rel_eq_token: g:env -> t0:term -> t1:term -> squash (T.equiv_token g t0 t1) -> related g t0 R_Eq t1 | Rel_subtyping_token: g:env -> t0:term -> t1:term -> squash (T.subtyping_token g t0 t1) -> related g t0 R_Sub t1 | Rel_equiv: g:env -> t0:term -> t1:term -> rel:relation -> related g t0 R_Eq t1 -> related g t0 rel t1 | Rel_arrow: g:env -> t1:term -> t2:term -> q:aqualv -> c1:comp_typ -> c2:comp_typ -> rel:relation -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars_comp_typ c1 `Set.union` freevars_comp_typ c2)) } -> related g t2 rel t1 -> related_comp (extend_env g x t2) (open_comp_typ c1 x) rel (open_comp_typ c2 x) -> related g (mk_arrow_ct t1 q c1) rel (mk_arrow_ct t2 q c2) | Rel_abs: g:env -> t1:term -> t2:term -> q:aqualv -> e1:term -> e2:term -> x:var{ None? (lookup_bvar g x) /\ ~ (x `Set.mem` (freevars e1 `Set.union` freevars e2)) } -> related g t1 R_Eq t2 -> related (extend_env g x t1) (subst_term e1 (open_with_var x 0)) R_Eq (subst_term e2 (open_with_var x 0)) -> related g (mk_abs t1 q e1) R_Eq (mk_abs t2 q e2) | Rel_ctxt: g:env -> t0:term -> t1:term -> ctxt:term_ctxt -> related g t0 R_Eq t1 -> related g (apply_term_ctxt ctxt t0) R_Eq (apply_term_ctxt ctxt t1) and related_comp : env -> comp_typ -> relation -> comp_typ -> Type0 = | Relc_typ: g:env -> t0:term -> t1:term -> eff:T.tot_or_ghost -> rel:relation -> related g t0 rel t1 -> related_comp g (eff, t0) rel (eff, t1) | Relc_total_ghost: g:env -> t:term -> related_comp g (T.E_Total, t) R_Sub (T.E_Ghost, t) | Relc_ghost_total: g:env -> t:term -> non_informative g t -> related_comp g (T.E_Ghost, t) R_Sub (T.E_Total, t) and branches_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (brs:list branch) -> (bnds : list (list R.binding)) -> Type0 = (* This judgement only enforces that branch_typing holds for every element of brs and its respective bnds (which must have the same length). *) | BT_Nil : branches_typing g sc_u sc_ty sc rty [] [] | BT_S : br : branch -> bnds : list R.binding -> pf : branch_typing g sc_u sc_ty sc rty br bnds -> rest_br : list branch -> rest_bnds : list (list R.binding) -> rest : branches_typing g sc_u sc_ty sc rty rest_br rest_bnds -> branches_typing g sc_u sc_ty sc rty (br :: rest_br) (bnds :: rest_bnds) and branch_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) (rty:comp_typ) : (br : branch) -> (bnds : list R.binding) -> Type0 = | BO : pat : pattern -> bnds : list R.binding{bindings_ok_for_pat g bnds pat} -> hyp_var:var{None? (lookup_bvar (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var)} -> body:term -> _ : squash (Some? (elaborate_pat pat bnds)) -> typing (extend_env (extend_env_l g (refl_bindings_to_bindings bnds)) hyp_var (eq2 sc_u sc_ty sc (fst (Some?.v (elaborate_pat pat bnds)))) ) body rty -> branch_typing g sc_u sc_ty sc rty (pat, close_term_bs (refl_bindings_to_bindings bnds) body) bnds and match_is_complete : env -> term -> typ -> list pattern -> list (list R.binding) -> Type0 = | MC_Tok : env:_ -> sc:_ -> ty:_ -> pats:_ -> bnds:_ -> squash (T.match_complete_token env sc ty pats bnds) -> match_is_complete env sc ty pats bnds and sub_typing (g:env) (t1 t2:term) = related g t1 R_Sub t2 and sub_comp (g:env) (c1 c2:comp_typ) = related_comp g c1 R_Sub c2 and equiv (g:env) (t1 t2:term) = related g t1 R_Eq t2 type tot_typing (g:env) (e:term) (t:term) = typing g e (T.E_Total, t) type ghost_typing (g:env) (e:term) (t:term) = typing g e (T.E_Ghost, t) val subtyping_token_renaming (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (y:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) y) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1) : T.subtyping_token (extend_env_l g (rename_bindings bs1 x y@(y,t)::bs0)) (rename t0 x y) (rename t1 x y) val subtyping_token_weakening (g:env) (bs0:bindings) (bs1:bindings) (x:var { None? (lookup_bvar (extend_env_l g (bs1@bs0)) x) }) (t:term) (t0 t1:term) (d:T.subtyping_token (extend_env_l g (bs1@bs0)) t0 t1) : T.subtyping_token (extend_env_l g (bs1@(x,t)::bs0)) t0 t1 let simplify_umax (#g:R.env) (#t:R.term) (#u:R.universe) (d:typing g t (T.E_Total, tm_type (u_max u u))) : typing g t (T.E_Total, tm_type u) = let ue : univ_eq (u_max u u) u = UN_MaxLeq u u (UNLEQ_Refl u) in let du : related g (tm_type (u_max u u)) R_Eq (tm_type u) = Rel_univ g (u_max u u) u ue in let du : related g (tm_type (u_max u u)) R_Sub (tm_type u) = Rel_equiv _ _ _ _ du in T_Sub _ _ _ _ d (Relc_typ _ _ _ T.E_Total _ du) val well_typed_terms_are_ln (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : Lemma (ensures ln e /\ ln (snd c)) val type_correctness (g:R.env) (e:R.term) (c:comp_typ) (_:typing g e c) : GTot (u:R.universe & typing g (snd c) (T.E_Total, tm_type u)) val binder_offset_pattern_invariant (p:pattern) (ss:subst) : Lemma (binder_offset_pattern p == binder_offset_pattern (subst_pattern p ss)) val binder_offset_patterns_invariant (p:list (pattern & bool)) (ss:subst) : Lemma (binder_offset_patterns p == binder_offset_patterns (subst_patterns p ss)) val open_close_inverse' (i:nat) (t:term { ln' t (i - 1) }) (x:var) : Lemma (ensures subst_term (subst_term t [ ND x i ]) (open_with_var x i) == t) val open_close_inverse'_binder (i:nat) (b:binder { ln'_binder b (i - 1) }) (x:var) : Lemma (ensures subst_binder (subst_binder b [ ND x i ]) (open_with_var x i) == b) val open_close_inverse'_terms (i:nat) (ts:list term { ln'_terms ts (i - 1) }) (x:var) : Lemma (ensures subst_terms (subst_terms ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_comp (i:nat) (c:comp { ln'_comp c (i - 1) }) (x:var) : Lemma (ensures subst_comp (subst_comp c [ ND x i ]) (open_with_var x i) == c) val open_close_inverse'_args (i:nat) (ts:list argv { ln'_args ts (i - 1) }) (x:var) : Lemma (ensures subst_args (subst_args ts [ ND x i ]) (open_with_var x i) == ts) val open_close_inverse'_patterns (i:nat) (ps:list (pattern & bool) { ln'_patterns ps (i - 1) }) (x:var) : Lemma (ensures subst_patterns (subst_patterns ps [ ND x i ]) (open_with_var x i) == ps) val open_close_inverse'_pattern (i:nat) (p:pattern{ln'_pattern p (i - 1)}) (x:var) : Lemma (ensures subst_pattern (subst_pattern p [ ND x i ]) (open_with_var x i) == p) val open_close_inverse'_branch (i:nat) (br:branch{ln'_branch br (i - 1)}) (x:var) : Lemma (ensures subst_branch (subst_branch br [ ND x i ]) (open_with_var x i) == br) val open_close_inverse'_branches (i:nat) (brs:list branch { ln'_branches brs (i - 1) }) (x:var) : Lemma (ensures subst_branches (subst_branches brs [ ND x i ]) (open_with_var x i) == brs) val open_close_inverse'_match_returns (i:nat) (m:match_returns_ascription { ln'_match_returns m (i - 1) }) (x:var) : Lemma (ensures subst_match_returns (subst_match_returns m [ ND x i ]) (open_with_var x i) == m) val open_close_inverse (e:R.term { ln e }) (x:var) : Lemma (open_term (close_term e x) x == e) val close_open_inverse' (i:nat) (t:term) (x:var { ~(x `Set.mem` freevars t) }) : Lemma (ensures subst_term (subst_term t (open_with_var x i)) [ ND x i ] == t) val close_open_inverse'_comp (i:nat) (c:comp) (x:var{ ~(x `Set.mem` freevars_comp c) }) : Lemma (ensures subst_comp (subst_comp c (open_with_var x i)) [ ND x i ] == c) val close_open_inverse'_args (i:nat) (args:list argv) (x:var{ ~(x `Set.mem` freevars_args args) }) : Lemma (ensures subst_args (subst_args args (open_with_var x i)) [ ND x i] == args) val close_open_inverse'_binder (i:nat) (b:binder) (x:var{ ~(x `Set.mem` freevars_binder b) }) : Lemma (ensures subst_binder (subst_binder b (open_with_var x i)) [ ND x i ] == b) val close_open_inverse'_terms (i:nat) (ts:list term) (x:var{ ~(x `Set.mem` freevars_terms ts) }) : Lemma (ensures subst_terms (subst_terms ts (open_with_var x i)) [ ND x i ] == ts) val close_open_inverse'_branches (i:nat) (brs:list branch) (x:var{ ~(x `Set.mem` freevars_branches brs) }) : Lemma (ensures subst_branches (subst_branches brs (open_with_var x i)) [ ND x i ] == brs) val close_open_inverse'_branch (i:nat) (br:branch) (x:var{ ~(x `Set.mem` freevars_branch br) }) : Lemma (ensures subst_branch (subst_branch br (open_with_var x i)) [ ND x i ] == br) val close_open_inverse'_pattern (i:nat) (p:pattern) (x:var{ ~(x `Set.mem` freevars_pattern p) }) : Lemma (ensures subst_pattern (subst_pattern p (open_with_var x i)) [ ND x i ] == p) val close_open_inverse'_patterns (i:nat) (ps:list (pattern & bool)) (x:var {~ (x `Set.mem` freevars_patterns ps) }) : Lemma (ensures subst_patterns (subst_patterns ps (open_with_var x i)) [ ND x i ] == ps) val close_open_inverse'_match_returns (i:nat) (m:match_returns_ascription) (x:var{ ~(x `Set.mem` freevars_match_returns m) }) : Lemma (ensures subst_match_returns (subst_match_returns m (open_with_var x i)) [ ND x i ] == m) val close_open_inverse (e:R.term) (x:var {~ (x `Set.mem` freevars e) }) : Lemma (close_term (open_term e x) x == e) // // fst has corresponding lemmas for other syntax classes // val close_with_not_free_var (t:R.term) (x:var) (i:nat) : Lemma (requires ~ (Set.mem x (freevars t))) (ensures subst_term t [ ND x i ] == t) // this also requires x to be not in freevars e1 `Set.union` freevars e2 val equiv_arrow (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var { None? (lookup_bvar g x) }) (eq:equiv (extend_env g x ty) (subst_term e1 (open_with_var x 0)) (subst_term e2 (open_with_var x 0))) : equiv g (mk_arrow ty q e1) (mk_arrow ty q e2) // the proof for this requires e1 and e2 to be ln val equiv_abs_close (#g:R.env) (#e1 #e2:R.term) (ty:R.typ) (q:R.aqualv) (x:var{None? (lookup_bvar g x)}) (eq:equiv (extend_env g x ty) e1 e2) : equiv g (mk_abs ty q (subst_term e1 [ ND x 0 ])) (mk_abs ty q (subst_term e2 [ ND x 0 ])) val open_with_gt_ln (e:term) (i:nat) (t:term) (j:nat) : Lemma (requires ln' e i /\ i < j) (ensures subst_term e [ DT j t ] == e) [SMTPat (ln' e i); SMTPat (subst_term e [ DT j t ])] // // Type of the top-level tactic that would splice-in the definitions // let fstar_env_fvs (g:R.env) = lookup_fvar g unit_fv == Some (tm_type u_zero) /\ lookup_fvar g bool_fv == Some (tm_type u_zero) /\ lookup_fvar g b2t_fv == Some b2t_ty type fstar_env = g:R.env{fstar_env_fvs g} type fstar_top_env = g:fstar_env { forall x. None? (lookup_bvar g x ) } // // This doesn't allow for universe polymorphic definitions // // May be we can change it to: // // g:fstar_top_env -> T.tac ((us, e, t):(univ_names & term & typ){typing (push g us) e t}) // noeq type sigelt_typing : env -> sigelt -> Type0 = | ST_Let : g : env -> fv : R.fv -> ty : R.typ -> tm : R.term -> squash (typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm })])) | ST_Let_Opaque : g : env -> fv : R.fv -> ty : R.typ -> (* no tm: only a proof of existence *) squash (exists (tm:R.term). typing g tm (T.E_Total, ty)) -> sigelt_typing g (pack_sigelt (Sg_Let false [pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = (`_) })])) (** * The type of the top-level tactic that would splice-in the definitions. * It returns a list of well typed definitions, via the judgment above. * * Each definition can have a 'blob' attached with a given name. * The blob can be used later, e.g., during extraction, and passed back to the * extension to perform additional processing. *) (* * It returns either: * - Some tm, blob, typ, with a proof that `typing g tm typ` * - None, blob, typ), with a proof that `exists tm. typing g tm typ` * The blob itself is optional and can store some additional metadata that * constructed by the tactic. If present, it will be stored in the * sigmeta_extension_data field of the enclosing sigelt. * *) let blob = string & R.term (* If checked is true, this sigelt is properly typed for the environment. If not, we don't know and let F* re-typecheck the sigelt. *) let sigelt_for (g:env) = tup:(bool & sigelt & option blob) { let (checked, se, _) = tup in checked ==> sigelt_typing g se } let dsl_tac_result_t (g:env) = list (sigelt_for g) type dsl_tac_t = g:fstar_top_env -> T.Tac (dsl_tac_result_t g) val if_complete_match (g:env) (t:term) : T.match_complete_token g t bool_ty [ Pat_Constant C_True; Pat_Constant C_False; ] [[]; []] // Derived rule for if val mkif (g:fstar_env) (scrutinee:term) (then_:term) (else_:term) (ty:term) (u_ty:universe) (hyp:var { None? (lookup_bvar g hyp) /\ ~(hyp `Set.mem` (freevars then_ `Set.union` freevars else_)) }) (eff:T.tot_or_ghost) (ty_eff:T.tot_or_ghost) (ts : typing g scrutinee (eff, bool_ty)) (tt : typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee true_bool)) then_ (eff, ty)) (te : typing (extend_env g hyp (eq2 (pack_universe Uv_Zero) bool_ty scrutinee false_bool)) else_ (eff, ty)) (tr : typing g ty (ty_eff, tm_type u_ty)) : typing g (mk_if scrutinee then_ else_) (eff, ty) (* Helper to return a single let definition in a splice_t tactic. *) let mk_checked_let (g:R.env) (nm:string) (tm:R.term) (ty:R.typ{typing g tm (T.E_Total, ty)}) : T.Tac (sigelt_for g) = let fv = pack_fv (T.cur_module () @ [nm]) in let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm }) in let se = R.pack_sigelt (R.Sg_Let false [lb]) in let pf : sigelt_typing g se = ST_Let g fv ty tm () in ( true, se, None )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Set.fsti.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Reflection.Typing.fsti" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: FStar.Stubs.Reflection.Types.env -> nm: Prims.string -> tm: FStar.Stubs.Reflection.Types.term -> ty: FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac (FStar.Reflection.Typing.sigelt_for g)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.env", "Prims.string", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.Mktuple3", "Prims.bool", "FStar.Stubs.Reflection.Types.sigelt", "FStar.Pervasives.Native.option", "FStar.Reflection.Typing.blob", "FStar.Pervasives.Native.None", "FStar.Stubs.Reflection.V2.Builtins.pack_sigelt", "FStar.Stubs.Reflection.V2.Data.Sg_Let", "Prims.Cons", "FStar.Stubs.Reflection.Types.letbinding", "Prims.Nil", "FStar.Stubs.Reflection.V2.Builtins.pack_lb", "FStar.Stubs.Reflection.V2.Data.Mklb_view", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Reflection.Typing.sigelt_for", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Stubs.Reflection.Types.name", "FStar.List.Tot.Base.op_At", "Prims.list", "FStar.Tactics.V2.Derived.cur_module" ]
[]
false
true
false
false
false
let mk_unchecked_let (g: R.env) (nm: string) (tm: R.term) (ty: R.typ) : T.Tac (sigelt_for g) =
let fv = pack_fv (T.cur_module () @ [nm]) in let lb = R.pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = ty; lb_def = tm }) in let se = R.pack_sigelt (R.Sg_Let false [lb]) in (false, se, None)
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.lemma_a_minus_b_n_c_n_k
val lemma_a_minus_b_n_c_n_k (k a b c:nat) (n:pos) : Lemma (requires k < n /\ k == a - b * n - c * n) (ensures k == a % n)
val lemma_a_minus_b_n_c_n_k (k a b c:nat) (n:pos) : Lemma (requires k < n /\ k == a - b * n - c * n) (ensures k == a % n)
let lemma_a_minus_b_n_c_n_k k a b c n = Math.Lemmas.lemma_mod_sub (a - b * n) n c; Math.Lemmas.lemma_mod_sub a n b; Math.Lemmas.small_mod k n
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 352, "start_col": 0, "start_line": 349 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4) noextract let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4) val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12)))) let normalize5_first_part_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let t = normalize_weak5 f in let (t0,t1,t2,t3,t4) = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - v f4 / pow2 48 * S.prime); assert (felem_fits5 t (1,1,1,1,2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let (r0,r1,r2,r3,r4) = r in minus_x_mul_pow2_256_lemma (1,1,1,1,2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); assert (felem_fits5 r (1,1,1,1,1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12) val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime)) let normalize5_second_part_x_is_one_lemma x r = LD.lemma_as_nat_bound_f4_lt_pow12 r; assert (as_nat5 r <= pow2 220 - 1); assert_norm (pow2 220 - 1 < S.prime); let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (v is_ge_p_m = 0); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_commutative #64 (v m_to_one) (v x); FStar.UInt.logor_lemma_1 #64 (v x); assert (v x1 = 1); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in Math.Lemmas.pow2_double_sum 12; assert (v s4 < pow2 13); let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 s); assert (as_nat5 k < pow2 220 + pow2 256 - S.prime); assert_norm (pow2 220 + pow2 256 - S.prime < S.prime) val normalize5_second_part_x_is_zero_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 0)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == (if as_nat5 r < S.prime then as_nat5 r else as_nat5 r - S.prime) /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime)) let normalize5_second_part_x_is_zero_lemma x r = let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (if v is_ge_p_m = ones_v U64 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (if v is_ge_p_m = ones_v U64 then v m_to_one = 1 else v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_lemma_1 #64 (v m_to_one); assert (v x1 = v m_to_one); assert (if v x1 = 1 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x1 * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + v x1 * (pow2 256 - S.prime)); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); if v x1 = 0 then begin assert (as_nat5 s = as_nat5 r); LD.as_nat_inj s r; assert (felem_fits_last1 s4 1); Math.Lemmas.small_div (v s4) (pow2 48); assert (as_nat5 k = as_nat5 r) end else begin assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); assert (as_nat5 s >= pow2 256); assert (v s4 >= pow2 48); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 r - S.prime) end val lemma_a_minus_b_n_c_n_k (k a b c:nat) (n:pos) : Lemma (requires k < n /\ k == a - b * n - c * n) (ensures k == a % n)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.nat -> a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> n: Prims.pos -> FStar.Pervasives.Lemma (requires k < n /\ k == a - b * n - c * n) (ensures k == a % n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.pos", "FStar.Math.Lemmas.small_mod", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_sub", "Prims.op_Subtraction", "FStar.Mul.op_Star" ]
[]
true
false
true
false
false
let lemma_a_minus_b_n_c_n_k k a b c n =
Math.Lemmas.lemma_mod_sub (a - b * n) n c; Math.Lemmas.lemma_mod_sub a n b; Math.Lemmas.small_mod k n
false
Vale.X64.BufferViewStore.fst
Vale.X64.BufferViewStore.get64_aux
val get64_aux (ptr: int) (heap: machine_heap) (v: nat64) (k: nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k))
val get64_aux (ptr: int) (heap: machine_heap) (v: nat64) (k: nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k))
let get64_aux (ptr:int) (heap:machine_heap) (v:nat64) (k:nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)) = get_heap_val64_reveal (); put64_reveal (); le_nat64_to_bytes_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); four_to_nat_8_injective (); two_to_nat_32_injective ()
{ "file_name": "vale/code/arch/x64/Vale.X64.BufferViewStore.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 38, "start_col": 0, "start_line": 30 }
module Vale.X64.BufferViewStore open FStar.Mul open Vale.Interop.Views open Vale.Interop module MB = LowStar.Monotonic.Buffer module HS = FStar.HyperStack open Vale.Lib.BufferViewHelpers open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Two open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open Vale.Arch.Types open FStar.Calc friend LowStar.BufferView.Up #reset-options "--z3rlimit 10 --max_fuel 0 --initial_fuel 0 --max_ifuel 1 --initial_ifuel 1" let math_aux (a b c:int) : Lemma (a + b + (c - b) == a + c) = () let map_aux (ptr1 ptr2:int) (v:int) (m:machine_heap) : Lemma (requires ptr1 == ptr2 /\ m.[ptr1] == v) (ensures m.[ptr2] == v) = ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Two.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferView.Up.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.BufferViewStore.fst" }
[ { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> heap: Vale.Arch.MachineHeap_s.machine_heap -> v: Vale.Def.Words_s.nat64 -> k: Prims.nat{k < 8} -> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.get_heap_val64 ptr heap == v) (ensures heap.[ ptr + k ] == FStar.UInt8.v (FStar.Seq.Base.index (Vale.Interop.Views.put64 (FStar.UInt64.uint_to_t v)) k) )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Def.Words_s.nat64", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Words.Two.two_to_nat_32_injective", "Prims.unit", "Vale.Def.Words.Seq.four_to_nat_8_injective", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat8", "Prims.eq2", "FStar.Seq.Base.length", "FStar.Mul.op_Star", "Vale.Def.Words.Seq_s.seq_four_to_seq_LE", "Vale.Def.Types_s.le_nat64_to_bytes_reveal", "Vale.Interop.Views.put64_reveal", "Vale.Arch.MachineHeap_s.get_heap_val64_reveal", "Vale.Arch.MachineHeap_s.get_heap_val64", "Prims.squash", "Prims.l_or", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Vale.Def.Words_s.pow2_8", "FStar.UInt.size", "FStar.UInt8.n", "Vale.Interop.op_String_Access", "Vale.Def.Types_s.nat8", "Prims.op_Addition", "FStar.UInt8.v", "FStar.Seq.Base.index", "FStar.UInt8.t", "Vale.Interop.Views.put64", "FStar.UInt64.uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let get64_aux (ptr: int) (heap: machine_heap) (v: nat64) (k: nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ ptr + k ] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)) =
get_heap_val64_reveal (); put64_reveal (); le_nat64_to_bytes_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); four_to_nat_8_injective (); two_to_nat_32_injective ()
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_first_part_lemma
val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12))))
val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12))))
let normalize5_first_part_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let t = normalize_weak5 f in let (t0,t1,t2,t3,t4) = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - v f4 / pow2 48 * S.prime); assert (felem_fits5 t (1,1,1,1,2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let (r0,r1,r2,r3,r4) = r in minus_x_mul_pow2_256_lemma (1,1,1,1,2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); assert (felem_fits5 r (1,1,1,1,1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 249, "start_col": 0, "start_line": 231 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4) noextract let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4) val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12))))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 _ = _ in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 f m) <: Type0)) (ensures (let _ = Hacl.Spec.K256.Field52.Lemmas2.normalize5_first_part f in (let FStar.Pervasives.Native.Mktuple2 #_ #_ x r = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ f4 = _ in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f - (Lib.IntTypes.v f4 / Prims.pow2 48) * Spec.K256.PointOps.prime - Lib.IntTypes.v x * Prims.pow2 256 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 1) /\ (Lib.IntTypes.v x = 0 \/ Lib.IntTypes.v x = 1 /\ Lib.IntTypes.v r4 < Prims.pow2 12)) <: Type0) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Lib.IntTypes.uint64", "Prims._assert", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.pow2", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.l_and", "Prims.unit", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_div_pow48", "Prims.op_Modulus", "Prims.op_Division", "Hacl.Spec.K256.Field52.Definitions.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.eq2", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Spec.K256.PointOps.prime", "Hacl.Spec.K256.Field52.Lemmas2.minus_x_mul_pow2_256_lemma", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256", "Prims.l_imp", "Prims.op_GreaterThanOrEqual", "Hacl.Spec.K256.Field52.Lemmas2.normalize_weak5_lemma", "Hacl.Spec.K256.Field52.normalize_weak5" ]
[]
false
false
true
false
false
let normalize5_first_part_lemma m f =
let m0, m1, m2, m3, m4 = m in let f0, f1, f2, f3, f4 = f in let t = normalize_weak5 f in let t0, t1, t2, t3, t4 = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - (v f4 / pow2 48) * S.prime); assert (felem_fits5 t (1, 1, 1, 1, 2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let r0, r1, r2, r3, r4 = r in minus_x_mul_pow2_256_lemma (1, 1, 1, 1, 2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - (v f4 / pow2 48) * S.prime - v x * pow2 256); assert (felem_fits5 r (1, 1, 1, 1, 1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12)
false
PulseTutorial.SpinLock.fst
PulseTutorial.SpinLock.lock_inv
val lock_inv : r: Pulse.Lib.Reference.ref FStar.UInt32.t -> p: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
let lock_inv (r:ref U32.t) (p:vprop) = exists* v. pts_to r v ** maybe (v = 0ul) p
{ "file_name": "share/steel/examples/pulse/by-example/PulseTutorial.SpinLock.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 11, "start_col": 0, "start_line": 10 }
module PulseTutorial.SpinLock open Pulse.Lib.Pervasives module Box = Pulse.Lib.Box module U32 = FStar.UInt32 //lock$ let maybe (b:bool) (p:vprop) = if b then p else emp
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.Lib.Box.fsti.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "PulseTutorial.SpinLock.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Pulse.Lib.Box", "short_module": "Box" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "PulseTutorial", "short_module": null }, { "abbrev": false, "full_module": "PulseTutorial", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Pulse.Lib.Reference.ref FStar.UInt32.t -> p: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Reference.ref", "FStar.UInt32.t", "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Reference.pts_to", "PulseCore.FractionalPermission.full_perm", "PulseTutorial.SpinLock.maybe", "Prims.op_Equality", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let lock_inv (r: ref U32.t) (p: vprop) =
exists* v. pts_to r v ** maybe (v = 0ul) p
false
PulseTutorial.SpinLock.fst
PulseTutorial.SpinLock.maybe
val maybe : b: Prims.bool -> p: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
let maybe (b:bool) (p:vprop) = if b then p else emp
{ "file_name": "share/steel/examples/pulse/by-example/PulseTutorial.SpinLock.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 8, "start_col": 0, "start_line": 7 }
module PulseTutorial.SpinLock open Pulse.Lib.Pervasives module Box = Pulse.Lib.Box module U32 = FStar.UInt32
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.Lib.Box.fsti.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "PulseTutorial.SpinLock.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Pulse.Lib.Box", "short_module": "Box" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "PulseTutorial", "short_module": null }, { "abbrev": false, "full_module": "PulseTutorial", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> p: Pulse.Lib.Core.vprop -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.emp" ]
[]
false
false
false
true
false
let maybe (b: bool) (p: vprop) =
if b then p else emp
false
Vale.SHA.PPC64LE.SHA_helpers.fst
Vale.SHA.PPC64LE.SHA_helpers.lemma_shuffle_core_properties
val lemma_shuffle_core_properties (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w_256) (ensures (let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let h = Spec.Loops.repeat_range 0 (t + 1) (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[0] in let b0 = word_to_nat32 hash.[1] in let c0 = word_to_nat32 hash.[2] in let d0 = word_to_nat32 hash.[3] in let e0 = word_to_nat32 hash.[4] in let f0 = word_to_nat32 hash.[5] in let g0 = word_to_nat32 hash.[6] in let h0 = word_to_nat32 hash.[7] in 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 let t2 = add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0) in word_to_nat32 h.[0] == add_wrap t1 t2 /\ word_to_nat32 h.[1] == a0 /\ word_to_nat32 h.[2] == b0 /\ word_to_nat32 h.[3] == c0 /\ word_to_nat32 h.[4] == add_wrap d0 t1 /\ word_to_nat32 h.[5] == e0 /\ word_to_nat32 h.[6] == f0 /\ word_to_nat32 h.[7] == g0))
val lemma_shuffle_core_properties (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w_256) (ensures (let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let h = Spec.Loops.repeat_range 0 (t + 1) (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[0] in let b0 = word_to_nat32 hash.[1] in let c0 = word_to_nat32 hash.[2] in let d0 = word_to_nat32 hash.[3] in let e0 = word_to_nat32 hash.[4] in let f0 = word_to_nat32 hash.[5] in let g0 = word_to_nat32 hash.[6] in let h0 = word_to_nat32 hash.[7] in 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 let t2 = add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0) in word_to_nat32 h.[0] == add_wrap t1 t2 /\ word_to_nat32 h.[1] == a0 /\ word_to_nat32 h.[2] == b0 /\ word_to_nat32 h.[3] == c0 /\ word_to_nat32 h.[4] == add_wrap d0 t1 /\ word_to_nat32 h.[5] == e0 /\ word_to_nat32 h.[6] == f0 /\ word_to_nat32 h.[7] == g0))
let lemma_shuffle_core_properties (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w_256) (ensures (let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let h = Spec.Loops.repeat_range 0 (t + 1) (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[0] in let b0 = word_to_nat32 hash.[1] in let c0 = word_to_nat32 hash.[2] in let d0 = word_to_nat32 hash.[3] in let e0 = word_to_nat32 hash.[4] in let f0 = word_to_nat32 hash.[5] in let g0 = word_to_nat32 hash.[6] in let h0 = word_to_nat32 hash.[7] in 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 let t2 = add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0) in word_to_nat32 h.[0] == add_wrap t1 t2 /\ word_to_nat32 h.[1] == a0 /\ word_to_nat32 h.[2] == b0 /\ word_to_nat32 h.[3] == c0 /\ word_to_nat32 h.[4] == add_wrap d0 t1 /\ word_to_nat32 h.[5] == e0 /\ word_to_nat32 h.[6] == f0 /\ word_to_nat32 h.[7] == g0)) = let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[0] in let b0 = word_to_nat32 hash.[1] in let c0 = word_to_nat32 hash.[2] in let d0 = word_to_nat32 hash.[3] in let e0 = word_to_nat32 hash.[4] in let f0 = word_to_nat32 hash.[5] in let g0 = word_to_nat32 hash.[6] in let h0 = word_to_nat32 hash.[7] in ch_256_reveal (); maj_256_reveal (); lemma_add_wrap_is_add_mod h0 (sigma256_1_1 e0); lemma_add_wrap_is_add_mod (add_wrap h0 (sigma256_1_1 e0)) (ch_256 e0 f0 g0); lemma_add_wrap_is_add_mod (add_wrap (add_wrap h0 (sigma256_1_1 e0)) (ch_256 e0 f0 g0)) (word_to_nat32 k.[t]); lemma_add_wrap_is_add_mod (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); lemma_add_wrap_is_add_mod (sigma256_1_0 a0) (maj_256 a0 b0 c0); lemma_add_wrap_is_add_mod (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)) (add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0)); lemma_add_wrap_is_add_mod d0 (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)); Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_orig; shuffle_core_properties block (Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig) t
{ "file_name": "vale/code/crypto/sha/Vale.SHA.PPC64LE.SHA_helpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 101, "end_line": 449, "start_col": 0, "start_line": 407 }
module Vale.SHA.PPC64LE.SHA_helpers open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Spec.SHA2 open Spec.SHA2.Lemmas open Spec.Agile.Hash open Spec.Hash.Definitions open Spec.Hash.Lemmas open Vale.Def.Types_s open Vale.Def.Words_s open FStar.Seq open FStar.UInt32 // Interop with UInt-based SHA spec open Vale.Arch.Types open Vale.Arch.TypesNative open Vale.Def.Sel open Vale.SHA2.Wrapper friend Spec.SHA2 friend Spec.SHA2.Lemmas friend Vale.SHA2.Wrapper #reset-options "--max_fuel 0 --max_ifuel 0" // Define these specific converters here, so that F* only reasons about // the correctness of the conversion once, rather that at every call site let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n let word = Lib.IntTypes.uint32 let k = (Spec.SHA2.k0 SHA2_256) val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 -> Lemma (add_mod x y == Lib.IntTypes.(x +. y)) [SMTPat (Lib.IntTypes.(x +. y))] let add_mod_lemma x y = () unfold let ws_opaque_aux = ws let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 = vv (ws_opaque_aux SHA2_256 b t) unfold let shuffle_core_opaque_aux = shuffle_core let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 = shuffle_core_opaque_aux SHA2_256 block hash t [@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 = update_multi_opaque_aux SHA2_256 hash () blocks let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) = update_multi SHA2_256 hash () blocks let word_to_nat32 = vv let nat32_to_word = to_uint32 let make_ordered_hash_def (abcd efgh:quad32) : (hash:words_state SHA2_256 { length hash == 8 /\ hash.[0] == to_uint32 abcd.lo0 /\ hash.[1] == to_uint32 abcd.lo1 /\ hash.[2] == to_uint32 abcd.hi2 /\ hash.[3] == to_uint32 abcd.hi3 /\ hash.[4] == to_uint32 efgh.lo0 /\ hash.[5] == to_uint32 efgh.lo1 /\ hash.[6] == to_uint32 efgh.hi2 /\ hash.[7] == to_uint32 efgh.hi3 }) = let a = to_uint32 abcd.lo0 in let b = to_uint32 abcd.lo1 in let c = to_uint32 abcd.hi2 in let d = to_uint32 abcd.hi3 in let e = to_uint32 efgh.lo0 in let f = to_uint32 efgh.lo1 in let g = to_uint32 efgh.hi2 in let h = to_uint32 efgh.hi3 in let l = [a; b; c; d; e; f; g; h] in assert_norm (List.length l == 8); let hash = seq_of_list l in assert (length hash == 8); elim_of_list l; hash [@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) : Lemma(let h = shuffle_core_opaque block hash t in let open Lib.IntTypes in let a0 = hash.[0] in let b0 = hash.[1] in let c0 = hash.[2] in let d0 = hash.[3] in let e0 = hash.[4] in let f0 = hash.[5] in let g0 = hash.[6] in let h0 = hash.[7] in let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in h.[0] == t1 +. t2 /\ h.[1] == a0 /\ h.[2] == b0 /\ h.[3] == c0 /\ h.[4] == d0 +. t1 /\ h.[5] == e0 /\ h.[6] == f0 /\ h.[7] == g0) = Pervasives.reveal_opaque (`%shuffle_core) shuffle_core; let h = shuffle_core SHA2_256 block hash t in let a0 = hash.[0] in let b0 = hash.[1] in let c0 = hash.[2] in let d0 = hash.[3] in let e0 = hash.[4] in let f0 = hash.[5] in let g0 = hash.[6] in let h0 = hash.[7] in let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in assert (h == seq_of_list l); elim_of_list l; () let lemma_add_wrap_is_add_mod (n0 n1:nat32) : Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1))) = assert_norm (pow2 32 == pow2_32); () unfold let shuffle_opaque = shuffle let update_block (hash:hash256) (block:block_w): Tot (hash256) = let hash_1 = shuffle_opaque SHA2_256 hash block in let open Lib.IntTypes in Spec.Loops.seq_map2 ( +. ) hash hash_1 #push-options "--z3cliopt smt.arith.nl=true" (* FIXME: Seemingly needed after fix to #2894 in F*, but should not be *) let lemma_update_block_equiv (hash:hash256) (block:bytes{length block = block_length}) : Lemma (update_block hash (words_of_bytes SHA2_256 #(block_word_length SHA2_256) block) == update SHA2_256 hash block) = Pervasives.reveal_opaque (`%Spec.SHA2.update) Spec.SHA2.update; Pervasives.reveal_opaque (`%Spec.SHA2.shuffle) Spec.SHA2.shuffle; assert (equal (update_block hash (words_of_bytes SHA2_256 #(block_word_length SHA2_256) block)) (update SHA2_256 hash block)); () #pop-options let update_multi_one (h:hash256) (b:bytes_blocks {length b = block_length}) : Lemma (ensures (update_multi SHA2_256 h () b == update SHA2_256 h b)) = update_multi_update SHA2_256 h b friend Lib.ByteSequence #reset-options "--z3rlimit 50 --max_fuel 1 --max_ifuel 0 --z3cliopt smt.arith.nl=true" let lemma_be_to_n_4 (s:seq4 nat8) : Lemma (Lib.ByteSequence.nat_from_bytes_be #Lib.IntTypes.SEC (seq_nat8_to_seq_uint8 s) == be_bytes_to_nat32 s) = let open Lib.IntTypes in let open Vale.Def.Words.Four_s in assert (pow2 8 = 0x100); assert (pow2 16 = 0x10000); assert_norm (pow2 24 = 0x1000000); let x = seq_nat8_to_seq_uint8 s in let f = Lib.ByteSequence.nat_from_intseq_be_ #U8 #SEC in calc (==) { f x <: nat ; == { } FStar.UInt8.v (last x) + pow2 8 * f (slice x 0 3); == {} index s 3 + pow2 8 * f (slice x 0 3); == {} index s 3 + pow2 8 * index s 2 + pow2 16 * f (slice x 0 2); == {} index s 3 + pow2 8 * index s 2 + pow2 16 * index s 1 + pow2 24 * f (slice x 0 1); == {} index s 3 + pow2 8 * index s 2 + pow2 16 * index s 1 + pow2 24 * index s 0 + pow2 32 * f (slice x 0 0); == {} index s 3 + pow2 8 * index s 2 + pow2 16 * index s 1 + pow2 24 * index s 0; == {} four_to_nat_unfold 8 (seq_to_four_BE s); == {reveal_opaque (`%four_to_nat) four_to_nat} be_bytes_to_nat32 s; } let lemma_mod_transform (quads:seq quad32) : Lemma (requires length quads % 4 == 0) (ensures length (seq_nat8_to_seq_uint8 (le_seq_quad32_to_bytes quads)) % 64 == 0) = () let lemma_update_multi_opaque_vale_is_update_multi (hash:hash256) (blocks:bytes) : Lemma (requires length blocks % 64 = 0) (ensures update_multi_opaque_vale hash blocks == update_multi_transparent hash blocks) = update_multi_reveal (); () let sigma_0_0_partial_def (t:counter) (block:block_w) : nat32 = if 16 <= t && t < size_k_w_256 then (let sigma0_in = ws_opaque block (t-15) in sigma256_0_0 sigma0_in) else 0 #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30" let lemma_sha256_sigma0 (src:quad32) (t:counter) (block:block_w) : Lemma (requires 16 <= t /\ t < size_k_w(SHA2_256) /\ src.hi3 == ws_opaque block (t-15)) (ensures (sigma256_0_0 src.hi3 == sigma_0_0_partial t block)) = sigma_0_0_partial_reveal (); () #reset-options "--max_fuel 0 --max_ifuel 0" let sigma_0_1_partial_def (t:counter) (block:block_w) : nat32 = if 16 <= t && t < size_k_w_256 then (let sigma1_in = ws_opaque block (t-2) in sigma256_0_1 sigma1_in) else 0 #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30" let lemma_sha256_sigma1 (src:quad32) (t:counter) (block:block_w) : Lemma (requires 16 <= t /\ t < size_k_w(SHA2_256) /\ src.hi3 == ws_opaque block (t-2)) (ensures (sigma256_0_1 src.hi3 == sigma_0_1_partial t block)) = sigma_0_1_partial_reveal (); () #reset-options "--max_fuel 0 --max_ifuel 0" let sigma_1_0_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32 = if t < size_k_w_256 then (let sigma0_in = word_to_nat32 ((repeat_range_vale t block hash_orig).[0]) in sigma256_1_0 sigma0_in) else 0 #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30" let lemma_sha256_sigma2 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w(SHA2_256) /\ src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[0])) (ensures (sigma256_1_0 src.hi3 == sigma_1_0_partial t block hash_orig)) = sigma_1_0_partial_reveal (); () #reset-options "--max_fuel 0 --max_ifuel 0" let sigma_1_1_partial_def (t:counter) (block:block_w) (hash_orig:hash256) : nat32 = if t < size_k_w_256 then (let sigma1_in = word_to_nat32 ((repeat_range_vale t block hash_orig).[4]) in sigma256_1_1 sigma1_in) else 0 #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30" let lemma_sha256_sigma3 (src:quad32) (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w(SHA2_256) /\ src.hi3 == word_to_nat32 ((repeat_range_vale t block hash_orig).[4])) (ensures (sigma256_1_1 src.hi3 == sigma_1_1_partial t block hash_orig)) = sigma_1_1_partial_reveal (); () #reset-options "--max_fuel 0 --max_ifuel 0" let make_seperated_hash_def (a b c d e f g h:nat32) : (hash:words_state SHA2_256 { length hash == 8 /\ hash.[0] == to_uint32 a /\ hash.[1] == to_uint32 b /\ hash.[2] == to_uint32 c /\ hash.[3] == to_uint32 d /\ hash.[4] == to_uint32 e /\ hash.[5] == to_uint32 f /\ hash.[6] == to_uint32 g /\ hash.[7] == to_uint32 h }) = let a = to_uint32 a in let b = to_uint32 b in let c = to_uint32 c in let d = to_uint32 d in let e = to_uint32 e in let f = to_uint32 f in let g = to_uint32 g in let h = to_uint32 h in let l = [a; b; c; d; e; f; g; h] in assert_norm (List.length l == 8); let hash = seq_of_list l in assert (length hash == 8); elim_of_list l; hash [@"opaque_to_smt"] let make_seperated_hash = opaque_make make_seperated_hash_def irreducible let make_seperated_hash_reveal = opaque_revealer (`%make_seperated_hash) make_seperated_hash make_seperated_hash_def let make_seperated_hash_quad32_def (a b c d e f g h:quad32) : (hash:words_state SHA2_256 { length hash == 8 /\ hash.[0] == to_uint32 a.hi3 /\ hash.[1] == to_uint32 b.hi3 /\ hash.[2] == to_uint32 c.hi3 /\ hash.[3] == to_uint32 d.hi3 /\ hash.[4] == to_uint32 e.hi3 /\ hash.[5] == to_uint32 f.hi3 /\ hash.[6] == to_uint32 g.hi3 /\ hash.[7] == to_uint32 h.hi3 }) = let a = to_uint32 a.hi3 in let b = to_uint32 b.hi3 in let c = to_uint32 c.hi3 in let d = to_uint32 d.hi3 in let e = to_uint32 e.hi3 in let f = to_uint32 f.hi3 in let g = to_uint32 g.hi3 in let h = to_uint32 h.hi3 in let l = [a; b; c; d; e; f; g; h] in assert_norm (List.length l == 8); let hash = seq_of_list l in assert (length hash == 8); elim_of_list l; hash [@"opaque_to_smt"] let make_seperated_hash_quad32 = opaque_make make_seperated_hash_quad32_def irreducible let make_seperated_hash_quad32_reveal = opaque_revealer (`%make_seperated_hash_quad32) make_seperated_hash_quad32 make_seperated_hash_quad32_def let lemma_make_seperated_hash (hash:hash256) (a b c d e f g h:quad32) : Lemma (requires length hash == 8 /\ a.hi3 == word_to_nat32 hash.[0] /\ b.hi3 == word_to_nat32 hash.[1] /\ c.hi3 == word_to_nat32 hash.[2] /\ d.hi3 == word_to_nat32 hash.[3] /\ e.hi3 == word_to_nat32 hash.[4] /\ f.hi3 == word_to_nat32 hash.[5] /\ g.hi3 == word_to_nat32 hash.[6] /\ h.hi3 == word_to_nat32 hash.[7]) (ensures hash == make_seperated_hash_quad32 a b c d e f g h) = assert (equal hash (make_seperated_hash_quad32 a b c d e f g h)) let lemma_vsel32 (a b c:nat32) : Lemma (ensures (isel32 a b c = (iand32 c a) *^ (iand32 (inot32 c) b))) = reveal_iand_all 32; reveal_inot_all 32; reveal_ixor_all 32; lemma_equal_nth 32 (isel32 a b c) ((iand32 c a) *^ (iand32 (inot32 c) b)) let ch_256_def (x y z:nat32) : (a:nat32 {a == (iand32 x y) *^ (iand32 (inot32 x) z)}) = reveal_iand_all 32; reveal_inot_all 32; reveal_ixor_all 32; ch256 x y z [@"opaque_to_smt"] let ch_256 = opaque_make ch_256_def irreducible let ch_256_reveal = opaque_revealer (`%ch_256) ch_256 ch_256_def let lemma_eq_maj_xvsel32 (a b c:nat32) : Lemma (ensures (isel32 c b (a *^ b) = (iand32 a b) *^ ((iand32 a c) *^ (iand32 b c)))) = reveal_iand_all 32; reveal_ixor_all 32; lemma_equal_nth 32 (isel32 c b (a *^ b)) ((iand32 a b) *^ ((iand32 a c) *^ (iand32 b c))) let maj_256_def (x y z:nat32) : (a:nat32 {a == (iand32 x y) *^ ((iand32 x z) *^ (iand32 y z))}) = reveal_iand_all 32; reveal_ixor_all 32; maj256 x y z [@"opaque_to_smt"] let maj_256 = opaque_make maj_256_def irreducible let maj_256_reveal = opaque_revealer (`%maj_256) maj_256 maj_256_def let lemma_sigma_0_0_partial (t:counter) (block:block_w) : Lemma (requires 16 <= t /\ t < size_k_w(SHA2_256)) (ensures (sigma256_0_0 (ws_opaque block (t-15)) == sigma_0_0_partial t block)) = sigma_0_0_partial_reveal () let lemma_sigma_0_1_partial (t:counter) (block:block_w) : Lemma (requires 16 <= t /\ t < size_k_w(SHA2_256)) (ensures (sigma256_0_1 (ws_opaque block (t-2)) == sigma_0_1_partial t block)) = sigma_0_1_partial_reveal () let lemma_sigma_1_0_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w(SHA2_256)) (ensures (sigma256_1_0 (word_to_nat32 ((repeat_range_vale t block hash_orig).[0])) == sigma_1_0_partial t block hash_orig)) = sigma_1_0_partial_reveal () let lemma_sigma_1_1_partial (t:counter) (block:block_w) (hash_orig:hash256) : Lemma (requires t < size_k_w(SHA2_256)) (ensures (sigma256_1_1 (word_to_nat32 ((repeat_range_vale t block hash_orig).[4])) == sigma_1_1_partial t block hash_orig)) = sigma_1_1_partial_reveal () #reset-options "--z3rlimit 20 --max_fuel 1" let lemma_quads_to_block_be qs = reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #nat32); reveal_opaque (`%ws) ws #reset-options "--max_fuel 0 --max_ifuel 0"
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fst.checked", "Vale.SHA2.Wrapper.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Sel.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Spec.SHA2.Lemmas.fst.checked", "Spec.SHA2.Lemmas.fst.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Loops.fst.checked", "Spec.Hash.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA.PPC64LE.SHA_helpers.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt32 // Interop with UInt-based SHA spec", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "Spec.SHA2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Vale.SHA.PPC64LE.SHA_helpers.counter -> block: Vale.SHA.PPC64LE.SHA_helpers.block_w -> hash_orig: Vale.SHA.PPC64LE.SHA_helpers.hash256 -> FStar.Pervasives.Lemma (requires t < Vale.SHA.PPC64LE.SHA_helpers.size_k_w_256) (ensures (let hash = Spec.Loops.repeat_range 0 t (Vale.SHA.PPC64LE.SHA_helpers.shuffle_core_opaque block) hash_orig in let h = Spec.Loops.repeat_range 0 (t + 1) (Vale.SHA.PPC64LE.SHA_helpers.shuffle_core_opaque block) hash_orig in let a0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 0 ] in let b0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 1 ] in let c0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 2 ] in let d0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 3 ] in let e0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 4 ] in let f0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 5 ] in let g0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 6 ] in let h0 = Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 hash.[ 7 ] in let t1 = Vale.Def.Types_s.add_wrap (Vale.Def.Types_s.add_wrap (Vale.Def.Types_s.add_wrap (Vale.Def.Types_s.add_wrap h0 (Vale.SHA2.Wrapper.sigma256_1_1 e0)) (Vale.SHA.PPC64LE.SHA_helpers.ch_256 e0 f0 g0)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 Vale.SHA.PPC64LE.SHA_helpers.k.[ t ])) (Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block t) in let t2 = Vale.Def.Types_s.add_wrap (Vale.SHA2.Wrapper.sigma256_1_0 a0) (Vale.SHA.PPC64LE.SHA_helpers.maj_256 a0 b0 c0) in Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 0 ] == Vale.Def.Types_s.add_wrap t1 t2 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 1 ] == a0 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 2 ] == b0 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 3 ] == c0 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 4 ] == Vale.Def.Types_s.add_wrap d0 t1 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 5 ] == e0 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 6 ] == f0 /\ Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 h.[ 7 ] == g0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.SHA.PPC64LE.SHA_helpers.counter", "Vale.SHA.PPC64LE.SHA_helpers.block_w", "Vale.SHA.PPC64LE.SHA_helpers.hash256", "Vale.SHA.PPC64LE.SHA_helpers.shuffle_core_properties", "Spec.Loops.repeat_range", "Vale.SHA.PPC64LE.SHA_helpers.shuffle_core_opaque", "Prims.unit", "Spec.Loops.repeat_range_induction", "Prims.op_Addition", "Vale.SHA.PPC64LE.SHA_helpers.lemma_add_wrap_is_add_mod", "Vale.Def.Types_s.add_wrap", "Vale.Def.Words_s.pow2_32", "Vale.SHA2.Wrapper.sigma256_1_1", "Vale.SHA.PPC64LE.SHA_helpers.ch_256", "Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32", "Spec.SHA2.op_String_Access", "Vale.SHA.PPC64LE.SHA_helpers.word", "Vale.SHA.PPC64LE.SHA_helpers.k", "Vale.SHA.PPC64LE.SHA_helpers.ws_opaque", "Vale.SHA2.Wrapper.sigma256_1_0", "Vale.SHA.PPC64LE.SHA_helpers.maj_256", "Vale.SHA.PPC64LE.SHA_helpers.maj_256_reveal", "Vale.SHA.PPC64LE.SHA_helpers.ch_256_reveal", "Vale.Def.Words_s.nat32", "FStar.Seq.Base.seq", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.op_LessThan", "Vale.SHA.PPC64LE.SHA_helpers.size_k_w_256", "Prims.squash", "Prims.l_and", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_shuffle_core_properties (t: counter) (block: block_w) (hash_orig: hash256) : Lemma (requires t < size_k_w_256) (ensures (let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let h = Spec.Loops.repeat_range 0 (t + 1) (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[ 0 ] in let b0 = word_to_nat32 hash.[ 1 ] in let c0 = word_to_nat32 hash.[ 2 ] in let d0 = word_to_nat32 hash.[ 3 ] in let e0 = word_to_nat32 hash.[ 4 ] in let f0 = word_to_nat32 hash.[ 5 ] in let g0 = word_to_nat32 hash.[ 6 ] in let h0 = word_to_nat32 hash.[ 7 ] in 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 let t2 = add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0) in word_to_nat32 h.[ 0 ] == add_wrap t1 t2 /\ word_to_nat32 h.[ 1 ] == a0 /\ word_to_nat32 h.[ 2 ] == b0 /\ word_to_nat32 h.[ 3 ] == c0 /\ word_to_nat32 h.[ 4 ] == add_wrap d0 t1 /\ word_to_nat32 h.[ 5 ] == e0 /\ word_to_nat32 h.[ 6 ] == f0 /\ word_to_nat32 h.[ 7 ] == g0)) =
let hash = Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig in let a0 = word_to_nat32 hash.[ 0 ] in let b0 = word_to_nat32 hash.[ 1 ] in let c0 = word_to_nat32 hash.[ 2 ] in let d0 = word_to_nat32 hash.[ 3 ] in let e0 = word_to_nat32 hash.[ 4 ] in let f0 = word_to_nat32 hash.[ 5 ] in let g0 = word_to_nat32 hash.[ 6 ] in let h0 = word_to_nat32 hash.[ 7 ] in ch_256_reveal (); maj_256_reveal (); lemma_add_wrap_is_add_mod h0 (sigma256_1_1 e0); lemma_add_wrap_is_add_mod (add_wrap h0 (sigma256_1_1 e0)) (ch_256 e0 f0 g0); lemma_add_wrap_is_add_mod (add_wrap (add_wrap h0 (sigma256_1_1 e0)) (ch_256 e0 f0 g0)) (word_to_nat32 k.[ t ]); lemma_add_wrap_is_add_mod (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); lemma_add_wrap_is_add_mod (sigma256_1_0 a0) (maj_256 a0 b0 c0); lemma_add_wrap_is_add_mod (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)) (add_wrap (sigma256_1_0 a0) (maj_256 a0 b0 c0)); lemma_add_wrap_is_add_mod d0 (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)); Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_orig; shuffle_core_properties block (Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_orig) t
false
Pulse.Lib.GhostWitness.fst
Pulse.Lib.GhostWitness.sqeq
val sqeq: p: Type -> squash p -> erased p
val sqeq: p: Type -> squash p -> erased p
let sqeq (p : Type) (_ : squash p) : erased p = FStar.IndefiniteDescription.elim_squash #p ()
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.GhostWitness.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 6, "start_col": 0, "start_line": 5 }
module Pulse.Lib.GhostWitness open Pulse.Lib.Pervasives
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.GhostWitness.fst" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type -> _: Prims.squash p -> FStar.Ghost.erased p
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "FStar.Ghost.hide", "FStar.IndefiniteDescription.elim_squash", "FStar.Ghost.erased" ]
[]
false
false
false
true
false
let sqeq (p: Type) (_: squash p) : erased p =
FStar.IndefiniteDescription.elim_squash #p ()
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x_is_one_lemma
val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
let normalize5_second_part_x_is_one_lemma x r = LD.lemma_as_nat_bound_f4_lt_pow12 r; assert (as_nat5 r <= pow2 220 - 1); assert_norm (pow2 220 - 1 < S.prime); let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (v is_ge_p_m = 0); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_commutative #64 (v m_to_one) (v x); FStar.UInt.logor_lemma_1 #64 (v x); assert (v x1 = 1); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in Math.Lemmas.pow2_double_sum 12; assert (v s4 < pow2 13); let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 s); assert (as_nat5 k < pow2 220 + pow2 256 - S.prime); assert_norm (pow2 220 + pow2 256 - S.prime < S.prime)
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 294, "start_col": 0, "start_line": 259 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4) noextract let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4) val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12)))) let normalize5_first_part_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let t = normalize_weak5 f in let (t0,t1,t2,t3,t4) = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - v f4 / pow2 48 * S.prime); assert (felem_fits5 t (1,1,1,1,2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let (r0,r1,r2,r3,r4) = r in minus_x_mul_pow2_256_lemma (1,1,1,1,2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); assert (felem_fits5 r (1,1,1,1,1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12) val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> r: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 1) /\ Lib.IntTypes.v x = 1 /\ Lib.IntTypes.v r4 < Prims.pow2 12) <: Type0)) (ensures (let k = Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x x r in Hacl.Spec.K256.Field52.Definitions.as_nat5 k == Hacl.Spec.K256.Field52.Definitions.as_nat5 r + Lib.IntTypes.v x * Prims.pow2 256 - Spec.K256.PointOps.prime /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 k (1, 1, 1, 1, 1) /\ Hacl.Spec.K256.Field52.Definitions.as_nat5 k < Spec.K256.PointOps.prime))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.uint64", "Hacl.Spec.K256.Field52.Definitions.felem5", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "Prims.op_Addition", "Prims.pow2", "Spec.K256.PointOps.prime", "Prims.unit", "Prims._assert", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.op_Equality", "Prims.nat", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_div_pow48", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Field52.Definitions.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.Lemmas2.minus_x_mul_pow2_256_lemma", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256", "FStar.Math.Lemmas.pow2_double_sum", "Hacl.Spec.K256.Field52.Lemmas2.plus_x_mul_pow2_256_minus_prime_lemma", "Hacl.Spec.K256.Field52.plus_x_mul_pow2_256_minus_prime", "FStar.UInt.logor_lemma_1", "FStar.UInt.logor_commutative", "Lib.IntTypes.logor_spec", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.u64", "Lib.IntTypes.op_Amp_Dot", "Hacl.Spec.K256.Field52.Lemmas2.is_felem_ge_prime5_lemma", "Hacl.Spec.K256.Field52.is_felem_ge_prime5", "Prims.op_LessThanOrEqual", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_as_nat_bound_f4_lt_pow12" ]
[]
false
false
true
false
false
let normalize5_second_part_x_is_one_lemma x r =
LD.lemma_as_nat_bound_f4_lt_pow12 r; assert (as_nat5 r <= pow2 220 - 1); assert_norm (pow2 220 - 1 < S.prime); let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (v is_ge_p_m = 0); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (v m_to_one = 0); let x1 = m_to_one |. x in logor_spec m_to_one x; FStar.UInt.logor_commutative #64 (v m_to_one) (v x); FStar.UInt.logor_lemma_1 #64 (v x); assert (v x1 = 1); let s = plus_x_mul_pow2_256_minus_prime x1 r in plus_x_mul_pow2_256_minus_prime_lemma (1, 1, 1, 1, 1) x1 r; assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); let s0, s1, s2, s3, s4 = s in Math.Lemmas.pow2_double_sum 12; assert (v s4 < pow2 13); let x2, k = minus_x_mul_pow2_256 s in minus_x_mul_pow2_256_lemma (1, 1, 1, 1, 2) s; assert (felem_fits5 k (1, 1, 1, 1, 1)); assert (as_nat5 k = as_nat5 s - (v s4 / pow2 48) * pow2 256); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 s); assert (as_nat5 k < pow2 220 + pow2 256 - S.prime); assert_norm (pow2 220 + pow2 256 - S.prime < S.prime)
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x_is_zero_lemma
val normalize5_second_part_x_is_zero_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 0)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == (if as_nat5 r < S.prime then as_nat5 r else as_nat5 r - S.prime) /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
val normalize5_second_part_x_is_zero_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 0)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == (if as_nat5 r < S.prime then as_nat5 r else as_nat5 r - S.prime) /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
let normalize5_second_part_x_is_zero_lemma x r = let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (if v is_ge_p_m = ones_v U64 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (if v is_ge_p_m = ones_v U64 then v m_to_one = 1 else v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_lemma_1 #64 (v m_to_one); assert (v x1 = v m_to_one); assert (if v x1 = 1 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x1 * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + v x1 * (pow2 256 - S.prime)); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); if v x1 = 0 then begin assert (as_nat5 s = as_nat5 r); LD.as_nat_inj s r; assert (felem_fits_last1 s4 1); Math.Lemmas.small_div (v s4) (pow2 48); assert (as_nat5 k = as_nat5 r) end else begin assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); assert (as_nat5 s >= pow2 256); assert (v s4 >= pow2 48); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 r - S.prime) end
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 342, "start_col": 0, "start_line": 304 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4) noextract let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4) val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12)))) let normalize5_first_part_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let t = normalize_weak5 f in let (t0,t1,t2,t3,t4) = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - v f4 / pow2 48 * S.prime); assert (felem_fits5 t (1,1,1,1,2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let (r0,r1,r2,r3,r4) = r in minus_x_mul_pow2_256_lemma (1,1,1,1,2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); assert (felem_fits5 r (1,1,1,1,1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12) val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime)) let normalize5_second_part_x_is_one_lemma x r = LD.lemma_as_nat_bound_f4_lt_pow12 r; assert (as_nat5 r <= pow2 220 - 1); assert_norm (pow2 220 - 1 < S.prime); let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (v is_ge_p_m = 0); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_commutative #64 (v m_to_one) (v x); FStar.UInt.logor_lemma_1 #64 (v x); assert (v x1 = 1); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in Math.Lemmas.pow2_double_sum 12; assert (v s4 < pow2 13); let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 s); assert (as_nat5 k < pow2 220 + pow2 256 - S.prime); assert_norm (pow2 220 + pow2 256 - S.prime < S.prime) val normalize5_second_part_x_is_zero_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 0)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == (if as_nat5 r < S.prime then as_nat5 r else as_nat5 r - S.prime) /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> r: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ _ = _ in Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 1) /\ Lib.IntTypes.v x = 0 ) <: Type0)) (ensures (let k = Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x x r in Hacl.Spec.K256.Field52.Definitions.as_nat5 k == (match Hacl.Spec.K256.Field52.Definitions.as_nat5 r < Spec.K256.PointOps.prime with | true -> Hacl.Spec.K256.Field52.Definitions.as_nat5 r | _ -> Hacl.Spec.K256.Field52.Definitions.as_nat5 r - Spec.K256.PointOps.prime) /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 k (1, 1, 1, 1, 1) /\ Hacl.Spec.K256.Field52.Definitions.as_nat5 k < Spec.K256.PointOps.prime))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.uint64", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims._assert", "Prims.b2t", "Prims.nat", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.unit", "FStar.Math.Lemmas.small_div", "Prims.pow2", "Hacl.Spec.K256.Field52.Definitions.felem_fits_last1", "Hacl.Spec.K256.Field52.Definitions.Lemmas.as_nat_inj", "Prims.bool", "Prims.op_Subtraction", "Spec.K256.PointOps.prime", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_div_pow48", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Division", "Hacl.Spec.K256.Field52.Definitions.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.Lemmas2.minus_x_mul_pow2_256_lemma", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.K256.Field52.minus_x_mul_pow2_256", "Hacl.Spec.K256.Field52.Lemmas2.plus_x_mul_pow2_256_minus_prime_lemma", "Hacl.Spec.K256.Field52.plus_x_mul_pow2_256_minus_prime", "Prims.op_LessThan", "Lib.IntTypes.range_t", "FStar.UInt.logor_lemma_1", "Lib.IntTypes.logor_spec", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.ones_v", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.u64", "Lib.IntTypes.op_Amp_Dot", "Hacl.Spec.K256.Field52.Lemmas2.is_felem_ge_prime5_lemma", "Hacl.Spec.K256.Field52.is_felem_ge_prime5" ]
[]
false
false
true
false
false
let normalize5_second_part_x_is_zero_lemma x r =
let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (if v is_ge_p_m = ones_v U64 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (if v is_ge_p_m = ones_v U64 then v m_to_one = 1 else v m_to_one = 0); let x1 = m_to_one |. x in logor_spec m_to_one x; FStar.UInt.logor_lemma_1 #64 (v m_to_one); assert (v x1 = v m_to_one); assert (if v x1 = 1 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let s = plus_x_mul_pow2_256_minus_prime x1 r in plus_x_mul_pow2_256_minus_prime_lemma (1, 1, 1, 1, 1) x1 r; assert (as_nat5 s = as_nat5 r + v x1 * (pow2 256 - S.prime)); let s0, s1, s2, s3, s4 = s in let x2, k = minus_x_mul_pow2_256 s in minus_x_mul_pow2_256_lemma (1, 1, 1, 1, 2) s; assert (felem_fits5 k (1, 1, 1, 1, 1)); assert (as_nat5 k = as_nat5 s - (v s4 / pow2 48) * pow2 256); if v x1 = 0 then (assert (as_nat5 s = as_nat5 r); LD.as_nat_inj s r; assert (felem_fits_last1 s4 1); Math.Lemmas.small_div (v s4) (pow2 48); assert (as_nat5 k = as_nat5 r)) else (assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); assert (as_nat5 s >= pow2 256); assert (v s4 >= pow2 48); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 r - S.prime))
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.normalize5_lemma
val normalize5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize5 f in as_nat5 r == as_nat5 f % S.prime /\ felem_fits5 r (1,1,1,1,1)))
val normalize5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize5 f in as_nat5 r == as_nat5 f % S.prime /\ felem_fits5 r (1,1,1,1,1)))
let normalize5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let x, r = normalize5_first_part f in let k = normalize5_second_part_x x r in let (r0,r1,r2,r3,r4) = r in normalize5_first_part_lemma m f; assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); if v x = 1 then begin normalize5_second_part_x_is_one_lemma x r; lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 1 S.prime end else begin normalize5_second_part_x_is_zero_lemma x r; if as_nat5 r < S.prime then lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 0 S.prime else lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 1 S.prime end
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 84, "end_line": 382, "start_col": 0, "start_line": 364 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1))) let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48 val carry_round_after_last_carry_mod_prime5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f (m0,m1,m2,m3,1))) (ensures (let r = carry_round5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let carry_round_after_last_carry_mod_prime5_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in //(m0,m1,m2,m3,1) let t1' = t1 +. (t0 >>. 52ul) in let t0' = t0 &. mask52 in LD.lemma_carry52 m1 m0 t1 t0; assert (felem_fits1 t1' (m1 + 1)); assert (felem_fits1 t0' 1); assert (v t0' = v t0 % pow2 52); assert (v t1' = v t1 + v t0 / pow2 52); let t2' = t2 +. (t1' >>. 52ul) in let t1'' = t1' &. mask52 in LD.lemma_carry52 m2 (m1 + 1) t2 t1'; assert (felem_fits1 t2' (m2 + 1)); assert (felem_fits1 t1'' 1); assert (v t1'' = v t1' % pow2 52); assert (v t2' = v t2 + v t1' / pow2 52); let t3' = t3 +. (t2' >>. 52ul) in let t2'' = t2' &. mask52 in LD.lemma_carry52 m3 (m2 + 1) t3 t2'; assert (felem_fits1 t3' (m3 + 1)); assert (felem_fits1 t2'' 1); assert (v t2'' = v t2' % pow2 52); assert (v t3' = v t3 + v t2' / pow2 52); let t4' = t4 +. (t3' >>. 52ul) in let t3'' = t3' &. mask52 in LD.lemma_carry_last52 m4 (m3 + 1) t4 t3'; assert (felem_fits_last1 t4' (m4 + 1)); assert (felem_fits1 t3'' 1); assert (v t3'' = v t3' % pow2 52); assert (v t4' = v t4 + v t3' / pow2 52); LD.carry_last_small_mod_lemma t4 t3'; ML.lemma_simplify_carry_round (v t0) (v t1) (v t2) (v t3) (v t4); let r = carry_round5 f in assert ((t0',t1'',t2'',t3'',t4') == r); assert (as_nat5 r == as_nat5 f) val plus_x_mul_pow2_256_minus_prime_lemma: m:scale64_5 -> x:uint64 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ m4 = 1 /\ felem_fits5 f m /\ v x < pow2 16)) (ensures (let r = plus_x_mul_pow2_256_minus_prime x f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime) /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let plus_x_mul_pow2_256_minus_prime_lemma m x f = let (t0,t1,t2,t3,t4) = f in let (m0,m1,m2,m3,m4) = m in let t0' = t0 +. x *. u64 0x1000003D1 in assert (v x < pow2 16); Math.Lemmas.lemma_mult_lt_right 0x1000003D1 (v x) (pow2 16); assert_norm (pow2 16 * 0x1000003D1 < max52); assert (v t0 + v x * 0x1000003D1 < (m0 + 1) * max52); Math.Lemmas.lemma_mult_le_right max52 (m0 + 1) 4096; assert_norm (4096 * max52 < pow2 64); Math.Lemmas.small_mod (v t0 + v x * 0x1000003D1) (pow2 64); assert (v t0' = v t0 + v x * 0x1000003D1); assert (felem_fits1 t0' (m0 + 1)); let r = carry_round5 (t0',t1,t2,t3,t4) in carry_round_after_last_carry_mod_prime5_lemma (m0+1,m1,m2,m3,m4) (t0',t1,t2,t3,t4); assert (as_nat5 r == as_nat5 (t0',t1,t2,t3,t4)); LD.lemma_pow2_256_minus_prime (); assert (as_nat5 r == as_nat5 f + v x * (pow2 256 - S.prime)) val normalize_weak5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize_weak5 f in let (r0,r1,r2,r3,r4) = r in let (t0,t1,t2,t3,t4) = f in as_nat5 r == as_nat5 f - v t4 / pow2 48 * S.prime /\ felem_fits5 r (1,1,1,1,2) /\ v r4 < v t4 + pow2 12 /\ (v r4 >= pow2 48 ==> v r4 % pow2 48 < pow2 12))) let normalize_weak5_lemma m f = let (m0,m1,m2,m3,m4) = m in let x, f1 = minus_x_mul_pow2_256 f in minus_x_mul_pow2_256_lemma m f; assert (as_nat5 f1 == as_nat5 f - v x * pow2 256); assert (felem_fits5 f1 (m0,m1,m2,m3,1)); let f2 = plus_x_mul_pow2_256_minus_prime x f1 in plus_x_mul_pow2_256_minus_prime_lemma (m0,m1,m2,m3,1) x f1; assert (as_nat5 f2 == as_nat5 f1 + v x * (pow2 256 - S.prime)); assert (felem_fits5 f2 (1,1,1,1,2)); assert (f2 == normalize_weak5 f); Math.Lemmas.distributivity_sub_right (v x) (pow2 256) S.prime; assert (as_nat5 f2 == as_nat5 f - v x * S.prime) /// Normalize #push-options "--ifuel 1" val is_felem_ge_prime5_lemma: f:felem5 -> Lemma (requires felem_fits5 f (1,1,1,1,1)) (ensures (let is_m = is_felem_ge_prime5 f in (v is_m = 0 \/ v is_m = ones_v U64) /\ (if v is_m = ones_v U64 then (as_nat5 f >= S.prime) else (as_nat5 f < S.prime)))) let is_felem_ge_prime5_lemma f = () #pop-options // let (f0,f1,f2,f3,f4) = f in // let m4 = eq_mask f4 mask48 in // eq_mask_lemma f4 mask48; // assert (if v f4 = v mask48 then v m4 = ones_v U64 else v m4 = 0); // let m3 = eq_mask f3 mask52 in // eq_mask_lemma f3 mask52; // assert (if v f3 = v mask52 then v m3 = ones_v U64 else v m3 = 0); // let m2 = eq_mask f2 mask52 in // eq_mask_lemma f2 mask52; // assert (if v f2 = v mask52 then v m2 = ones_v U64 else v m2 = 0); // let m1 = eq_mask f1 mask52 in // eq_mask_lemma f1 mask52; // assert (if v f1 = v mask52 then v m1 = ones_v U64 else v m1 = 0); // let m0 = gte_mask f0 (u64 0xffffefffffc2f) in // gte_mask_lemma f0 (u64 0xffffefffffc2f); // assert (if v f0 >= 0xffffefffffc2f then v m0 = ones_v U64 else v m0 = 0); // let m = m0 &. m1 &. m2 &. m3 &. m4 in () // if v m4 = 0 then // logand_zeros (m0 &. m1 &. m2 &. m3) // else begin // logand_ones (m0 &. m1 &. m2 &. m3) end noextract let normalize5_first_part (f0,f1,f2,f3,f4) = let (t0,t1,t2,t3,t4) = normalize_weak5 (f0,f1,f2,f3,f4) in let x, (r0,r1,r2,r3,r4) = minus_x_mul_pow2_256 (t0,t1,t2,t3,t4) in x, (r0,r1,r2,r3,r4) noextract let normalize5_second_part_x (x:uint64) (r0,r1,r2,r3,r4) : felem5 = let is_ge_p_m = is_felem_ge_prime5 (r0,r1,r2,r3,r4) in // as_nat r >= S.prime let m_to_one = is_ge_p_m &. u64 1 in let x1 = m_to_one |. x in let (s0,s1,s2,s3,s4) = plus_x_mul_pow2_256_minus_prime x1 (r0,r1,r2,r3,r4) in let x2, (k0,k1,k2,k3,k4) = minus_x_mul_pow2_256 (s0,s1,s2,s3,s4) in (k0,k1,k2,k3,k4) val normalize5_first_part_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let x, r = normalize5_first_part f in let (f0,f1,f2,f3,f4) = f in let (r0,r1,r2,r3,r4) = r in as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256 /\ felem_fits5 r (1,1,1,1,1) /\ (v x = 0 \/ (v x = 1 /\ v r4 < pow2 12)))) let normalize5_first_part_lemma m f = let (m0,m1,m2,m3,m4) = m in let (f0,f1,f2,f3,f4) = f in let t = normalize_weak5 f in let (t0,t1,t2,t3,t4) = t in normalize_weak5_lemma m f; assert (as_nat5 t == as_nat5 f - v f4 / pow2 48 * S.prime); assert (felem_fits5 t (1,1,1,1,2)); assert ((v t4 >= pow2 48 ==> v t4 % pow2 48 < pow2 12)); let x, r = minus_x_mul_pow2_256 t in let (r0,r1,r2,r3,r4) = r in minus_x_mul_pow2_256_lemma (1,1,1,1,2) t; assert (as_nat5 r == as_nat5 t - v x * pow2 256); assert (as_nat5 r == as_nat5 f - v f4 / pow2 48 * S.prime - v x * pow2 256); assert (felem_fits5 r (1,1,1,1,1)); assert (v r4 = v t4 % pow2 48 /\ v x = v t4 / pow2 48); LD.lemma_div_pow48 t4; assert (if v t4 < pow2 48 then v x = 0 else v x = 1 /\ v r4 < pow2 12) val normalize5_second_part_x_is_one_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 1 /\ v r4 < pow2 12)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == as_nat5 r + v x * pow2 256 - S.prime /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime)) let normalize5_second_part_x_is_one_lemma x r = LD.lemma_as_nat_bound_f4_lt_pow12 r; assert (as_nat5 r <= pow2 220 - 1); assert_norm (pow2 220 - 1 < S.prime); let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (v is_ge_p_m = 0); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_commutative #64 (v m_to_one) (v x); FStar.UInt.logor_lemma_1 #64 (v x); assert (v x1 = 1); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in Math.Lemmas.pow2_double_sum 12; assert (v s4 < pow2 13); let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 s); assert (as_nat5 k < pow2 220 + pow2 256 - S.prime); assert_norm (pow2 220 + pow2 256 - S.prime < S.prime) val normalize5_second_part_x_is_zero_lemma: x:uint64 -> r:felem5 -> Lemma (requires (let (r0,r1,r2,r3,r4) = r in felem_fits5 r (1,1,1,1,1) /\ v x = 0)) (ensures (let k = normalize5_second_part_x x r in as_nat5 k == (if as_nat5 r < S.prime then as_nat5 r else as_nat5 r - S.prime) /\ felem_fits5 k (1,1,1,1,1) /\ as_nat5 k < S.prime)) let normalize5_second_part_x_is_zero_lemma x r = let is_ge_p_m = is_felem_ge_prime5 r in is_felem_ge_prime5_lemma r; assert (if v is_ge_p_m = ones_v U64 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let m_to_one = is_ge_p_m &. u64 1 in logand_lemma is_ge_p_m (u64 1); assert (if v is_ge_p_m = ones_v U64 then v m_to_one = 1 else v m_to_one = 0); let x1 = m_to_one |. x in //1 logor_spec m_to_one x; FStar.UInt.logor_lemma_1 #64 (v m_to_one); assert (v x1 = v m_to_one); assert (if v x1 = 1 then (as_nat5 r >= S.prime) else as_nat5 r < S.prime); let s = plus_x_mul_pow2_256_minus_prime x1 r in // + x1 * (pow2 256 - S.prime) plus_x_mul_pow2_256_minus_prime_lemma (1,1,1,1,1) x1 r; assert (as_nat5 s = as_nat5 r + v x1 * (pow2 256 - S.prime)); //(v s4 >= pow2 48 ==> v s4 % pow2 48 < pow2 12) let (s0,s1,s2,s3,s4) = s in let x2, k = minus_x_mul_pow2_256 s in // - s4 / pow2 48 * pow2 256 minus_x_mul_pow2_256_lemma (1,1,1,1,2) s; assert (felem_fits5 k (1,1,1,1,1)); assert (as_nat5 k = as_nat5 s - v s4 / pow2 48 * pow2 256); if v x1 = 0 then begin assert (as_nat5 s = as_nat5 r); LD.as_nat_inj s r; assert (felem_fits_last1 s4 1); Math.Lemmas.small_div (v s4) (pow2 48); assert (as_nat5 k = as_nat5 r) end else begin assert (as_nat5 s = as_nat5 r + pow2 256 - S.prime); assert (as_nat5 s >= pow2 256); assert (v s4 >= pow2 48); LD.lemma_div_pow48 s4; assert (as_nat5 k = as_nat5 r - S.prime) end val lemma_a_minus_b_n_c_n_k (k a b c:nat) (n:pos) : Lemma (requires k < n /\ k == a - b * n - c * n) (ensures k == a % n) let lemma_a_minus_b_n_c_n_k k a b c n = Math.Lemmas.lemma_mod_sub (a - b * n) n c; Math.Lemmas.lemma_mod_sub a n b; Math.Lemmas.small_mod k n val normalize5_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires (let (m0,m1,m2,m3,m4) = m in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ felem_fits5 f m)) (ensures (let r = normalize5 f in as_nat5 r == as_nat5 f % S.prime /\ felem_fits5 r (1,1,1,1,1)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires (let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 _ = _ in m0 + 1 <= 4096 /\ m1 + 1 <= 4096 /\ m2 + 1 <= 4096 /\ m3 + 1 <= 4096 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 f m) <: Type0)) (ensures (let r = Hacl.Spec.K256.Field52.normalize5 f in Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f % Spec.K256.PointOps.prime /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (1, 1, 1, 1, 1)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.tuple5", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Field52.Lemmas2.lemma_a_minus_b_n_c_n_k", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.op_Division", "Prims.pow2", "Spec.K256.PointOps.prime", "Prims.unit", "Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x_is_one_lemma", "Prims.bool", "Prims.op_LessThan", "Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x_is_zero_lemma", "Prims._assert", "Prims.eq2", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Hacl.Spec.K256.Field52.Lemmas2.normalize5_first_part_lemma", "Lib.IntTypes.int_t", "Hacl.Spec.K256.Field52.Lemmas2.normalize5_second_part_x", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.K256.Field52.Lemmas2.normalize5_first_part" ]
[]
false
false
true
false
false
let normalize5_lemma m f =
let m0, m1, m2, m3, m4 = m in let f0, f1, f2, f3, f4 = f in let x, r = normalize5_first_part f in let k = normalize5_second_part_x x r in let r0, r1, r2, r3, r4 = r in normalize5_first_part_lemma m f; assert (as_nat5 r == as_nat5 f - (v f4 / pow2 48) * S.prime - v x * pow2 256); if v x = 1 then (normalize5_second_part_x_is_one_lemma x r; lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 1 S.prime) else (normalize5_second_part_x_is_zero_lemma x r; if as_nat5 r < S.prime then lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 0 S.prime else lemma_a_minus_b_n_c_n_k (as_nat5 k) (as_nat5 f) (v f4 / pow2 48) 1 S.prime)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_freeable
val optional_freeable : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Type0
let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 61, "start_col": 0, "start_line": 51 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.optional_key", "Prims.l_True", "Hacl.Streaming.Interface.__proj__Stateful__item__freeable", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
true
let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) =
allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_footprint
val optional_footprint : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Prims.GTot LowStar.Monotonic.Buffer.loc
let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 85, "start_col": 0, "start_line": 75 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.optional_key", "LowStar.Monotonic.Buffer.loc_none", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "LowStar.Monotonic.Buffer.loc", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
false
let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) =
allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_invariant
val optional_invariant : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Type0
let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 73, "start_col": 0, "start_line": 63 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.optional_key", "Prims.l_True", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
true
let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) =
allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_reveal
val optional_reveal : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Prims.GTot (Stateful?.t key i)
let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 97, "start_col": 0, "start_line": 87 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Streaming.Interface.optional_key i km key -> Prims.GTot (Stateful?.t key i)
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.optional_key", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
false
let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) =
allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_hide
val optional_hide (#index: _) (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i) : optional_key i km key
val optional_hide (#index: _) (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i) : optional_key i km key
let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 110, "start_col": 0, "start_line": 99 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: Stateful?.s key i -> Hacl.Streaming.Interface.optional_key i km key
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Hacl.Streaming.Interface.optional_key", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
false
false
false
false
false
let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i) : optional_key i km key =
allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.footprint_s
val footprint_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): GTot B.loc
val footprint_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): GTot B.loc
let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key)
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 112, "end_line": 169, "start_col": 0, "start_line": 167 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state_s' c i -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state_s'", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "Hacl.Streaming.Functor.optional_footprint", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let footprint_s #index (c: block index) (i: index) (h: HS.mem) s =
let State block_state buf_ _ _ p_key = s in let open B in ((loc_addr_of_buffer buf_) `loc_union` (c.state.footprint h block_state)) `loc_union` (optional_footprint h p_key)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.stateful_frame_preserves_freeable
val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s))
val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s))
let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in ()
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 140, "start_col": 0, "start_line": 126 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: LowStar.Monotonic.Buffer.loc -> s: Stateful?.s sc i -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Stateful?.invariant sc h0 s /\ LowStar.Monotonic.Buffer.loc_disjoint l (Stateful?.footprint sc h0 s) /\ LowStar.Monotonic.Buffer.modifies l h0 h1) (ensures Stateful?.freeable sc h0 s ==> Stateful?.freeable sc h1 s)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.stateful", "LowStar.Monotonic.Buffer.loc", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "FStar.Monotonic.HyperStack.mem", "Prims.unit", "Prims.l_and", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "LowStar.Monotonic.Buffer.modifies", "Hacl.Streaming.Interface.__proj__Stateful__item__freeable", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_freeable" ]
[]
false
false
true
false
false
let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 =
let lem h0 h1 : Lemma (requires (sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures (sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in ()
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.freeable_s
val freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i) : Type0
val freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i) : Type0
let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 206, "start_col": 0, "start_line": 204 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state_s' c i -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state_s'", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Prims.l_and", "LowStar.Monotonic.Buffer.freeable", "Hacl.Streaming.Interface.__proj__Stateful__item__freeable", "Hacl.Streaming.Functor.optional_freeable" ]
[]
false
false
false
false
true
let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i) : Type0 =
let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.seen
val seen: #index:Type0 -> c:block index -> i:index -> h:HS.mem -> s:state' c i -> GTot bytes
val seen: #index:Type0 -> c:block index -> i:index -> h:HS.mem -> s:state' c i -> GTot bytes
let seen #index c i h s = G.reveal (State?.seen (B.deref h s))
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 222, "start_col": 0, "start_line": 221 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "FStar.Ghost.reveal", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Functor.__proj__State__item__seen", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "LowStar.Monotonic.Buffer.deref", "Hacl.Streaming.Functor.state_s", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Functor.bytes" ]
[]
false
false
false
false
false
let seen #index c i h s =
G.reveal (State?.seen (B.deref h s))
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.optional_frame
val optional_frame (#index: _) (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem) : Lemma (requires (optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1 )) (ensures (optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s)))
val optional_frame (#index: _) (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem) : Lemma (requires (optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1 )) (ensures (optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s)))
let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 165, "start_col": 0, "start_line": 142 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: LowStar.Monotonic.Buffer.loc -> s: Hacl.Streaming.Interface.optional_key i km key -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Hacl.Streaming.Functor.optional_invariant h0 s /\ LowStar.Monotonic.Buffer.loc_disjoint l (Hacl.Streaming.Functor.optional_footprint h0 s) /\ LowStar.Monotonic.Buffer.modifies l h0 h1) (ensures Hacl.Streaming.Functor.optional_invariant h1 s /\ Hacl.Streaming.Functor.optional_reveal h0 s == Hacl.Streaming.Functor.optional_reveal h1 s /\ Hacl.Streaming.Functor.optional_footprint h1 s == Hacl.Streaming.Functor.optional_footprint h0 s /\ (Hacl.Streaming.Functor.optional_freeable h0 s ==> Hacl.Streaming.Functor.optional_freeable h1 s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.stateful", "LowStar.Monotonic.Buffer.loc", "Hacl.Streaming.Interface.optional_key", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.stateful_frame_preserves_freeable", "Prims.unit", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_invariant", "FStar.Pervasives.allow_inversion", "Prims.l_and", "Hacl.Streaming.Functor.optional_invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Streaming.Functor.optional_footprint", "LowStar.Monotonic.Buffer.modifies", "Prims.squash", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Functor.optional_reveal", "Prims.l_imp", "Hacl.Streaming.Functor.optional_freeable", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0: HS.mem) (h1: HS.mem) : Lemma (requires (optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1 )) (ensures (optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) =
allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.all_seen
val all_seen (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes
val all_seen (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes
let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s)
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 234, "start_col": 0, "start_line": 233 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "FStar.Seq.Base.append", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Functor.init_input", "Hacl.Streaming.Functor.seen", "Hacl.Streaming.Functor.bytes" ]
[]
false
false
false
false
false
let all_seen (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes =
S.append (init_input c i h s) (seen c i h s)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.reveal_key
val reveal_key: #index:Type0 -> c:block index -> i:index -> h:HS.mem -> s:state' c i -> GTot (c.key.I.t i)
val reveal_key: #index:Type0 -> c:block index -> i:index -> h:HS.mem -> s:state' c i -> GTot (c.key.I.t i)
let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s))
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 228, "start_col": 0, "start_line": 227 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot (Stateful?.t (Block?.key c) i)
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Functor.optional_reveal", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.__proj__State__item__p_key", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Hacl.Streaming.Interface.optional_key", "LowStar.Monotonic.Buffer.deref", "Hacl.Streaming.Functor.state_s", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Stateful__item__t" ]
[]
false
false
false
false
false
let reveal_key #index c i h s =
optional_reveal h (State?.p_key (B.deref h s))
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.init_input
val init_input (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes
val init_input (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes
let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s)
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 231, "start_col": 0, "start_line": 230 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Interface.__proj__Block__item__init_input_s", "Hacl.Streaming.Functor.reveal_key", "Hacl.Streaming.Functor.bytes" ]
[]
false
false
false
false
false
let init_input (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : GTot bytes =
c.init_input_s i (reveal_key c i h s)
false
LList.fst
LList.push
val push (#a:Type) (ptr:t a) (l:list (cell a)) (v:a) : Steel (t a & list (cell a)) (llist ptr l) (fun pc -> llist (fst pc) (snd pc)) (requires fun _ -> True) (ensures fun _ pc _ -> datas (snd pc) == v::datas l)
val push (#a:Type) (ptr:t a) (l:list (cell a)) (v:a) : Steel (t a & list (cell a)) (llist ptr l) (fun pc -> llist (fst pc) (snd pc)) (requires fun _ -> True) (ensures fun _ pc _ -> datas (snd pc) == v::datas l)
let push #a ptr l v = let cell = mk_cell ptr v in let p = alloc_pt cell in rewrite_slprop (llist ptr l) (llist (next cell) l) (fun _ -> ()); intro_llist_cons p cell l; let pc = p, (cell::l) in pc
{ "file_name": "share/steel/examples/steel/LList.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 46, "start_col": 0, "start_line": 40 }
module LList open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference include LList.Invariant module L = FStar.List.Tot.Base #set-options "--ide_id_info_off" let rec datas (#a:Type) (l:list (cell a)) : list a = match l with | [] -> [] | hd::tl -> data hd :: datas tl val new_llist (#a:Type) (init:a) : Steel (t a & list (cell a)) emp (fun pc -> llist (fst pc) (snd pc)) (requires fun _ -> True) (ensures fun _ pc _ -> datas (snd pc) == [init]) let new_llist #a init = let cell = mk_cell null_llist init in let p = alloc_pt cell in intro_llist_nil a; rewrite_slprop (llist null_llist []) (llist (next cell) []) (fun _ -> ()); intro_llist_cons p cell []; let pc = p, [cell] in pc val push (#a:Type) (ptr:t a) (l:list (cell a)) (v:a) : Steel (t a & list (cell a)) (llist ptr l) (fun pc -> llist (fst pc) (snd pc)) (requires fun _ -> True) (ensures fun _ pc _ -> datas (snd pc) == v::datas l)
{ "checked_file": "/", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "LList.Invariant.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "LList.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "LList.Invariant", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: LList.Invariant.t a -> l: Prims.list (LList.Invariant.cell a) -> v: a -> Steel.Effect.Steel (LList.Invariant.t a * Prims.list (LList.Invariant.cell a))
Steel.Effect.Steel
[]
[]
[ "LList.Invariant.t", "Prims.list", "LList.Invariant.cell", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.Cons", "Prims.unit", "LList.Invariant.intro_llist_cons", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "LList.Invariant.llist", "LList.Invariant.next", "Steel.Memory.mem", "Steel.Reference.ref", "Steel.Reference.alloc_pt", "LList.Invariant.mk_cell" ]
[]
false
true
false
false
false
let push #a ptr l v =
let cell = mk_cell ptr v in let p = alloc_pt cell in rewrite_slprop (llist ptr l) (llist (next cell) l) (fun _ -> ()); intro_llist_cons p cell l; let pc = p, (cell :: l) in pc
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.invariant_s
val invariant_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0
val invariant_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0
let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 200, "start_col": 0, "start_line": 176 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state_s' c i -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state_s'", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Spec.bytes", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "Hacl.Streaming.Functor.optional_invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "Hacl.Streaming.Functor.optional_footprint", "Prims.int", "Prims.op_Addition", "FStar.Seq.Base.length", "FStar.UInt64.v", "FStar.UInt32.v", "Hacl.Streaming.Interface.__proj__Block__item__init_input_len", "Prims.op_LessThanOrEqual", "Hacl.Streaming.Interface.__proj__Block__item__max_input_len", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Hacl.Streaming.Interface.__proj__Block__item__update_multi_s", "Hacl.Streaming.Interface.__proj__Block__item__init_s", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "Prims.unit", "Prims._assert", "Prims.op_Modulus", "FStar.Math.Lemmas.modulo_lemma", "Hacl.Streaming.Interface.__proj__Block__item__block_len", "FStar.Pervasives.Native.tuple2", "Hacl.Streaming.Spec.split_at_last", "Hacl.Streaming.Interface.uint8", "FStar.Seq.Base.append", "Hacl.Streaming.Interface.__proj__Block__item__init_input_s", "Hacl.Streaming.Functor.optional_reveal", "FStar.Ghost.reveal" ]
[]
false
false
false
false
true
let invariant_s #index (c: block index) (i: index) h s =
let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); assert (0 % U32.v (Block?.block_len c i) = 0); Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); assert (0 % U32.v (Block?.blocks_state_len c i) = 0); B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest
false
Vale.X64.BufferViewStore.fst
Vale.X64.BufferViewStore.bv_upd_update_heap128
val bv_upd_update_heap128: (b:IB.b8{DV.length (IB.get_downview b.IB.bsrc) % 16 == 0}) -> (heap:machine_heap) -> (i:nat{i < DV.length (IB.get_downview b.IB.bsrc) / 16}) -> (v:quad32) -> (mem:IB.interop_heap{MB.live (IB.hs_of_mem mem) b.IB.bsrc}) -> Lemma (requires IB.correct_down_p mem heap b) (ensures (let dv = IB.get_downview b.IB.bsrc in let bv = UV.mk_buffer dv up_view128 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq bv; let heap' = update_heap128 (addrs b + 16 * i) v heap in UV.upd h bv i v == DV.upd_seq h dv (get_seq_heap heap' addrs b)))
val bv_upd_update_heap128: (b:IB.b8{DV.length (IB.get_downview b.IB.bsrc) % 16 == 0}) -> (heap:machine_heap) -> (i:nat{i < DV.length (IB.get_downview b.IB.bsrc) / 16}) -> (v:quad32) -> (mem:IB.interop_heap{MB.live (IB.hs_of_mem mem) b.IB.bsrc}) -> Lemma (requires IB.correct_down_p mem heap b) (ensures (let dv = IB.get_downview b.IB.bsrc in let bv = UV.mk_buffer dv up_view128 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq bv; let heap' = update_heap128 (addrs b + 16 * i) v heap in UV.upd h bv i v == DV.upd_seq h dv (get_seq_heap heap' addrs b)))
let bv_upd_update_heap128 b heap i v mem = let dv = IB.get_downview b.IB.bsrc in DV.length_eq dv; let uv = UV.mk_buffer dv up_view128 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq uv; let ptr = addrs b + 16 * i in let heap' = update_heap128 ptr v heap in let prefix, _, suffix = UV.split_at_i uv i h in let s_down = prefix `Seq.append` (put128 v `Seq.append` suffix) in let s_f = get_seq_heap heap' addrs b in let h' = UV.upd h uv i v in // This is by definition of UV.upd, fetched from the friended definition assert (h' == DV.upd_seq h dv s_down); DV.upd_seq_spec h dv s_down; // assert (DV.as_seq h' dv == s_down); let aux1 (j:nat{j < i * 16}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 16 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_down (base * 16 + j%16); ( == ) { assert (base * 16 + 16 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*16) (base*16 + 16) (j % 16) } // True by slice properties Seq.index (Seq.slice s_down (base*16) (base*16 + 16)) (j%16); ( == ) { UV.sel_upd uv i base v h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get128, which we get from get128 and put128 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*16) (base*16+16)) (Seq.slice s_down (base*16) (base*16+16))) } Seq.index (Seq.slice s_init (base*16) (base*16+16)) (j%16); ( == ) { assert (base * 16 + 16 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*16) (base*16 + 16) (j % 16) } // True by slice properties Seq.index s_init (base * 16 + j%16); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap128 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in let aux2(j:nat{j >= i * 16 /\ j < i * 16 + 16}) : Lemma (Seq.index s_down j == Seq.index s_f j) = UV.sel_upd uv i i v h; // assert (UV.sel h' uv i == v); UV.get_sel h' uv i; // assert (Vale.Interop.Views.get128 (Seq.slice s_down (i*16) (i*16+16)) = v); Vale.Arch.MachineHeap.correct_update_get128 ptr v heap; // assert (get_heap_val128 ptr heap' = v); let k = j - i * 16 in get128_aux ptr heap' v k; // assert (heap'.[ptr + k] = UInt8.v (Seq.index (put128 v) k)); map_aux (ptr + k) (addrs b + j) (UInt8.v (Seq.index s_down j)) heap' // assert (heap'.[ptr + k] = heap'.[addrs b + j]) in let aux3 (j:nat{j >= i * 16 + 16 /\ j < Seq.length s_down}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 16 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_down (base * 16 + j%16); ( == ) { assert (base * 16 + 16 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*16) (base*16 + 16) (j % 16) } // True by slice properties Seq.index (Seq.slice s_down (base*16) (base*16 + 16)) (j%16); ( == ) { UV.sel_upd uv i base v h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get128, which we get from get128 and put128 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*16) (base*16+16)) (Seq.slice s_down (base*16) (base*16+16))) } Seq.index (Seq.slice s_init (base*16) (base*16+16)) (j%16); ( == ) { assert (base * 16 + 16 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*16) (base * 16 + 16) (j % 16) } // True by slice properties Seq.index s_init (base * 16 + j%16); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap128 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in Classical.forall_intro aux1; Classical.forall_intro aux2; Classical.forall_intro aux3; assert (Seq.equal s_down s_f)
{ "file_name": "vale/code/arch/x64/Vale.X64.BufferViewStore.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 264, "start_col": 0, "start_line": 162 }
module Vale.X64.BufferViewStore open FStar.Mul open Vale.Interop.Views open Vale.Interop module MB = LowStar.Monotonic.Buffer module HS = FStar.HyperStack open Vale.Lib.BufferViewHelpers open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Two open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open Vale.Arch.Types open FStar.Calc friend LowStar.BufferView.Up #reset-options "--z3rlimit 10 --max_fuel 0 --initial_fuel 0 --max_ifuel 1 --initial_ifuel 1" let math_aux (a b c:int) : Lemma (a + b + (c - b) == a + c) = () let map_aux (ptr1 ptr2:int) (v:int) (m:machine_heap) : Lemma (requires ptr1 == ptr2 /\ m.[ptr1] == v) (ensures m.[ptr2] == v) = () let get64_aux (ptr:int) (heap:machine_heap) (v:nat64) (k:nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)) = get_heap_val64_reveal (); put64_reveal (); le_nat64_to_bytes_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); four_to_nat_8_injective (); two_to_nat_32_injective () let get128_aux (ptr:int) (heap:machine_heap) (v:quad32) (k:nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put128 v) k)) = get_heap_val128_reveal (); get_heap_val32_reveal (); put128_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; four_to_nat_8_injective () #reset-options "--max_fuel 1 --initial_fuel 1 --z3rlimit 200" let bv_upd_update_heap64 b heap i v mem = let dv = IB.get_downview b.IB.bsrc in DV.length_eq dv; let uv = UV.mk_buffer dv up_view64 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq uv; let ptr = addrs b + 8 * i in let heap' = update_heap64 ptr v heap in let prefix, _, suffix = UV.split_at_i uv i h in let s_down = prefix `Seq.append` (put64 (UInt64.uint_to_t v) `Seq.append` suffix) in let s_f = get_seq_heap heap' addrs b in let h' = UV.upd h uv i (UInt64.uint_to_t v) in // This is by definition of UV.upd, fetched from the friended definition assert (h' == DV.upd_seq h dv s_down); DV.upd_seq_spec h dv s_down; // assert (DV.as_seq h' dv == s_down); // We know that all elements but UV.sel h' uv i will be the same, (using UV.sel_upd lemmas) // hence aux1 and aux3 can be proven with initial correct_down_p on h // and the Bytes_Semantics.frame lemma // For aux2, we know that get64 (Seq.slice s_down (i*8) (i*8+8)) = v (through UV.sel lemmas) // We also know that get_heap_val64 ptr = v, which with get64_aux and some index matching // should give us the property let aux1 (j:nat{j < i * 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index (Seq.slice s_down (base*8) (base*8 + 8)) (j%8); ( == ) { UV.sel_upd uv i base (UInt64.uint_to_t v) h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get64, which we get from get64 and put64 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*8) (base*8+8)) (Seq.slice s_down (base*8) (base*8+8))) } Seq.index (Seq.slice s_init (base*8) (base*8 + 8)) (j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index s_init (base * 8 + j%8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in let aux2(j:nat{j >= i * 8 /\ j < i * 8 + 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = UV.sel_upd uv i i (UInt64.uint_to_t v) h; // assert (UV.sel h' uv i == UInt64.uint_to_t v); UV.get_sel h' uv i; // assert (Vale.Interop.Views.get64 (Seq.slice s_down (i*8) (i*8+8)) = UInt64.uint_to_t v); Vale.Arch.MachineHeap.correct_update_get64 ptr v heap; // assert (get_heap_val64 ptr heap' = v); let k = j - i * 8 in get64_aux ptr heap' v k; // assert (heap'.[ptr + k] = UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)); map_aux (ptr + k) (addrs b + j) (UInt8.v (Seq.index s_down j)) heap' // assert (heap'.[ptr + k] = heap'.[addrs b + j]) in let aux3 (j:nat{j >= i * 8 + 8 /\ j < Seq.length s_down}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index (Seq.slice s_down (base*8) (base*8 + 8)) (j%8); ( == ) { UV.sel_upd uv i base (UInt64.uint_to_t v) h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get64, which we get from get64 and put64 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*8) (base*8+8)) (Seq.slice s_down (base*8) (base*8+8))) } Seq.index (Seq.slice s_init (base*8) (base*8 + 8)) (j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index s_init (base * 8 + j%8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in Classical.forall_intro aux1; Classical.forall_intro aux2; Classical.forall_intro aux3; assert (Seq.equal s_down s_f)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Two.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferView.Up.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.BufferViewStore.fst" }
[ { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.Interop.Types.b8 { LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) % 16 == 0 } -> heap: Vale.Arch.MachineHeap_s.machine_heap -> i: Prims.nat {i < LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) / 16} -> v: Vale.Def.Types_s.quad32 -> mem: Vale.Interop.Heap_s.interop_heap {LowStar.Monotonic.Buffer.live (Vale.Interop.Heap_s.hs_of_mem mem) (Buffer?.bsrc b)} -> FStar.Pervasives.Lemma (requires Vale.Interop.Heap_s.correct_down_p mem heap b) (ensures (let dv = Vale.Interop.Types.get_downview (Buffer?.bsrc b) in let bv = LowStar.BufferView.Up.mk_buffer dv Vale.Interop.Views.up_view128 in let addrs = Vale.Interop.Heap_s.addrs_of_mem mem in let h = Vale.Interop.Heap_s.hs_of_mem mem in LowStar.BufferView.Up.length_eq bv; let heap' = Vale.Arch.MachineHeap_s.update_heap128 (addrs b + 16 * i) v heap in LowStar.BufferView.Up.upd h bv i v == LowStar.BufferView.Down.upd_seq h dv (Vale.Interop.get_seq_heap heap' addrs b)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Interop.Types.b8", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.Arch.MachineHeap_s.machine_heap", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Vale.Def.Types_s.quad32", "Vale.Interop.Heap_s.interop_heap", "LowStar.Monotonic.Buffer.live", "Vale.Interop.Heap_s.hs_of_mem", "FStar.Seq.Base.seq", "LowStar.BufferView.Up.buffer_src", "FStar.Seq.Properties.lseq", "LowStar.BufferView.Up.__proj__View__item__n", "LowStar.BufferView.Up.get_view", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "FStar.Seq.Base.index", "Prims.op_Multiply", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.UInt8.uint_to_t", "Vale.Interop.op_String_Access", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.euclidean_division_definition", "FStar.Seq.Base.lemma_index_slice", "Prims.op_LessThanOrEqual", "LowStar.BufferView.Up.get_sel", "LowStar.BufferView.Up.sel_upd", "Vale.Arch.MachineHeap.frame_update_heap128", "LowStar.BufferView.Down.as_seq", "Vale.X64.BufferViewStore.map_aux", "FStar.UInt8.v", "Vale.X64.BufferViewStore.get128_aux", "Prims.op_Subtraction", "Vale.Arch.MachineHeap.correct_update_get128", "LowStar.BufferView.Down.upd_seq_spec", "FStar.Monotonic.HyperStack.mem", "LowStar.BufferView.Down.upd_seq", "LowStar.BufferView.Up.upd", "Vale.Interop.get_seq_heap", "FStar.Seq.Base.append", "Vale.Interop.Views.put128", "FStar.Pervasives.Native.tuple3", "LowStar.BufferView.Up.as_down_buffer", "LowStar.BufferView.Up.split_at_i", "Vale.Arch.MachineHeap_s.update_heap128", "LowStar.BufferView.Up.length_eq", "Vale.Interop.Types.addr_map", "Vale.Interop.Heap_s.addrs_of_mem", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "Vale.Interop.Views.up_view128", "LowStar.BufferView.Down.length_eq", "LowStar.BufferView.Down.buffer" ]
[]
false
false
true
false
false
let bv_upd_update_heap128 b heap i v mem =
let dv = IB.get_downview b.IB.bsrc in DV.length_eq dv; let uv = UV.mk_buffer dv up_view128 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq uv; let ptr = addrs b + 16 * i in let heap' = update_heap128 ptr v heap in let prefix, _, suffix = UV.split_at_i uv i h in let s_down = prefix `Seq.append` ((put128 v) `Seq.append` suffix) in let s_f = get_seq_heap heap' addrs b in let h' = UV.upd h uv i v in assert (h' == DV.upd_seq h dv s_down); DV.upd_seq_spec h dv s_down; let aux1 (j: nat{j < i * 16}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 16 in let s_init = DV.as_seq h dv in calc ( == ) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_down (base * 16 + j % 16); ( == ) { (assert (base * 16 + 16 <= Seq.length s_down); Seq.lemma_index_slice s_down (base * 16) (base * 16 + 16) (j % 16)) } Seq.index (Seq.slice s_down (base * 16) (base * 16 + 16)) (j % 16); ( == ) { (UV.sel_upd uv i base v h; UV.get_sel h uv base; UV.get_sel h' uv base; assert (Seq.equal (Seq.slice s_init (base * 16) (base * 16 + 16)) (Seq.slice s_down (base * 16) (base * 16 + 16)))) } Seq.index (Seq.slice s_init (base * 16) (base * 16 + 16)) (j % 16); ( == ) { (assert (base * 16 + 16 <= Seq.length s_init); Seq.lemma_index_slice s_init (base * 16) (base * 16 + 16) (j % 16)) } Seq.index s_init (base * 16 + j % 16); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[ addrs b + j ])) } UInt8.uint_to_t (heap.[ addrs b + j ]); ( == ) { Vale.Arch.MachineHeap.frame_update_heap128 ptr v heap } UInt8.uint_to_t (heap'.[ addrs b + j ]); ( == ) { () } Seq.index s_f j; } in let aux2 (j: nat{j >= i * 16 /\ j < i * 16 + 16}) : Lemma (Seq.index s_down j == Seq.index s_f j) = UV.sel_upd uv i i v h; UV.get_sel h' uv i; Vale.Arch.MachineHeap.correct_update_get128 ptr v heap; let k = j - i * 16 in get128_aux ptr heap' v k; map_aux (ptr + k) (addrs b + j) (UInt8.v (Seq.index s_down j)) heap' in let aux3 (j: nat{j >= i * 16 + 16 /\ j < Seq.length s_down}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 16 in let s_init = DV.as_seq h dv in calc ( == ) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_down (base * 16 + j % 16); ( == ) { (assert (base * 16 + 16 <= Seq.length s_down); Seq.lemma_index_slice s_down (base * 16) (base * 16 + 16) (j % 16)) } Seq.index (Seq.slice s_down (base * 16) (base * 16 + 16)) (j % 16); ( == ) { (UV.sel_upd uv i base v h; UV.get_sel h uv base; UV.get_sel h' uv base; assert (Seq.equal (Seq.slice s_init (base * 16) (base * 16 + 16)) (Seq.slice s_down (base * 16) (base * 16 + 16)))) } Seq.index (Seq.slice s_init (base * 16) (base * 16 + 16)) (j % 16); ( == ) { (assert (base * 16 + 16 <= Seq.length s_init); Seq.lemma_index_slice s_init (base * 16) (base * 16 + 16) (j % 16)) } Seq.index s_init (base * 16 + j % 16); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 16 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[ addrs b + j ])) } UInt8.uint_to_t (heap.[ addrs b + j ]); ( == ) { Vale.Arch.MachineHeap.frame_update_heap128 ptr v heap } UInt8.uint_to_t (heap'.[ addrs b + j ]); ( == ) { () } Seq.index s_f j; } in Classical.forall_intro aux1; Classical.forall_intro aux2; Classical.forall_intro aux3; assert (Seq.equal s_down s_f)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.freeable
val freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : Type0
val freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) : Type0
let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 210, "start_col": 0, "start_line": 208 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Prims.l_and", "Hacl.Streaming.Functor.freeable_s", "LowStar.Monotonic.Buffer.get", "Hacl.Streaming.Functor.state_s", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.freeable" ]
[]
false
false
false
false
true
let freeable (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) =
freeable_s c i h (B.get h s 0) /\ B.freeable s
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.invariant_loc_in_footprint
val invariant_loc_in_footprint (#index: Type0) (c: block index) (i: index) (s: state' c i) (m: HS.mem) : Lemma (requires (invariant c i m s)) (ensures (B.loc_in (footprint c i m s) m)) [SMTPat (invariant c i m s)]
val invariant_loc_in_footprint (#index: Type0) (c: block index) (i: index) (s: state' c i) (m: HS.mem) : Lemma (requires (invariant c i m s)) (ensures (B.loc_in (footprint c i m s) m)) [SMTPat (invariant c i m s)]
let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in ()
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 218, "start_col": 0, "start_line": 213 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> s: Hacl.Streaming.Functor.state' c i -> m: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Hacl.Streaming.Functor.invariant c i m s) (ensures LowStar.Monotonic.Buffer.loc_in (Hacl.Streaming.Functor.footprint c i m s) m) [SMTPat (Hacl.Streaming.Functor.invariant c i m s)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.block", "Hacl.Streaming.Functor.state'", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__key", "Prims.unit", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "Prims.squash", "LowStar.Monotonic.Buffer.loc_in", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant_loc_in_footprint", "Hacl.Streaming.Interface.__proj__Block__item__state" ]
[]
true
false
true
false
false
let invariant_loc_in_footprint #index c i s m =
[@@ inline_let ]let _ = c.state.invariant_loc_in_footprint #i in [@@ inline_let ]let _ = c.key.invariant_loc_in_footprint #i in ()
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.total_len_h
val total_len_h : c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Streaming.Functor.state' c i -> Prims.GTot FStar.UInt64.t
let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p)
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 788, "start_col": 0, "start_line": 787 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ==========================================================
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Streaming.Functor.state' c i -> Prims.GTot FStar.UInt64.t
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Functor.__proj__State__item__total_len", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "LowStar.Monotonic.Buffer.deref", "Hacl.Streaming.Functor.state_s", "LowStar.Buffer.trivial_preorder", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let total_len_h #index (c: block index) (i: index) h (p: state' c i) =
State?.total_len (B.deref h p)
false
FStar.Pervasives.Native.fst
FStar.Pervasives.Native.fst
val fst (x: tuple2 'a 'b) : 'a
val fst (x: tuple2 'a 'b) : 'a
let fst (x: tuple2 'a 'b) : 'a = Mktuple2?._1 x
{ "file_name": "ulib/FStar.Pervasives.Native.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 62, "start_col": 0, "start_line": 62 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Pervasives.Native (* This is a file from the core library, dependencies must be explicit *) open Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides several basic types in F* that enjoy some special /// status in extraction. For instance, the tuple type below is /// compiled to OCaml's tuple type, rather than to a F*-defined /// inductive type. See ulib/ml/FStar_Pervasives_Native.ml /// (** [option a] represents either [Some a]-value or a non-informative [None]. *) type option (a: Type) = | None : option a | Some : v: a -> option a (**** Tuples *) /// Aside from special support in extraction, the tuple types have /// special syntax in F*. /// /// For instance, rather than [tupleN a1 ... aN], /// we usually write [a1 & ... & aN] or [a1 * ... * aN]. /// /// The latter notation is more common for those coming to F* from /// OCaml or F#. However, the [*] also clashes with the multiplication /// operator on integers define in FStar.Mul. For this reason, we now /// prefer to use the [&] notation, though there are still many uses /// of [*] remaining. /// /// Tuple values are introduced using as [a1, ..., an], rather than /// [MktupleN a1 ... aN]. /// /// We define tuples up to a fixed arity of 14. We have considered /// splitting this module into 14 different modules, one for each /// tuple type rather than eagerly including 14-tuples in the /// dependence graph of all programs. (** Pairs: [tuple2 a b] is can be written either as [a * b], for notation compatible with OCaml's. Or, better, as [a & b]. *) type tuple2 'a 'b = | Mktuple2 : _1: 'a -> _2: 'b -> tuple2 'a 'b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked" ], "interface_file": false, "source_file": "FStar.Pervasives.Native.fst" }
[ { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: ('a * 'b) -> 'a
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.__proj__Mktuple2__item___1" ]
[]
false
false
false
true
false
let fst (x: tuple2 'a 'b) : 'a =
Mktuple2?._1 x
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.split_at_last_all_seen
val split_at_last_all_seen : c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Streaming.Functor.state' c i -> Prims.GTot (Hacl.Streaming.Spec.bytes * Hacl.Streaming.Spec.bytes)
let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 794, "start_col": 0, "start_line": 791 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Streaming.Functor.state' c i -> Prims.GTot (Hacl.Streaming.Spec.bytes * Hacl.Streaming.Spec.bytes)
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Spec.bytes", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Hacl.Streaming.Spec.split_at_last", "Hacl.Streaming.Functor.bytes", "Hacl.Streaming.Functor.all_seen" ]
[]
false
false
false
false
false
let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) =
let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest
false
FStar.Pervasives.Native.fst
FStar.Pervasives.Native.snd
val snd (x: tuple2 'a 'b) : 'b
val snd (x: tuple2 'a 'b) : 'b
let snd (x: tuple2 'a 'b) : 'b = Mktuple2?._2 x
{ "file_name": "ulib/FStar.Pervasives.Native.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 63, "start_col": 0, "start_line": 63 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Pervasives.Native (* This is a file from the core library, dependencies must be explicit *) open Prims /// This module is implicitly opened in the scope of all other modules. /// /// It provides several basic types in F* that enjoy some special /// status in extraction. For instance, the tuple type below is /// compiled to OCaml's tuple type, rather than to a F*-defined /// inductive type. See ulib/ml/FStar_Pervasives_Native.ml /// (** [option a] represents either [Some a]-value or a non-informative [None]. *) type option (a: Type) = | None : option a | Some : v: a -> option a (**** Tuples *) /// Aside from special support in extraction, the tuple types have /// special syntax in F*. /// /// For instance, rather than [tupleN a1 ... aN], /// we usually write [a1 & ... & aN] or [a1 * ... * aN]. /// /// The latter notation is more common for those coming to F* from /// OCaml or F#. However, the [*] also clashes with the multiplication /// operator on integers define in FStar.Mul. For this reason, we now /// prefer to use the [&] notation, though there are still many uses /// of [*] remaining. /// /// Tuple values are introduced using as [a1, ..., an], rather than /// [MktupleN a1 ... aN]. /// /// We define tuples up to a fixed arity of 14. We have considered /// splitting this module into 14 different modules, one for each /// tuple type rather than eagerly including 14-tuples in the /// dependence graph of all programs. (** Pairs: [tuple2 a b] is can be written either as [a * b], for notation compatible with OCaml's. Or, better, as [a & b]. *) type tuple2 'a 'b = | Mktuple2 : _1: 'a -> _2: 'b -> tuple2 'a 'b (** The fst and snd projections on pairs are very common *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked" ], "interface_file": false, "source_file": "FStar.Pervasives.Native.fst" }
[ { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: ('a * 'b) -> 'b
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.__proj__Mktuple2__item___2" ]
[]
false
false
false
true
false
let snd (x: tuple2 'a 'b) : 'b =
Mktuple2?._2 x
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.index_of_state
val index_of_state: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> Stack index (fun h0 -> invariant c i h0 s) (fun h0 i' h1 -> h0 == h1 /\ i' == i))
val index_of_state: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> Stack index (fun h0 -> invariant c i h0 s) (fun h0 i' h1 -> h0 == h1 /\ i' == i))
let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 257, "start_col": 0, "start_line": 254 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> s: Hacl.Streaming.Functor.state c i t t' -> FStar.HyperStack.ST.Stack index)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Interface.__proj__Block__item__index_of_state", "Hacl.Streaming.Functor.state_s", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
false
false
false
false
let index_of_state #index c i t t' s =
let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.seen_length
val seen_length: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> Stack U64.t (fun h0 -> invariant c i h0 s) (fun h0 l h1 -> h0 == h1 /\ U64.v l == U32.v (c.init_input_len i) + S.length (seen c i h0 s)))
val seen_length: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> Stack U64.t (fun h0 -> invariant c i h0 s) (fun h0 l h1 -> h0 == h1 /\ U64.v l == U32.v (c.init_input_len i) + S.length (seen c i h0 s)))
let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 262, "start_col": 0, "start_line": 259 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> s: Hacl.Streaming.Functor.state c i t t' -> FStar.HyperStack.ST.Stack FStar.UInt64.t)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Functor.state_s", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
false
false
false
false
let seen_length #index c i t t' s =
let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len
false
Vale.X64.BufferViewStore.fst
Vale.X64.BufferViewStore.bv_upd_update_heap64
val bv_upd_update_heap64: (b:IB.b8{DV.length (IB.get_downview b.IB.bsrc) % 8 == 0}) -> (heap:machine_heap) -> (i:nat{i < DV.length (IB.get_downview b.IB.bsrc) / 8}) -> (v:nat64) -> (mem:IB.interop_heap{MB.live (IB.hs_of_mem mem) b.IB.bsrc}) -> Lemma (requires IB.correct_down_p mem heap b) (ensures (let dv = IB.get_downview b.IB.bsrc in let bv = UV.mk_buffer dv up_view64 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq bv; let heap' = update_heap64 (addrs b + 8 * i) v heap in UV.upd h bv i (UInt64.uint_to_t v) == DV.upd_seq h dv (get_seq_heap heap' addrs b)))
val bv_upd_update_heap64: (b:IB.b8{DV.length (IB.get_downview b.IB.bsrc) % 8 == 0}) -> (heap:machine_heap) -> (i:nat{i < DV.length (IB.get_downview b.IB.bsrc) / 8}) -> (v:nat64) -> (mem:IB.interop_heap{MB.live (IB.hs_of_mem mem) b.IB.bsrc}) -> Lemma (requires IB.correct_down_p mem heap b) (ensures (let dv = IB.get_downview b.IB.bsrc in let bv = UV.mk_buffer dv up_view64 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq bv; let heap' = update_heap64 (addrs b + 8 * i) v heap in UV.upd h bv i (UInt64.uint_to_t v) == DV.upd_seq h dv (get_seq_heap heap' addrs b)))
let bv_upd_update_heap64 b heap i v mem = let dv = IB.get_downview b.IB.bsrc in DV.length_eq dv; let uv = UV.mk_buffer dv up_view64 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq uv; let ptr = addrs b + 8 * i in let heap' = update_heap64 ptr v heap in let prefix, _, suffix = UV.split_at_i uv i h in let s_down = prefix `Seq.append` (put64 (UInt64.uint_to_t v) `Seq.append` suffix) in let s_f = get_seq_heap heap' addrs b in let h' = UV.upd h uv i (UInt64.uint_to_t v) in // This is by definition of UV.upd, fetched from the friended definition assert (h' == DV.upd_seq h dv s_down); DV.upd_seq_spec h dv s_down; // assert (DV.as_seq h' dv == s_down); // We know that all elements but UV.sel h' uv i will be the same, (using UV.sel_upd lemmas) // hence aux1 and aux3 can be proven with initial correct_down_p on h // and the Bytes_Semantics.frame lemma // For aux2, we know that get64 (Seq.slice s_down (i*8) (i*8+8)) = v (through UV.sel lemmas) // We also know that get_heap_val64 ptr = v, which with get64_aux and some index matching // should give us the property let aux1 (j:nat{j < i * 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index (Seq.slice s_down (base*8) (base*8 + 8)) (j%8); ( == ) { UV.sel_upd uv i base (UInt64.uint_to_t v) h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get64, which we get from get64 and put64 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*8) (base*8+8)) (Seq.slice s_down (base*8) (base*8+8))) } Seq.index (Seq.slice s_init (base*8) (base*8 + 8)) (j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index s_init (base * 8 + j%8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in let aux2(j:nat{j >= i * 8 /\ j < i * 8 + 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = UV.sel_upd uv i i (UInt64.uint_to_t v) h; // assert (UV.sel h' uv i == UInt64.uint_to_t v); UV.get_sel h' uv i; // assert (Vale.Interop.Views.get64 (Seq.slice s_down (i*8) (i*8+8)) = UInt64.uint_to_t v); Vale.Arch.MachineHeap.correct_update_get64 ptr v heap; // assert (get_heap_val64 ptr heap' = v); let k = j - i * 8 in get64_aux ptr heap' v k; // assert (heap'.[ptr + k] = UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)); map_aux (ptr + k) (addrs b + j) (UInt8.v (Seq.index s_down j)) heap' // assert (heap'.[ptr + k] = heap'.[addrs b + j]) in let aux3 (j:nat{j >= i * 8 + 8 /\ j < Seq.length s_down}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc (==) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index (Seq.slice s_down (base*8) (base*8 + 8)) (j%8); ( == ) { UV.sel_upd uv i base (UInt64.uint_to_t v) h; // assert (UV.sel h uv base == UV.sel h' uv base); UV.get_sel h uv base; UV.get_sel h' uv base; // With the injectivity of get64, which we get from get64 and put64 being inverses, // we get the following assert (Seq.equal (Seq.slice s_init (base*8) (base*8+8)) (Seq.slice s_down (base*8) (base*8+8))) } Seq.index (Seq.slice s_init (base*8) (base*8 + 8)) (j%8); ( == ) { assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base*8) (base*8 + 8) (j % 8) } // True by slice properties Seq.index s_init (base * 8 + j%8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[addrs b + j])) } UInt8.uint_to_t (heap.[addrs b + j]); // True by correct_down_p ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } // True by frame_update UInt8.uint_to_t (heap'.[addrs b + j]); ( == ) { } // True by definition of get_seq_heap Seq.index s_f j; } in Classical.forall_intro aux1; Classical.forall_intro aux2; Classical.forall_intro aux3; assert (Seq.equal s_down s_f)
{ "file_name": "vale/code/arch/x64/Vale.X64.BufferViewStore.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 160, "start_col": 0, "start_line": 52 }
module Vale.X64.BufferViewStore open FStar.Mul open Vale.Interop.Views open Vale.Interop module MB = LowStar.Monotonic.Buffer module HS = FStar.HyperStack open Vale.Lib.BufferViewHelpers open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Two open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open Vale.Arch.Types open FStar.Calc friend LowStar.BufferView.Up #reset-options "--z3rlimit 10 --max_fuel 0 --initial_fuel 0 --max_ifuel 1 --initial_ifuel 1" let math_aux (a b c:int) : Lemma (a + b + (c - b) == a + c) = () let map_aux (ptr1 ptr2:int) (v:int) (m:machine_heap) : Lemma (requires ptr1 == ptr2 /\ m.[ptr1] == v) (ensures m.[ptr2] == v) = () let get64_aux (ptr:int) (heap:machine_heap) (v:nat64) (k:nat{k < 8}) : Lemma (requires get_heap_val64 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put64 (UInt64.uint_to_t v)) k)) = get_heap_val64_reveal (); put64_reveal (); le_nat64_to_bytes_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); four_to_nat_8_injective (); two_to_nat_32_injective () let get128_aux (ptr:int) (heap:machine_heap) (v:quad32) (k:nat{k < 16}) : Lemma (requires get_heap_val128 ptr heap == v) (ensures heap.[ptr + k] == UInt8.v (Seq.index (put128 v) k)) = get_heap_val128_reveal (); get_heap_val32_reveal (); put128_reveal (); reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat8); reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; four_to_nat_8_injective () #reset-options "--max_fuel 1 --initial_fuel 1 --z3rlimit 200"
{ "checked_file": "/", "dependencies": [ "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Two.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferView.Up.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.BufferViewStore.fst" }
[ { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "Vale.Interop", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Views", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.Interop.Types.b8 {LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) % 8 == 0} -> heap: Vale.Arch.MachineHeap_s.machine_heap -> i: Prims.nat {i < LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) / 8} -> v: Vale.Def.Words_s.nat64 -> mem: Vale.Interop.Heap_s.interop_heap {LowStar.Monotonic.Buffer.live (Vale.Interop.Heap_s.hs_of_mem mem) (Buffer?.bsrc b)} -> FStar.Pervasives.Lemma (requires Vale.Interop.Heap_s.correct_down_p mem heap b) (ensures (let dv = Vale.Interop.Types.get_downview (Buffer?.bsrc b) in let bv = LowStar.BufferView.Up.mk_buffer dv Vale.Interop.Views.up_view64 in let addrs = Vale.Interop.Heap_s.addrs_of_mem mem in let h = Vale.Interop.Heap_s.hs_of_mem mem in LowStar.BufferView.Up.length_eq bv; let heap' = Vale.Arch.MachineHeap_s.update_heap64 (addrs b + 8 * i) v heap in LowStar.BufferView.Up.upd h bv i (FStar.UInt64.uint_to_t v) == LowStar.BufferView.Down.upd_seq h dv (Vale.Interop.get_seq_heap heap' addrs b)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Interop.Types.b8", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.Arch.MachineHeap_s.machine_heap", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Vale.Def.Words_s.nat64", "Vale.Interop.Heap_s.interop_heap", "LowStar.Monotonic.Buffer.live", "Vale.Interop.Heap_s.hs_of_mem", "FStar.Seq.Base.seq", "LowStar.BufferView.Up.buffer_src", "FStar.UInt64.t", "FStar.Seq.Properties.lseq", "LowStar.BufferView.Up.__proj__View__item__n", "LowStar.BufferView.Up.get_view", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "FStar.Seq.Base.index", "Prims.op_Multiply", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.UInt8.uint_to_t", "Vale.Interop.op_String_Access", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.euclidean_division_definition", "FStar.Seq.Base.lemma_index_slice", "Prims.op_LessThanOrEqual", "LowStar.BufferView.Up.get_sel", "LowStar.BufferView.Up.sel_upd", "FStar.UInt64.uint_to_t", "Vale.Arch.MachineHeap.frame_update_heap64", "LowStar.BufferView.Down.as_seq", "Vale.X64.BufferViewStore.map_aux", "FStar.UInt8.v", "Vale.X64.BufferViewStore.get64_aux", "Prims.op_Subtraction", "Vale.Arch.MachineHeap.correct_update_get64", "LowStar.BufferView.Down.upd_seq_spec", "FStar.Monotonic.HyperStack.mem", "LowStar.BufferView.Down.upd_seq", "LowStar.BufferView.Up.upd", "Vale.Interop.get_seq_heap", "FStar.Seq.Base.append", "Vale.Interop.Views.put64", "FStar.Pervasives.Native.tuple3", "LowStar.BufferView.Up.as_down_buffer", "LowStar.BufferView.Up.split_at_i", "Vale.Arch.MachineHeap_s.update_heap64", "LowStar.BufferView.Up.length_eq", "Vale.Interop.Types.addr_map", "Vale.Interop.Heap_s.addrs_of_mem", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "Vale.Interop.Views.up_view64", "LowStar.BufferView.Down.length_eq", "LowStar.BufferView.Down.buffer" ]
[]
false
false
true
false
false
let bv_upd_update_heap64 b heap i v mem =
let dv = IB.get_downview b.IB.bsrc in DV.length_eq dv; let uv = UV.mk_buffer dv up_view64 in let addrs = IB.addrs_of_mem mem in let h = IB.hs_of_mem mem in UV.length_eq uv; let ptr = addrs b + 8 * i in let heap' = update_heap64 ptr v heap in let prefix, _, suffix = UV.split_at_i uv i h in let s_down = prefix `Seq.append` ((put64 (UInt64.uint_to_t v)) `Seq.append` suffix) in let s_f = get_seq_heap heap' addrs b in let h' = UV.upd h uv i (UInt64.uint_to_t v) in assert (h' == DV.upd_seq h dv s_down); DV.upd_seq_spec h dv s_down; let aux1 (j: nat{j < i * 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc ( == ) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j % 8); ( == ) { (assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base * 8) (base * 8 + 8) (j % 8)) } Seq.index (Seq.slice s_down (base * 8) (base * 8 + 8)) (j % 8); ( == ) { (UV.sel_upd uv i base (UInt64.uint_to_t v) h; UV.get_sel h uv base; UV.get_sel h' uv base; assert (Seq.equal (Seq.slice s_init (base * 8) (base * 8 + 8)) (Seq.slice s_down (base * 8) (base * 8 + 8)))) } Seq.index (Seq.slice s_init (base * 8) (base * 8 + 8)) (j % 8); ( == ) { (assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base * 8) (base * 8 + 8) (j % 8)) } Seq.index s_init (base * 8 + j % 8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[ addrs b + j ])) } UInt8.uint_to_t (heap.[ addrs b + j ]); ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } UInt8.uint_to_t (heap'.[ addrs b + j ]); ( == ) { () } Seq.index s_f j; } in let aux2 (j: nat{j >= i * 8 /\ j < i * 8 + 8}) : Lemma (Seq.index s_down j == Seq.index s_f j) = UV.sel_upd uv i i (UInt64.uint_to_t v) h; UV.get_sel h' uv i; Vale.Arch.MachineHeap.correct_update_get64 ptr v heap; let k = j - i * 8 in get64_aux ptr heap' v k; map_aux (ptr + k) (addrs b + j) (UInt8.v (Seq.index s_down j)) heap' in let aux3 (j: nat{j >= i * 8 + 8 /\ j < Seq.length s_down}) : Lemma (Seq.index s_down j == Seq.index s_f j) = let base = j / 8 in let s_init = DV.as_seq h dv in calc ( == ) { Seq.index s_down j; ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_down (base * 8 + j % 8); ( == ) { (assert (base * 8 + 8 <= Seq.length s_down); Seq.lemma_index_slice s_down (base * 8) (base * 8 + 8) (j % 8)) } Seq.index (Seq.slice s_down (base * 8) (base * 8 + 8)) (j % 8); ( == ) { (UV.sel_upd uv i base (UInt64.uint_to_t v) h; UV.get_sel h uv base; UV.get_sel h' uv base; assert (Seq.equal (Seq.slice s_init (base * 8) (base * 8 + 8)) (Seq.slice s_down (base * 8) (base * 8 + 8)))) } Seq.index (Seq.slice s_init (base * 8) (base * 8 + 8)) (j % 8); ( == ) { (assert (base * 8 + 8 <= Seq.length s_init); Seq.lemma_index_slice s_init (base * 8) (base * 8 + 8) (j % 8)) } Seq.index s_init (base * 8 + j % 8); ( == ) { FStar.Math.Lemmas.euclidean_division_definition j 8 } Seq.index s_init j; ( == ) { assert (Seq.index s_init j == UInt8.uint_to_t (heap.[ addrs b + j ])) } UInt8.uint_to_t (heap.[ addrs b + j ]); ( == ) { Vale.Arch.MachineHeap.frame_update_heap64 ptr v heap } UInt8.uint_to_t (heap'.[ addrs b + j ]); ( == ) { () } Seq.index s_f j; } in Classical.forall_intro aux1; Classical.forall_intro aux2; Classical.forall_intro aux3; assert (Seq.equal s_down s_f)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.frame_invariant
val frame_invariant: #index:Type0 -> c:block index -> i:index -> l:B.loc -> s:state' c i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant c i h0 s /\ B.loc_disjoint l (footprint c i h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant c i h1 s /\ footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1)) [ SMTPat (invariant c i h1 s); SMTPat (B.modifies l h0 h1) ]
val frame_invariant: #index:Type0 -> c:block index -> i:index -> l:B.loc -> s:state' c i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant c i h0 s /\ B.loc_disjoint l (footprint c i h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant c i h1 s /\ footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1)) [ SMTPat (invariant c i h1 s); SMTPat (B.modifies l h0 h1) ]
let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 246, "start_col": 0, "start_line": 236 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> l: LowStar.Monotonic.Buffer.loc -> s: Hacl.Streaming.Functor.state' c i -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Hacl.Streaming.Functor.invariant c i h0 s /\ LowStar.Monotonic.Buffer.loc_disjoint l (Hacl.Streaming.Functor.footprint c i h0 s) /\ LowStar.Monotonic.Buffer.modifies l h0 h1) (ensures Hacl.Streaming.Functor.invariant c i h1 s /\ Hacl.Streaming.Functor.footprint c i h0 s == Hacl.Streaming.Functor.footprint c i h1 s /\ Hacl.Streaming.Functor.preserves_freeable c i s h0 h1) [ SMTPat (Hacl.Streaming.Functor.invariant c i h1 s); SMTPat (LowStar.Monotonic.Buffer.modifies l h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.block", "LowStar.Monotonic.Buffer.loc", "Hacl.Streaming.Functor.state'", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_invariant", "Prims.unit", "Hacl.Streaming.Functor.stateful_frame_preserves_freeable", "FStar.Pervasives.allow_inversion", "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Functor.state_s", "LowStar.Monotonic.Buffer.deref" ]
[]
false
false
true
false
false
let frame_invariant #index c i l s h0 h1 =
let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1
false
Hacl.Spec.K256.Field52.Lemmas2.fst
Hacl.Spec.K256.Field52.Lemmas2.minus_x_mul_pow2_256_lemma
val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1)))
val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1)))
let minus_x_mul_pow2_256_lemma m f = let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0,t1,t2,t3,t4') in calc (==) { // as_nat5 f v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; (==) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48 + v t4 % pow2 48) * pow208; (==) { Math.Lemmas.distributivity_add_left (v t4 / pow2 48 * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + (v t4 / pow2 48 * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; (==) { } (v x * pow2 48) * pow208 + as_nat5 r; (==) { Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208 } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48
{ "file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 50, "start_col": 0, "start_line": 30 }
module Hacl.Spec.K256.Field52.Lemmas2 open FStar.Mul open Lib.IntTypes module S = Spec.K256 include Hacl.Spec.K256.Field52.Definitions include Hacl.Spec.K256.Field52 module ML = Hacl.Spec.K256.MathLemmas module LD = Hacl.Spec.K256.Field52.Definitions.Lemmas #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" /// Normalize-weak val minus_x_mul_pow2_256_lemma: m:scale64_5 -> f:felem5 -> Lemma (requires felem_fits5 f m) (ensures (let x, r = minus_x_mul_pow2_256 f in let (r0,r1,r2,r3,r4) = r in let (m0,m1,m2,m3,m4) = m in let (t0,t1,t2,t3,t4) = f in v x < pow2 16 /\ v x = v t4 / pow2 48 /\ v r4 = v t4 % pow2 48 /\ as_nat5 r == as_nat5 f - v x * pow2 256 /\ felem_fits5 r (m0,m1,m2,m3,1)))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.K256.MathLemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.Lemmas.fst.checked", "Hacl.Spec.K256.Field52.Definitions.fst.checked", "Hacl.Spec.K256.Field52.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Field52.Lemmas2.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Definitions.Lemmas", "short_module": "LD" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.MathLemmas", "short_module": "ML" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Field52", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Hacl.Spec.K256.Field52.Definitions.scale64_5 -> f: Hacl.Spec.K256.Field52.Definitions.felem5 -> FStar.Pervasives.Lemma (requires Hacl.Spec.K256.Field52.Definitions.felem_fits5 f m) (ensures (let _ = Hacl.Spec.K256.Field52.minus_x_mul_pow2_256 f in (let FStar.Pervasives.Native.Mktuple2 #_ #_ x r = _ in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ r4 = _ in let _ = m in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ m0 m1 m2 m3 _ = _ in let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ t4 = _ in Lib.IntTypes.v x < Prims.pow2 16 /\ Lib.IntTypes.v x = Lib.IntTypes.v t4 / Prims.pow2 48 /\ Lib.IntTypes.v r4 = Lib.IntTypes.v t4 % Prims.pow2 48 /\ Hacl.Spec.K256.Field52.Definitions.as_nat5 r == Hacl.Spec.K256.Field52.Definitions.as_nat5 f - Lib.IntTypes.v x * Prims.pow2 256 /\ Hacl.Spec.K256.Field52.Definitions.felem_fits5 r (m0, m1, m2, m3, 1)) <: Type0) <: Type0) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Field52.Definitions.scale64_5", "Hacl.Spec.K256.Field52.Definitions.felem5", "Prims.nat", "Lib.IntTypes.uint64", "FStar.Math.Lemmas.lemma_div_lt", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Addition", "FStar.Mul.op_Star", "Hacl.Spec.K256.Field52.Definitions.pow52", "Hacl.Spec.K256.Field52.Definitions.pow104", "Hacl.Spec.K256.Field52.Definitions.pow156", "Hacl.Spec.K256.Field52.Definitions.pow208", "Prims.pow2", "Hacl.Spec.K256.Field52.Definitions.as_nat5", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Division", "Prims.op_Modulus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.K256.Field52.Definitions.Lemmas.lemma_mask48", "Lib.IntTypes.op_Amp_Dot", "Hacl.Spec.K256.Field52.Definitions.mask48", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t" ]
[]
false
false
true
false
false
let minus_x_mul_pow2_256_lemma m f =
let m0, m1, m2, m3, m4 = m in let t0, t1, t2, t3, t4 = f in let x = t4 >>. 48ul in let t4' = t4 &. mask48 in LD.lemma_mask48 t4; let r = (t0, t1, t2, t3, t4') in calc ( == ) { v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + v t4 * pow208; ( == ) { Math.Lemmas.euclidean_division_definition (v t4) (pow2 48) } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + ((v t4 / pow2 48) * pow2 48 + v t4 % pow2 48) * pow208; ( == ) { Math.Lemmas.distributivity_add_left ((v t4 / pow2 48) * pow2 48) (v t4 % pow2 48) pow208 } v t0 + v t1 * pow52 + v t2 * pow104 + v t3 * pow156 + ((v t4 / pow2 48) * pow2 48) * pow208 + (v t4 % pow2 48) * pow208; ( == ) { () } (v x * pow2 48) * pow208 + as_nat5 r; ( == ) { (Math.Lemmas.paren_mul_right (v x) (pow2 48) pow208; Math.Lemmas.pow2_plus 48 208) } v x * pow2 256 + as_nat5 r; }; Math.Lemmas.lemma_div_lt (v t4) 64 48
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.seen_h
val seen_h : c: Hacl.Streaming.Interface.block _ -> i: _ -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
let seen_h = seen
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 1192, "start_col": 10, "start_line": 1192 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0) #push-options "--z3cliopt smt.arith.nl=false" let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0 #pop-options /// The functional part of the invariant unfold val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True))) let invariant_s_funct #index c i t t' p data len h0 h1 = let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest /// We isolate the functional correctness proof obligations for [update_small] val update_small_functional_correctness : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // The precondition of [small_update] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s)) /\ // Generic conditions state_is_updated c i t t' s data len h0 h1 /\ // Functional conditions about the memory updates begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let sz = rest c i total_len0 in let buf = buf0 in let data_v0 = B.as_seq h0 data in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in buf_part_v1 == S.append buf_beg_v0 data_v0 /\ c.state.v i h1 block_state1 == c.state.v i h0 block_state0 end )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #push-options "--z3cliopt smt.arith.nl=false" let update_small_functional_correctness #index c i t t' p data len h0 h1 = let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state buf total_len0 seen0 key = s0 in let seen0 = G.reveal seen0 in let i = Ghost.reveal i in let key_v0 = optional_reveal #_ #i #c.km #c.key h0 key in let init_v0 = c.init_input_s i key_v0 in let all_seen0 = S.append init_v0 seen0 in let blocks0, rest0 = split_at_last c i all_seen0 in let State block_state buf total_len1 seen1 key = s1 in let seen1 = G.reveal seen1 in let i = Ghost.reveal i in let key_v1 = optional_reveal #_ #i #c.km #c.key h1 key in assert(key_v1 == key_v0); let init_v1 = c.init_input_s i key_v1 in assert(init_v1 == init_v0); let all_seen1 = S.append init_v1 seen1 in let blocks1, rest1 = split_at_last c i all_seen1 in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); let data_v0 = B.as_seq h0 data in split_at_last_small c i all_seen0 data_v0; // The first problematic condition assert(blocks1 `S.equal` blocks0); assert(c.state.v i h1 block_state == c.update_multi_s i (c.init_s i key_v1) 0 blocks1); // The second problematic condition assert(S.equal (S.slice (B.as_seq h1 buf) 0 (Seq.length rest1)) rest1) #pop-options // The absence of loc_disjoint_includes makes reasoning a little more difficult. // Notably, we lose all of the important disjointness properties between the // outer point p and the buffer within B.deref h p. These need to be // re-established by hand. Another thing that we lose without this pattern is // knowing that loc_buffer b is included within loc_addr_of_buffer b. This is // important for reasoning about the preservation of e.g. the contents of data. #restart-solver #push-options "--z3rlimit 300 --z3cliopt smt.arith.nl=false --z3refresh \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2,-FStar.Seq.Properties.slice_slice,-LowStar.Monotonic.Buffer.loc_disjoint_includes_r'" let update_small #index c i t t' p data len = let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen_ k' = s in [@inline_let] let block_state: c.state.s i = block_state in // Functional reasoning. let sz = rest c i total_len in add_len_small c i total_len len; let h0 = ST.get () in let buf1 = B.sub buf 0ul sz in let buf2 = B.sub buf sz len in // Memory reasoning. c.state.invariant_loc_in_footprint h0 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h0 k'; // key_invariant_loc_in_footprint #index c i h0 p; B.(loc_disjoint_includes_r (loc_buffer data) (footprint c i h0 p) (loc_buffer buf2)); // FIRST STATEFUL OPERATION B.blit data 0ul buf2 0ul len; // Memory reasoning. let h1 = ST.get () in modifies_footprint c i p data len h0 h1; c.state.invariant_loc_in_footprint h1 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h1 k'; // Functional reasoning on data begin let buf1_v0 = B.as_seq h0 buf1 in let buf1_v1 = B.as_seq h1 buf1 in let buf2_v1 = B.as_seq h1 buf2 in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in let data_v0 = B.as_seq h0 data in assert(buf1_v1 == buf1_v0); assert(buf1_v0 == buf_beg_v0); assert(buf2_v1 `S.equal` data_v0); assert(buf_part_v1 `S.equal` S.append buf_beg_v0 data_v0) end; // SECOND STATEFUL OPERATION let total_len = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len (G.hide (G.reveal seen_ `S.append` (B.as_seq h0 data))) k' in p *= tmp; // Memory reasoning. let h2 = ST.get () in modifies_footprint' c i p data len h1 h2; c.state.invariant_loc_in_footprint h2 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h2 k'; ST.lemma_equal_domains_trans h0 h1 h2; // Prove the invariant update_small_functional_correctness c i t t' p data len h0 h2 #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block _ -> i: _ -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Functor.seen", "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Functor.bytes" ]
[]
false
false
false
false
false
let seen_h =
seen
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.rest_finish
val rest_finish (#index: _) (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l) })
val rest_finish (#index: _) (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l) })
let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 747, "start_col": 0, "start_line": 727 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> len: FStar.UInt32.t -> x: FStar.UInt32.t { let l = FStar.UInt32.v (Block?.block_len c i) in let n = FStar.Pervasives.Native.fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (FStar.UInt32.v len)) in 0 <= n * l /\ n * l <= FStar.UInt32.v len /\ FStar.UInt32.v x = FStar.UInt32.v len - n * l }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.UInt32.t", "Prims.op_AmpAmp", "FStar.UInt32.op_Equals_Hat", "FStar.UInt32.uint_to_t", "FStar.UInt32.op_Greater_Hat", "Hacl.Streaming.Interface.__proj__Block__item__block_len", "Prims.unit", "FStar.Math.Lemmas.nat_times_nat_is_nat", "Prims.nat", "FStar.Pervasives.Native.fst", "Lib.UpdateMulti.split_at_last_lazy_nb_rem", "FStar.UInt32.v", "FStar.UInt.uint_t", "Prims.bool", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.op_Equality", "Prims.int", "Prims.op_Subtraction", "Hacl.Streaming.Functor.split_at_last_num_blocks_lem", "FStar.UInt32.rem", "Prims.op_GreaterThan" ]
[]
false
false
false
false
false
let rest_finish #index (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l) }) =
[@@ inline_let ]let l = c.block_len i in [@@ inline_let ]let r = len `U32.rem` l in split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then ((let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in Math.Lemmas.nat_times_nat_is_nat n l); c.block_len i) else r
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.all_seen_h
val all_seen_h : c: Hacl.Streaming.Interface.block _ -> i: _ -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
let all_seen_h = all_seen
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 1193, "start_col": 10, "start_line": 1193 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0) #push-options "--z3cliopt smt.arith.nl=false" let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0 #pop-options /// The functional part of the invariant unfold val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True))) let invariant_s_funct #index c i t t' p data len h0 h1 = let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest /// We isolate the functional correctness proof obligations for [update_small] val update_small_functional_correctness : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // The precondition of [small_update] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s)) /\ // Generic conditions state_is_updated c i t t' s data len h0 h1 /\ // Functional conditions about the memory updates begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let sz = rest c i total_len0 in let buf = buf0 in let data_v0 = B.as_seq h0 data in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in buf_part_v1 == S.append buf_beg_v0 data_v0 /\ c.state.v i h1 block_state1 == c.state.v i h0 block_state0 end )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #push-options "--z3cliopt smt.arith.nl=false" let update_small_functional_correctness #index c i t t' p data len h0 h1 = let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state buf total_len0 seen0 key = s0 in let seen0 = G.reveal seen0 in let i = Ghost.reveal i in let key_v0 = optional_reveal #_ #i #c.km #c.key h0 key in let init_v0 = c.init_input_s i key_v0 in let all_seen0 = S.append init_v0 seen0 in let blocks0, rest0 = split_at_last c i all_seen0 in let State block_state buf total_len1 seen1 key = s1 in let seen1 = G.reveal seen1 in let i = Ghost.reveal i in let key_v1 = optional_reveal #_ #i #c.km #c.key h1 key in assert(key_v1 == key_v0); let init_v1 = c.init_input_s i key_v1 in assert(init_v1 == init_v0); let all_seen1 = S.append init_v1 seen1 in let blocks1, rest1 = split_at_last c i all_seen1 in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); let data_v0 = B.as_seq h0 data in split_at_last_small c i all_seen0 data_v0; // The first problematic condition assert(blocks1 `S.equal` blocks0); assert(c.state.v i h1 block_state == c.update_multi_s i (c.init_s i key_v1) 0 blocks1); // The second problematic condition assert(S.equal (S.slice (B.as_seq h1 buf) 0 (Seq.length rest1)) rest1) #pop-options // The absence of loc_disjoint_includes makes reasoning a little more difficult. // Notably, we lose all of the important disjointness properties between the // outer point p and the buffer within B.deref h p. These need to be // re-established by hand. Another thing that we lose without this pattern is // knowing that loc_buffer b is included within loc_addr_of_buffer b. This is // important for reasoning about the preservation of e.g. the contents of data. #restart-solver #push-options "--z3rlimit 300 --z3cliopt smt.arith.nl=false --z3refresh \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2,-FStar.Seq.Properties.slice_slice,-LowStar.Monotonic.Buffer.loc_disjoint_includes_r'" let update_small #index c i t t' p data len = let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen_ k' = s in [@inline_let] let block_state: c.state.s i = block_state in // Functional reasoning. let sz = rest c i total_len in add_len_small c i total_len len; let h0 = ST.get () in let buf1 = B.sub buf 0ul sz in let buf2 = B.sub buf sz len in // Memory reasoning. c.state.invariant_loc_in_footprint h0 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h0 k'; // key_invariant_loc_in_footprint #index c i h0 p; B.(loc_disjoint_includes_r (loc_buffer data) (footprint c i h0 p) (loc_buffer buf2)); // FIRST STATEFUL OPERATION B.blit data 0ul buf2 0ul len; // Memory reasoning. let h1 = ST.get () in modifies_footprint c i p data len h0 h1; c.state.invariant_loc_in_footprint h1 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h1 k'; // Functional reasoning on data begin let buf1_v0 = B.as_seq h0 buf1 in let buf1_v1 = B.as_seq h1 buf1 in let buf2_v1 = B.as_seq h1 buf2 in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in let data_v0 = B.as_seq h0 data in assert(buf1_v1 == buf1_v0); assert(buf1_v0 == buf_beg_v0); assert(buf2_v1 `S.equal` data_v0); assert(buf_part_v1 `S.equal` S.append buf_beg_v0 data_v0) end; // SECOND STATEFUL OPERATION let total_len = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len (G.hide (G.reveal seen_ `S.append` (B.as_seq h0 data))) k' in p *= tmp; // Memory reasoning. let h2 = ST.get () in modifies_footprint' c i p data len h1 h2; c.state.invariant_loc_in_footprint h2 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h2 k'; ST.lemma_equal_domains_trans h0 h1 h2; // Prove the invariant update_small_functional_correctness c i t t' p data len h0 h2 #pop-options // Stupid name collisions
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block _ -> i: _ -> h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Streaming.Functor.state' c i -> Prims.GTot Hacl.Streaming.Functor.bytes
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Streaming.Functor.all_seen", "Hacl.Streaming.Interface.block", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Functor.state'", "Hacl.Streaming.Functor.bytes" ]
[]
false
false
false
false
false
let all_seen_h =
all_seen
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.add_len
val add_len (#index: _) (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i))
val add_len (#index: _) (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i))
let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 758, "start_col": 0, "start_line": 753 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> total_len: FStar.UInt64.t -> len: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
Prims.Pure
[]
[]
[ "Hacl.Streaming.Interface.block", "FStar.UInt64.t", "FStar.UInt32.t", "FStar.UInt64.add", "FStar.Int.Cast.uint32_to_uint64", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt64.v", "FStar.UInt32.v", "Hacl.Streaming.Interface.__proj__Block__item__max_input_len", "Prims.l_and", "Prims.op_Equality", "Prims.int" ]
[]
false
false
false
false
false
let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) =
total_len `U64.add` (Int.Cast.uint32_to_uint64 len)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.nblocks
val nblocks (#index: _) (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) })
val nblocks (#index: _) (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) })
let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 720, "start_col": 0, "start_line": 697 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> len: FStar.UInt32.t -> x: FStar.UInt32.t { let l = FStar.UInt32.v (Block?.blocks_state_len c i) in FStar.UInt32.v x * l <= FStar.UInt32.v len /\ FStar.UInt32.v x = Hacl.Streaming.Spec.split_at_last_num_blocks c i (FStar.UInt32.v len) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.UInt32.t", "Prims.unit", "Hacl.Streaming.Spec.split_at_last_num_blocks_spec", "FStar.Ghost.reveal", "Prims.nat", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Mul.op_Star", "FStar.Ghost.erased", "FStar.Ghost.hide", "FStar.UInt32.v", "FStar.UInt32.div", "Prims.op_Modulus", "FStar.UInt32.sub", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.nat_times_nat_is_nat", "Prims.op_Addition", "Hacl.Streaming.Spec.split_at_last_num_blocks", "Prims.l_and", "Prims.op_Multiply", "FStar.UInt64.v", "FStar.Int.Cast.uint32_to_uint64", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "Prims.op_Subtraction", "Hacl.Streaming.Functor.rest", "Prims.op_GreaterThan", "Prims.op_GreaterThanOrEqual", "Hacl.Streaming.Interface.__proj__Block__item__block_len", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let nblocks #index (c: block index) (i: index) (len: UInt32.t) : (x: UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) =
let open FStar.Int.Cast in [@@ inline_let ]let l = c.blocks_state_len i in [@@ inline_let ]let r = rest c i (uint32_to_uint64 len) in let len_v:Ghost.erased nat = U32.v len in let l_v:Ghost.erased nat = U32.v l in let r_v:Ghost.erased nat = U32.v r in let n_s:Ghost.erased nat = split_at_last_num_blocks c i len_v in assert (Ghost.reveal len_v = n_s * l_v + r_v); Math.Lemmas.nat_times_nat_is_nat n_s l_v; assert (U32.v r <= U32.v len); [@@ inline_let ]let blocks = len `U32.sub` r in let blocks_v:Ghost.erased nat = U32.v blocks in assert (blocks_v % l_v = 0); [@@ inline_let ]let n = blocks `U32.div` l in let n_v:Ghost.erased nat = U32.v n in assert (n_v * l_v = Ghost.reveal blocks_v); split_at_last_num_blocks_spec c i len_v n_v r_v; n
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.rest
val rest (#index: _) (c: block index) (i: index) (total_len: UInt64.t) : (x: UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l) })
val rest (#index: _) (c: block index) (i: index) (total_len: UInt64.t) : (x: UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l) })
let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 688, "start_col": 0, "start_line": 645 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> total_len: FStar.UInt64.t -> x: FStar.UInt32.t { let n = Hacl.Streaming.Spec.split_at_last_num_blocks c i (FStar.UInt64.v total_len) in let l = FStar.UInt32.v (Block?.blocks_state_len c i) in 0 <= n * l /\ n * l <= FStar.UInt64.v total_len /\ FStar.UInt32.v x = FStar.UInt64.v total_len - n * l }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.UInt64.t", "Prims.op_AmpAmp", "FStar.UInt64.op_Equals_Hat", "FStar.UInt64.uint_to_t", "FStar.UInt64.op_Greater_Hat", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "Prims.unit", "Hacl.Streaming.Functor.split_at_last_num_blocks_lem", "FStar.UInt64.v", "Prims.bool", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.UInt32.v", "Prims.op_Subtraction", "FStar.Mul.op_Star", "FStar.UInt.uint_t", "Prims.nat", "Hacl.Streaming.Spec.split_at_last_num_blocks", "FStar.Calc.calc_finish", "FStar.UInt32.n", "Prims.eq2", "Prims.op_Modulus", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Int.Cast.uint32_to_uint64", "Prims.pow2", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.small_modulo_lemma_1", "FStar.Math.Lemmas.euclidean_division_definition", "FStar.UInt32.t", "FStar.Int.Cast.uint64_to_uint32", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Ghost.reveal", "Prims.op_Division", "FStar.Ghost.erased", "FStar.Ghost.hide", "FStar.UInt64.rem", "Prims.l_or", "FStar.UInt.size" ]
[]
false
false
false
false
false
let rest #index (c: block index) (i: index) (total_len: UInt64.t) : (x: UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l) }) =
let open FStar.Int.Cast in [@@ inline_let ]let l = uint32_to_uint64 (c.blocks_state_len i) in [@@ inline_let ]let r = total_len `U64.rem` l in let total_len_v:Ghost.erased nat = U64.v total_len in let l_v:Ghost.erased nat = U64.v l in let r_v:Ghost.erased nat = U64.v r in assert (Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); Math.Lemmas.euclidean_division_definition total_len_v l_v; assert (Ghost.reveal r_v = total_len_v % l_v); assert (r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then (split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i) else [@@ inline_let ]let r' = FStar.Int.Cast.uint64_to_uint32 r in FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); calc ( == ) { U32.v r'; ( == ) { () } U64.v r % pow2 32; ( == ) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } U64.v r; ( == ) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i)); ( == ) { () } U64.v total_len % U32.v (c.blocks_state_len i); }; assert (let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in U32.v r' = U64.v total_len - (n * l)); r'
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.state_is_updated
val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0)
val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0)
let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 98, "end_line": 999, "start_col": 0, "start_line": 985 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> s: Hacl.Streaming.Functor.state c i t t' -> data: LowStar.Buffer.buffer Hacl.Streaming.Spec.uint8 -> len: FStar.UInt32.t -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Hacl.Streaming.Spec.uint8", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Prims.l_and", "Prims.l_or", "Prims.int", "FStar.UInt64.v", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "LowStar.Monotonic.Buffer.as_seq", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Functor.optional_reveal", "Hacl.Streaming.Functor.state_s", "LowStar.Monotonic.Buffer.get" ]
[]
false
false
false
false
false
let state_is_updated #index c i t t' p data len h0 h1 =
let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.add_len_small
val add_len_small (#index: _) (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = (rest c i total_len) `U32.add` len))
val add_len_small (#index: _) (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = (rest c i total_len) `U32.add` len))
let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r'
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 779, "start_col": 0, "start_line": 762 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> total_len: FStar.UInt64.t -> len: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v len <= FStar.UInt32.v (Block?.blocks_state_len c i) - FStar.UInt32.v (Hacl.Streaming.Functor.rest c i total_len) /\ FStar.UInt64.v total_len + FStar.UInt32.v len <= FStar.UInt64.v (Block?.max_input_len c i)) (ensures Hacl.Streaming.Functor.rest c i (Hacl.Streaming.Functor.add_len c i total_len len) = FStar.UInt32.add (Hacl.Streaming.Functor.rest c i total_len) len)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.UInt64.t", "FStar.UInt32.t", "Hacl.Streaming.Spec.split_at_last_num_blocks_spec", "Prims.unit", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.l_imp", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Hacl.Streaming.Functor.rest", "FStar.UInt.uint_t", "Prims.nat", "Hacl.Streaming.Spec.split_at_last_num_blocks", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.v", "Prims.l_and", "Prims.op_Subtraction", "Hacl.Streaming.Interface.__proj__Block__item__max_input_len", "Prims.squash", "Hacl.Streaming.Functor.add_len", "FStar.UInt32.add", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t) : Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = (rest c i total_len) `U32.add` len)) =
let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert (total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert (r' <= l); assert (r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert (b = n * l + r'); split_at_last_num_blocks_spec c i b n r'
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.split_at_last_rest_eq
val split_at_last_rest_eq (#index: Type0) (c: block index) (i: index) (t: Type0{t == c.state.s i}) (t': Type0{t' == optional_key i c.km c.key}) (s: state c i t t') (h0: HS.mem) : Lemma (requires (invariant c i h0 s)) (ensures (let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz))
val split_at_last_rest_eq (#index: Type0) (c: block index) (i: index) (t: Type0{t == c.state.s i}) (t': Type0{t' == optional_key i c.km c.key}) (s: state c i t t') (h0: HS.mem) : Lemma (requires (invariant c i h0 s)) (ensures (let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz))
let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in ()
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 841, "start_col": 0, "start_line": 819 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: index -> t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> s: Hacl.Streaming.Functor.state c i t t' -> h0: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Hacl.Streaming.Functor.invariant c i h0 s) (ensures (let s = LowStar.Monotonic.Buffer.get h0 s 0 in let _ = s in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ _ _ total_len seen_ k' = _ in let key_v = Hacl.Streaming.Functor.optional_reveal h0 k' in let all_seen = FStar.Seq.Base.append (Block?.init_input_s c i key_v) (FStar.Ghost.reveal seen_) in let _ = Hacl.Streaming.Spec.split_at_last c i all_seen in (let FStar.Pervasives.Native.Mktuple2 #_ #_ _ r = _ in let sz = Hacl.Streaming.Functor.rest c i total_len in FStar.Seq.Base.length r == FStar.UInt32.v sz) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Streaming.Interface.block", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "Hacl.Streaming.Spec.bytes", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "Hacl.Streaming.Spec.split_at_last_num_blocks", "FStar.UInt64.v", "FStar.UInt32.v", "Prims.int", "Prims.op_Subtraction", "Hacl.Streaming.Functor.rest", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Hacl.Streaming.Spec.split_at_last", "Hacl.Streaming.Interface.uint8", "FStar.Seq.Base.append", "Hacl.Streaming.Interface.__proj__Block__item__init_input_s", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Functor.optional_reveal", "Hacl.Streaming.Functor.state_s", "LowStar.Monotonic.Buffer.get", "Hacl.Streaming.Functor.invariant", "Prims.squash", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let split_at_last_rest_eq (#index: Type0) (c: block index) (i: index) (t: Type0{t == c.state.s i}) (t': Type0{t' == optional_key i c.km c.key}) (s: state c i t t') (h0: HS.mem) : Lemma (requires (invariant c i h0 s)) (ensures (let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) =
let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in ()
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.invariant_s_funct
val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True)))
val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True)))
let invariant_s_funct #index c i t t' p data len h0 h1 = let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 1029, "start_col": 0, "start_line": 1021 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0) #push-options "--z3cliopt smt.arith.nl=false" let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0 #pop-options /// The functional part of the invariant unfold val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> s: Hacl.Streaming.Functor.state c i t t' -> data: LowStar.Buffer.buffer Hacl.Streaming.Spec.uint8 -> len: FStar.UInt32.t -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Prims.Pure Type0)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Hacl.Streaming.Spec.uint8", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Spec.bytes", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Prims.l_and", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Hacl.Streaming.Interface.__proj__Block__item__update_multi_s", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Seq.Base.length", "Prims.unit", "FStar.Math.Lemmas.modulo_lemma", "FStar.UInt32.v", "Hacl.Streaming.Interface.__proj__Block__item__block_len", "Hacl.Streaming.Interface.__proj__Block__item__init_s", "Hacl.Streaming.Functor.optional_reveal", "Hacl.Streaming.Functor.state_s", "LowStar.Monotonic.Buffer.get", "FStar.Pervasives.Native.tuple2", "Hacl.Streaming.Functor.split_at_last_all_seen" ]
[]
false
false
false
false
false
let invariant_s_funct #index c i t t' p data len h0 h1 =
let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.modifies_footprint
val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True)))))
val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True)))))
let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 902, "start_col": 0, "start_line": 893 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True)))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in s: Hacl.Streaming.Functor.state' c i -> data: LowStar.Buffer.buffer Hacl.Streaming.Spec.uint8 -> len: FStar.UInt32.t -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires (let _ = LowStar.Monotonic.Buffer.deref h0 s in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ _ buf_ _ _ _ = _ in Hacl.Streaming.Functor.update_pre c i s data len h0 /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer buf_) h0 h1 ) <: Type0)) (ensures (let _ = LowStar.Monotonic.Buffer.deref h0 s in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs0 buf0 _ _ k0 = _ in let _ = LowStar.Monotonic.Buffer.deref h1 s in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs1 buf1 _ _ k1 = _ in Hacl.Streaming.Functor.footprint c i h0 s == Hacl.Streaming.Functor.footprint c i h1 s /\ Hacl.Streaming.Functor.preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ Stateful?.invariant (Block?.state c) h1 bs1 /\ Stateful?.v (Block?.state c) i h1 bs1 == Stateful?.v (Block?.state c) i h0 bs0 /\ Stateful?.footprint (Block?.state c) h1 bs1 == Stateful?.footprint (Block?.state c) h0 bs0 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) (LowStar.Monotonic.Buffer.loc_buffer buf1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) (LowStar.Monotonic.Buffer.loc_buffer data) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) (LowStar.Monotonic.Buffer.loc_addr_of_buffer buf1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) (Stateful?.footprint (Block?.state c) h1 bs1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer s) (LowStar.Monotonic.Buffer.loc_buffer buf1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer s) (LowStar.Monotonic.Buffer.loc_buffer data) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer s) (Stateful?.footprint (Block?.state c) h1 bs1) /\ (match Block?.km c = Hacl.Streaming.Interface.Runtime with | true -> Stateful?.invariant (Block?.key c) h1 k1 /\ Stateful?.v (Block?.key c) i h1 k1 == Stateful?.v (Block?.key c) i h0 k0 /\ Stateful?.footprint (Block?.key c) h1 k1 == Stateful?.footprint (Block?.key c) h0 k0 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) (Stateful?.footprint (Block?.key c) h1 k1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer s ) (Stateful?.footprint (Block?.key c) h1 k1) | _ -> LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer s) LowStar.Monotonic.Buffer.loc_none /\ Prims.l_True)) <: Type0) <: Type0)))
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Hacl.Streaming.Functor.state'", "FStar.Ghost.reveal", "LowStar.Buffer.buffer", "Hacl.Streaming.Spec.uint8", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.Runtime", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_invariant", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.bool", "Prims.unit", "Hacl.Streaming.Functor.state_s", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "Hacl.Streaming.Interface.__proj__Stateful__item__freeable", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "LowStar.Monotonic.Buffer.modifies", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_freeable" ]
[]
false
false
false
false
false
let modifies_footprint c i p data len h0 h1 =
let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1
false
Hacl.Impl.P256.Scalar.fst
Hacl.Impl.P256.Scalar.bn_is_lt_order_and_gt_zero_mask4
val bn_is_lt_order_and_gt_zero_mask4: f:felem -> Stack uint64 (requires fun h -> live h f) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ (if 0 < as_nat h0 f && as_nat h0 f < S.order then v r = ones_v U64 else v r = 0))
val bn_is_lt_order_and_gt_zero_mask4: f:felem -> Stack uint64 (requires fun h -> live h f) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ (if 0 < as_nat h0 f && as_nat h0 f < S.order then v r = ones_v U64 else v r = 0))
let bn_is_lt_order_and_gt_zero_mask4 f = let h0 = ST.get () in let is_lt_order = bn_is_lt_order_mask4 f in assert (v is_lt_order = (if as_nat h0 f < S.order then ones_v U64 else 0)); let is_eq_zero = bn_is_zero_mask4 f in assert (v is_eq_zero = (if as_nat h0 f = 0 then ones_v U64 else 0)); lognot_lemma is_eq_zero; assert (v (lognot is_eq_zero) = (if 0 < as_nat h0 f then ones_v U64 else 0)); let res = logand is_lt_order (lognot is_eq_zero) in logand_lemma is_lt_order (lognot is_eq_zero); assert (v res == (if 0 < as_nat h0 f && as_nat h0 f < S.order then ones_v U64 else 0)); res
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Scalar.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 65, "start_col": 0, "start_line": 53 }
module Hacl.Impl.P256.Scalar open FStar.Mul open FStar.HyperStack.All open FStar.HyperStack module ST = FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Hacl.Impl.P256.Bignum open Hacl.Impl.P256.Constants module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module BM = Hacl.Bignum.Montgomery friend Hacl.Bignum256 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Create one [@CInline] let make_qone f = [@inline_let] let f0 = u64 0xc46353d039cdaaf in [@inline_let] let f1 = u64 0x4319055258e8617b in [@inline_let] let f2 = u64 0x0 in [@inline_let] let f3 = u64 0xffffffff in assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 < S.order); assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 == SM.to_qmont 1); SM.lemma_to_from_qmont_id 1; bn_make_u64_4 f f0 f1 f2 f3 /// Comparison [@CInline] let bn_is_lt_order_mask4 f = let h0 = ST.get () in push_frame (); let tmp = create_felem () in make_order tmp; let c = bn_sub4 tmp f tmp in assert (if v c = 0 then as_nat h0 f >= S.order else as_nat h0 f < S.order); pop_frame (); u64 0 -. c
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Constants.fst.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "Hacl.Bignum256.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.P256.Scalar.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Constants", "short_module": null }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint64
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.op_AmpAmp", "Prims.op_LessThan", "Hacl.Impl.P256.Bignum.as_nat", "Spec.P256.PointOps.order", "Lib.IntTypes.ones_v", "Prims.bool", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.lognot", "Lib.IntTypes.int_t", "Lib.IntTypes.logand", "Prims.b2t", "Prims.op_Equality", "Lib.IntTypes.lognot_lemma", "Lib.IntTypes.uint64", "Hacl.Impl.P256.Bignum.bn_is_zero_mask4", "Hacl.Impl.P256.Scalar.bn_is_lt_order_mask4", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let bn_is_lt_order_and_gt_zero_mask4 f =
let h0 = ST.get () in let is_lt_order = bn_is_lt_order_mask4 f in assert (v is_lt_order = (if as_nat h0 f < S.order then ones_v U64 else 0)); let is_eq_zero = bn_is_zero_mask4 f in assert (v is_eq_zero = (if as_nat h0 f = 0 then ones_v U64 else 0)); lognot_lemma is_eq_zero; assert (v (lognot is_eq_zero) = (if 0 < as_nat h0 f then ones_v U64 else 0)); let res = logand is_lt_order (lognot is_eq_zero) in logand_lemma is_lt_order (lognot is_eq_zero); assert (v res == (if 0 < as_nat h0 f && as_nat h0 f < S.order then ones_v U64 else 0)); res
false
Hacl.Impl.P256.Scalar.fst
Hacl.Impl.P256.Scalar.make_qone
val make_qone: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f < S.order /\ qmont_as_nat h1 f == 1)
val make_qone: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f < S.order /\ qmont_as_nat h1 f == 1)
let make_qone f = [@inline_let] let f0 = u64 0xc46353d039cdaaf in [@inline_let] let f1 = u64 0x4319055258e8617b in [@inline_let] let f2 = u64 0x0 in [@inline_let] let f3 = u64 0xffffffff in assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 < S.order); assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 == SM.to_qmont 1); SM.lemma_to_from_qmont_id 1; bn_make_u64_4 f f0 f1 f2 f3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Scalar.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 35, "start_col": 0, "start_line": 27 }
module Hacl.Impl.P256.Scalar open FStar.Mul open FStar.HyperStack.All open FStar.HyperStack module ST = FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Hacl.Impl.P256.Bignum open Hacl.Impl.P256.Constants module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module BM = Hacl.Bignum.Montgomery friend Hacl.Bignum256 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Create one
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Constants.fst.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "Hacl.Bignum256.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.P256.Scalar.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Constants", "short_module": null }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "Hacl.Spec.P256.Montgomery.lemma_to_from_qmont_id", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Hacl.Spec.P256.Montgomery.to_qmont", "Prims.b2t", "Prims.op_LessThan", "Spec.P256.PointOps.order", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_qone f =
[@@ inline_let ]let f0 = u64 0xc46353d039cdaaf in [@@ inline_let ]let f1 = u64 0x4319055258e8617b in [@@ inline_let ]let f2 = u64 0x0 in [@@ inline_let ]let f3 = u64 0xffffffff in assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 < S.order); assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 == SM.to_qmont 1); SM.lemma_to_from_qmont_id 1; bn_make_u64_4 f f0 f1 f2 f3
false
Hacl.Impl.P256.Scalar.fst
Hacl.Impl.P256.Scalar.qmod_short_lemma
val qmod_short_lemma: a:nat{a < pow2 256} -> Lemma (let r = if a >= S.order then a - S.order else a in r = a % S.order)
val qmod_short_lemma: a:nat{a < pow2 256} -> Lemma (let r = if a >= S.order then a - S.order else a in r = a % S.order)
let qmod_short_lemma a = let r = if a >= S.order then a - S.order else a in if a >= S.order then begin Math.Lemmas.lemma_mod_sub a S.order 1; assert_norm (pow2 256 - S.order < S.order); Math.Lemmas.small_mod r S.order end else Math.Lemmas.small_mod r S.order
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Scalar.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 95, "start_col": 0, "start_line": 88 }
module Hacl.Impl.P256.Scalar open FStar.Mul open FStar.HyperStack.All open FStar.HyperStack module ST = FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Hacl.Impl.P256.Bignum open Hacl.Impl.P256.Constants module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module BM = Hacl.Bignum.Montgomery friend Hacl.Bignum256 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Create one [@CInline] let make_qone f = [@inline_let] let f0 = u64 0xc46353d039cdaaf in [@inline_let] let f1 = u64 0x4319055258e8617b in [@inline_let] let f2 = u64 0x0 in [@inline_let] let f3 = u64 0xffffffff in assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 < S.order); assert_norm (v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192 == SM.to_qmont 1); SM.lemma_to_from_qmont_id 1; bn_make_u64_4 f f0 f1 f2 f3 /// Comparison [@CInline] let bn_is_lt_order_mask4 f = let h0 = ST.get () in push_frame (); let tmp = create_felem () in make_order tmp; let c = bn_sub4 tmp f tmp in assert (if v c = 0 then as_nat h0 f >= S.order else as_nat h0 f < S.order); pop_frame (); u64 0 -. c [@CInline] let bn_is_lt_order_and_gt_zero_mask4 f = let h0 = ST.get () in let is_lt_order = bn_is_lt_order_mask4 f in assert (v is_lt_order = (if as_nat h0 f < S.order then ones_v U64 else 0)); let is_eq_zero = bn_is_zero_mask4 f in assert (v is_eq_zero = (if as_nat h0 f = 0 then ones_v U64 else 0)); lognot_lemma is_eq_zero; assert (v (lognot is_eq_zero) = (if 0 < as_nat h0 f then ones_v U64 else 0)); let res = logand is_lt_order (lognot is_eq_zero) in logand_lemma is_lt_order (lognot is_eq_zero); assert (v res == (if 0 < as_nat h0 f && as_nat h0 f < S.order then ones_v U64 else 0)); res let load_qelem_conditional res b = push_frame (); bn_from_bytes_be4 res b; let is_b_valid = bn_is_lt_order_and_gt_zero_mask4 res in let oneq = create_felem () in bn_set_one4 oneq; let h0 = ST.get () in Lib.ByteBuffer.buf_mask_select res oneq is_b_valid res; let h1 = ST.get () in assert (as_seq h1 res == (if (v is_b_valid = 0) then as_seq h0 oneq else as_seq h0 res)); pop_frame (); is_b_valid /// Field Arithmetic val qmod_short_lemma: a:nat{a < pow2 256} -> Lemma (let r = if a >= S.order then a - S.order else a in r = a % S.order)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Constants.fst.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "Hacl.Bignum256.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.P256.Scalar.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Constants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.nat{a < Prims.pow2 256} -> FStar.Pervasives.Lemma (ensures (let r = (match a >= Spec.P256.PointOps.order with | true -> a - Spec.P256.PointOps.order | _ -> a) <: Prims.int in r = a % Spec.P256.PointOps.order))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_GreaterThanOrEqual", "Spec.P256.PointOps.order", "FStar.Math.Lemmas.small_mod", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_Subtraction", "FStar.Math.Lemmas.lemma_mod_sub", "Prims.bool" ]
[]
false
false
true
false
false
let qmod_short_lemma a =
let r = if a >= S.order then a - S.order else a in if a >= S.order then (Math.Lemmas.lemma_mod_sub a S.order 1; assert_norm (pow2 256 - S.order < S.order); Math.Lemmas.small_mod r S.order) else Math.Lemmas.small_mod r S.order
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.free
val free: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> free_st #index c i t t')
val free: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> free_st #index c i t t')
let free #index c i t t' state = let _ = allow_inversion key_management in let open LowStar.BufferOps in let State block_state buf _ _ k' = !*state in let h0 = ST.get () in begin match c.km with | Runtime -> c.key.free i k' | Erased -> () end; let h1 = ST.get () in c.state.frame_freeable #i (optional_footprint #index #i #c.km #c.key h0 k') block_state h0 h1; c.state.frame_invariant #i (optional_footprint #index #i #c.km #c.key h0 k') block_state h0 h1; c.state.free i block_state; B.free buf; B.free state
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 1817, "start_col": 0, "start_line": 1803 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0) #push-options "--z3cliopt smt.arith.nl=false" let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0 #pop-options /// The functional part of the invariant unfold val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True))) let invariant_s_funct #index c i t t' p data len h0 h1 = let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest /// We isolate the functional correctness proof obligations for [update_small] val update_small_functional_correctness : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // The precondition of [small_update] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s)) /\ // Generic conditions state_is_updated c i t t' s data len h0 h1 /\ // Functional conditions about the memory updates begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let sz = rest c i total_len0 in let buf = buf0 in let data_v0 = B.as_seq h0 data in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in buf_part_v1 == S.append buf_beg_v0 data_v0 /\ c.state.v i h1 block_state1 == c.state.v i h0 block_state0 end )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #push-options "--z3cliopt smt.arith.nl=false" let update_small_functional_correctness #index c i t t' p data len h0 h1 = let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state buf total_len0 seen0 key = s0 in let seen0 = G.reveal seen0 in let i = Ghost.reveal i in let key_v0 = optional_reveal #_ #i #c.km #c.key h0 key in let init_v0 = c.init_input_s i key_v0 in let all_seen0 = S.append init_v0 seen0 in let blocks0, rest0 = split_at_last c i all_seen0 in let State block_state buf total_len1 seen1 key = s1 in let seen1 = G.reveal seen1 in let i = Ghost.reveal i in let key_v1 = optional_reveal #_ #i #c.km #c.key h1 key in assert(key_v1 == key_v0); let init_v1 = c.init_input_s i key_v1 in assert(init_v1 == init_v0); let all_seen1 = S.append init_v1 seen1 in let blocks1, rest1 = split_at_last c i all_seen1 in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); let data_v0 = B.as_seq h0 data in split_at_last_small c i all_seen0 data_v0; // The first problematic condition assert(blocks1 `S.equal` blocks0); assert(c.state.v i h1 block_state == c.update_multi_s i (c.init_s i key_v1) 0 blocks1); // The second problematic condition assert(S.equal (S.slice (B.as_seq h1 buf) 0 (Seq.length rest1)) rest1) #pop-options // The absence of loc_disjoint_includes makes reasoning a little more difficult. // Notably, we lose all of the important disjointness properties between the // outer point p and the buffer within B.deref h p. These need to be // re-established by hand. Another thing that we lose without this pattern is // knowing that loc_buffer b is included within loc_addr_of_buffer b. This is // important for reasoning about the preservation of e.g. the contents of data. #restart-solver #push-options "--z3rlimit 300 --z3cliopt smt.arith.nl=false --z3refresh \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2,-FStar.Seq.Properties.slice_slice,-LowStar.Monotonic.Buffer.loc_disjoint_includes_r'" let update_small #index c i t t' p data len = let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen_ k' = s in [@inline_let] let block_state: c.state.s i = block_state in // Functional reasoning. let sz = rest c i total_len in add_len_small c i total_len len; let h0 = ST.get () in let buf1 = B.sub buf 0ul sz in let buf2 = B.sub buf sz len in // Memory reasoning. c.state.invariant_loc_in_footprint h0 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h0 k'; // key_invariant_loc_in_footprint #index c i h0 p; B.(loc_disjoint_includes_r (loc_buffer data) (footprint c i h0 p) (loc_buffer buf2)); // FIRST STATEFUL OPERATION B.blit data 0ul buf2 0ul len; // Memory reasoning. let h1 = ST.get () in modifies_footprint c i p data len h0 h1; c.state.invariant_loc_in_footprint h1 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h1 k'; // Functional reasoning on data begin let buf1_v0 = B.as_seq h0 buf1 in let buf1_v1 = B.as_seq h1 buf1 in let buf2_v1 = B.as_seq h1 buf2 in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in let data_v0 = B.as_seq h0 data in assert(buf1_v1 == buf1_v0); assert(buf1_v0 == buf_beg_v0); assert(buf2_v1 `S.equal` data_v0); assert(buf_part_v1 `S.equal` S.append buf_beg_v0 data_v0) end; // SECOND STATEFUL OPERATION let total_len = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len (G.hide (G.reveal seen_ `S.append` (B.as_seq h0 data))) k' in p *= tmp; // Memory reasoning. let h2 = ST.get () in modifies_footprint' c i p data len h1 h2; c.state.invariant_loc_in_footprint h2 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h2 k'; ST.lemma_equal_domains_trans h0 h1 h2; // Prove the invariant update_small_functional_correctness c i t t' p data len h0 h2 #pop-options // Stupid name collisions noextract let seen_h = seen noextract let all_seen_h = all_seen /// Case 2: we have no buffered data (ie: the buffer was just initialized), or the /// internal buffer is full meaning that we can just hash it to go to the case where /// there is no buffered data. Of course, the data we append has to be non-empty, /// otherwise we might end-up with an empty internal buffer. /// Auxiliary lemma which groups the functional correctness proof obligations /// for [update_empty_or_full]. #push-options "--z3cliopt smt.arith.nl=false" val update_empty_or_full_functional_correctness : #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer Lib.IntTypes.uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // Same precondition as [update_empty_or_full_buf] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ (rest c i (total_len_h c i h0 s) = 0ul \/ rest c i (total_len_h c i h0 s) = c.blocks_state_len i) /\ U32.v len > 0 /\ // Generic additional preconditions state_is_updated c i t t' s data len h0 h1 /\ // Additional preconditions begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let seen0 = G.reveal seen0 in let seen1 = G.reveal seen1 in let block_state = block_state0 in let buf = buf0 in let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.v n_blocks * U32.v (c.blocks_state_len i) <= U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.gsub data 0ul data1_len in let data2 = B.gsub data data1_len data2_len in let all_seen0 = all_seen c i h0 s in let all_seen1 = all_seen c i h1 s in let blocks0, res0 = split_at_last c i all_seen0 in let blocks1, res1 = split_at_last c i all_seen1 in let data1_v = B.as_seq h0 data1 in let data2_v = B.as_seq h0 data2 in let key = optional_reveal #index #i #c.km #c.key h0 key0 in let init_s = c.init_s i key in let all_seen_data1 = S.append all_seen0 data1_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); S.length all_seen0 % U32.v (c.block_len i) = 0 /\ // TODO: should be proved automatically S.length all_seen_data1 % U32.v (c.block_len i) = 0 /\ // TODO: should be proved automatically c.state.v i h1 block_state == c.update_multi_s i init_s 0 all_seen_data1 /\ S.slice (B.as_seq h1 buf) 0 (Seq.length data2_v) `S.equal` data2_v /\ True end /\ True )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let update_empty_or_full_functional_correctness #index c i t t' p data len h0 h1 = let s = B.get h0 p 0 in let State block_state buf_ total_len seen0 key = s in let init_s = c.init_s i (optional_reveal #index #i #c.km #c.key h0 key) in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.gsub data 0ul data1_len in let data2 = B.gsub data data1_len data2_len in let data_v = B.as_seq h0 data in let init_input = init_input c i h0 p in let seen1 = seen c i h1 p in let all_seen0 = all_seen c i h0 p in let all_seen1 = all_seen c i h1 p in let blocks0, rest0 = split_at_last_all_seen c i h0 p in let blocks1, rest1 = split_at_last_all_seen c i h1 p in let data_blocks, data_rest = split_at_last c i data_v in split_at_last_blocks c i all_seen0 data_v; assert(Seq.equal all_seen1 (S.append all_seen0 data_v)); assert(S.equal blocks1 (S.append all_seen0 data_blocks)); assert(S.equal data_rest rest1) #pop-options inline_for_extraction noextract val update_empty_or_full_buf: #index:Type0 -> c:block index -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer Lib.IntTypes.uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ (rest c i (total_len_h c i h0 s) = 0ul \/ rest c i (total_len_h c i h0 s) = c.blocks_state_len i) /\ U32.v len > 0) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) #push-options "--z3cliopt smt.arith.nl=false --z3rlimit 500" let update_empty_or_full_buf #index c i t t' p data len = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in [@inline_let] let _ = c.update_multi_associative i in let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen k' = s in [@inline_let] let block_state: c.state.s i = block_state in let sz = rest c i total_len in let h0 = ST.get () in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); assert(0 % U32.v (c.block_len i) = 0); let init_key : Ghost.erased _ = optional_reveal h0 (k' <: optional_key i c.km c.key) in let init_state : Ghost.erased _ = c.init_s i init_key in assert( let all_seen = all_seen c i h0 p in let blocks, rest = split_at_last c i all_seen in Seq.length rest = U32.v sz /\ c.state.v i h0 block_state == c.update_multi_s i init_state 0 blocks); (* Start by "flushing" the buffer: hash it so that all the data seen so far * has been processed and we can consider the buffer as empty *) if U32.(sz =^ 0ul) then begin assert( let all_seen = all_seen c i h0 p in c.state.v i h0 block_state == c.update_multi_s i init_state 0 all_seen) end else begin let prevlen = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 sz) in c.update_multi (G.hide i) block_state prevlen buf (c.blocks_state_len i); begin let h1 = ST.get () in let all_seen = all_seen c i h0 p in let blocks, rest = split_at_last c i all_seen in assert(Seq.length blocks = U64.v prevlen); assert(c.state.v i h0 block_state == c.update_multi_s i init_state 0 blocks); assert(c.state.v i h1 block_state == c.update_multi_s i (c.update_multi_s i init_state 0 blocks) (U64.v prevlen) rest); assert(all_seen `Seq.equal` Seq.append blocks rest); (* TODO: the pattern of ``update_multi_associative`` is not triggered *) c.update_multi_associative i init_state 0 (U64.v prevlen) blocks rest; assert(c.state.v i h1 block_state == c.update_multi_s i init_state 0 all_seen) end end; let h1 = ST.get () in assert( let all_seen = all_seen c i h0 p in c.state.v i h1 block_state == c.update_multi_s i init_state 0 all_seen); split_at_last_blocks c i (all_seen c i h0 p) (B.as_seq h0 data); // TODO: remove? let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.sub data 0ul data1_len in let data2 = B.sub data data1_len data2_len in c.update_multi (G.hide i) block_state total_len data1 data1_len; let h01 = ST.get () in optional_frame #_ #i #c.km #c.key (c.state.footprint h0 block_state) k' h0 h01; assert(preserves_freeable c i p h0 h01); begin let all_seen = all_seen c i h0 p in let data1_v = B.as_seq h01 data1 in c.update_multi_associative i init_state 0 (Seq.length all_seen) all_seen data1_v; assert(c.state.v i h01 block_state == c.update_multi_s i init_state 0 (Seq.append all_seen data1_v)) end; let dst = B.sub buf 0ul data2_len in let h1 = ST.get () in B.blit data2 0ul dst 0ul data2_len; let h2 = ST.get () in c.state.frame_invariant (B.loc_buffer buf) block_state h1 h2; optional_frame #_ #i #c.km #c.key (B.loc_buffer buf) k' h1 h2; stateful_frame_preserves_freeable #index #(Block?.state c) #i (B.loc_buffer dst) (State?.block_state s) h1 h2; assert(preserves_freeable c i p h01 h2); [@inline_let] let total_len' = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len' (seen `S.append` B.as_seq h0 data) k' in p *= tmp; let h3 = ST.get () in c.state.frame_invariant (B.loc_buffer p) block_state h2 h3; optional_frame #_ #i #c.km #c.key (B.loc_buffer p) k' h2 h3; stateful_frame_preserves_freeable #index #(Block?.state c) #i (B.loc_buffer p) (State?.block_state s) h2 h3; assert(preserves_freeable c i p h2 h3); assert(preserves_freeable c i p h0 h3); update_empty_or_full_functional_correctness #index c i t t' p data len h0 h3; (* The following proof obligation is the difficult one - keep it here for * easy debugging when updating the definitions/proofs *) assert(invariant_s c i h3 (B.get h3 p 0)) #pop-options /// Case 3: we are given just enough data to end up on the boundary. It is just /// a sub-case of [update_small], but with a little bit more precise pre and post /// conditions. inline_for_extraction noextract val update_round: #index:Type0 -> c:block index -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ ( let r = rest c i (total_len_h c i h0 s) in U32.v len + U32.v r = U32.v (c.blocks_state_len i) /\ r <> 0ul)) (ensures fun h0 _ h1 -> update_post c i s data len h0 h1 /\ begin let blocks, rest = split_at_last_all_seen c i h0 s in let blocks', rest' = split_at_last_all_seen c i h1 s in blocks' `S.equal` blocks /\ rest' `S.equal` S.append rest (B.as_seq h0 data) /\ S.length rest' = U32.v (c.blocks_state_len i) end)) #push-options "--z3rlimit 200 --z3cliopt smt.arith.nl=false" let update_round #index c i t t' p data len = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.update_multi_associative i in let open LowStar.BufferOps in (**) let h0 = ST.get() in update_small #index c i t t' p data len; (**) let h1 = ST.get() in (**) split_at_last_small c i (all_seen c i h0 p) (B.as_seq h0 data); (**) begin // For some reason, the proof fails if we don't call those (**) let blocks, rest = split_at_last_all_seen c i h0 p in (**) let blocks', rest' = split_at_last_all_seen c i h1 p in (**) () (**) end #pop-options /// General update function, as a decomposition of the three sub-cases /// ================================================================== #push-options "--z3rlimit 200" let update #index c i t t' state chunk chunk_len = let open LowStar.BufferOps in let s = !*state in let State block_state buf_ total_len seen k' = s in let i = c.index_of_state i block_state in if FStar.UInt64.(FStar.Int.Cast.uint32_to_uint64 chunk_len >^ c.max_input_len i -^ total_len) then Hacl.Streaming.Types.MaximumLengthExceeded else let sz = rest c i total_len in if chunk_len `U32.lte` (c.blocks_state_len i `U32.sub` sz) then update_small c i t t' state chunk chunk_len else if sz = 0ul then update_empty_or_full_buf c i t t' state chunk chunk_len else begin let h0 = ST.get () in let diff = c.blocks_state_len i `U32.sub` sz in let chunk1 = B.sub chunk 0ul diff in let chunk2 = B.sub chunk diff (chunk_len `U32.sub` diff) in update_round c i t t' state chunk1 diff; let h1 = ST.get () in update_empty_or_full_buf c i t t' state chunk2 (chunk_len `U32.sub` diff); let h2 = ST.get () in ( let seen = G.reveal seen in assert (seen_h c i h1 state `S.equal` (S.append seen (B.as_seq h0 chunk1))); assert (seen_h c i h2 state `S.equal` (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2))); S.append_assoc seen (B.as_seq h0 chunk1) (B.as_seq h0 chunk2); assert (S.equal (S.append (B.as_seq h0 chunk1) (B.as_seq h0 chunk2)) (B.as_seq h0 chunk)); assert (S.equal (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2)) (S.append seen (B.as_seq h0 chunk))); assert (seen_h c i h2 state `S.equal` (S.append seen (B.as_seq h0 chunk))); () ) end; Hacl.Streaming.Types.Success #pop-options #push-options "--z3cliopt smt.arith.nl=false" val digest_process_begin_functional_correctness : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> dst:B.buffer uint8 -> l: c.output_length_t { B.length dst == c.output_length i l } -> h0: HS.mem -> h1: HS.mem -> tmp_block_state: t -> Lemma (requires ( // The precondition of [digest] invariant c i h0 s /\ c.state.invariant #i h1 tmp_block_state /\ begin let s = B.get h0 s 0 in let State block_state buf_ total_len seen key = s in let r = rest c i total_len in (**) assert(U32.v r <= U64.v total_len); let prev_len = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 r) in let r_last = rest_finish c i r in (**) assert(U32.v r_last <= U32.v r); let r_multi = U32.(r -^ r_last) in let buf_multi = B.gsub buf_ 0ul r_multi in let prev_length = U64.v prev_len in let k = optional_reveal #_ #i #c.km #c.key h0 key in c.state.v i h1 tmp_block_state == c.update_multi_s i (c.state.v i h0 block_state) prev_length (B.as_seq h0 buf_multi) end)) (ensures ( let all_seen = all_seen c i h0 s in let s = B.get h0 s 0 in let State block_state buf_ total_len seen key = s in let block_length = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem block_length (S.length all_seen)) in let k = optional_reveal #_ #i #c.km #c.key h0 key in let init_state = c.init_s i k in (**) Math.Lemmas.modulo_lemma 0 block_length; (**) Math.Lemmas.cancel_mul_mod n block_length; (**) Math.Lemmas.nat_times_nat_is_nat n block_length; (**) split_at_last_num_blocks_lem c i (S.length all_seen); 0 % block_length = 0 /\ 0 <= n * block_length /\ (n * block_length) % block_length = 0 /\ c.state.v i h1 tmp_block_state == c.update_multi_s i init_state 0 (S.slice all_seen 0 (n * block_length))) )) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let digest_process_begin_functional_correctness #index c i t t' p dst l h0 h1 tmp_block_state = let h3 = h0 in let h4 = h1 in let s = B.get h0 p 0 in let State block_state buf_ total_len seen k' = s in let r = rest c i total_len in let buf_ = B.gsub buf_ 0ul r in let prev_len = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 r) in let r_last = rest_finish c i r in let r_multi = U32.(r -^ r_last) in let i = G.reveal i in let all_seen = all_seen c i h0 p in let block_length = U32.v (c.block_len i) in let blocks_state_length = U32.v (c.blocks_state_len i) in let k = optional_reveal #_ #i #c.km #c.key h0 k' in let prev_length = U64.v prev_len in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem block_length (S.length all_seen)) in let init_state = c.init_s i k in Math.Lemmas.modulo_lemma 0 block_length; Math.Lemmas.cancel_mul_mod n block_length; assert(prev_length + U32.v r = U64.v total_len); assert(U32.v r_multi <= U32.v r); assert(prev_length + U32.v r_multi <= U64.v total_len); assert(n * block_length <= U64.v total_len); let buf_multi = B.gsub buf_ 0ul r_multi in assert( c.state.v i h4 tmp_block_state == c.update_multi_s i (c.state.v i h0 block_state) prev_length (B.as_seq h3 buf_multi)); assert( B.as_seq h3 buf_multi == S.slice all_seen prev_length (prev_length + U32.v r_multi)); assert( c.state.v i h4 tmp_block_state == c.update_multi_s i (c.update_multi_s i init_state 0 (S.slice all_seen 0 prev_length)) prev_length (S.slice all_seen prev_length (prev_length + U32.v r_multi))); assert(0 % block_length = 0); assert(S.length (S.slice all_seen 0 prev_length) % block_length = 0); assert(prev_length + U32.v r_multi <= S.length all_seen); c.update_multi_associative i init_state 0 prev_length (S.slice all_seen 0 prev_length) (S.slice all_seen prev_length (prev_length + U32.v r_multi)); assert( S.equal (S.append (S.slice all_seen 0 prev_length) (S.slice all_seen prev_length (prev_length + U32.v r_multi))) (S.slice all_seen 0 (prev_length + U32.v r_multi))); assert( c.state.v i h4 tmp_block_state == c.update_multi_s i init_state 0 (S.slice all_seen 0 (prev_length + U32.v r_multi))); split_at_last_finish c i all_seen; Math.Lemmas.nat_times_nat_is_nat n block_length; assert(0 <= n * block_length); assert(n * block_length <= S.length all_seen); assert( c.state.v i h4 tmp_block_state == c.update_multi_s i init_state 0 (S.slice all_seen 0 (n * block_length))) #pop-options #restart-solver #push-options "--z3cliopt smt.arith.nl=false --z3rlimit 200" let digest #index c i t t' state output l = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in [@inline_let] let _ = c.update_multi_associative i in [@inline_let] let _ = allow_inversion key_management in let open LowStar.BufferOps in let h0 = ST.get () in let State block_state buf_ total_len seen k' = !*state in push_frame (); let h1 = ST.get () in c.state.frame_invariant #i B.loc_none block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i B.loc_none block_state h0 h1; optional_frame #_ #i #c.km #c.key B.loc_none k' h0 h1; let r = rest c i total_len in let buf_ = B.sub buf_ 0ul r in let tmp_block_state = c.state.alloca i in let h2 = ST.get () in assert (B.(loc_disjoint (c.state.footprint #i h2 tmp_block_state) (c.state.footprint #i h1 block_state))); B.modifies_only_not_unused_in B.loc_none h1 h2; c.state.frame_invariant #i B.loc_none block_state h1 h2; stateful_frame_preserves_freeable #index #c.state #i B.loc_none block_state h1 h2; optional_frame #_ #i #c.km #c.key B.loc_none k' h1 h2; c.state.copy (G.hide i) block_state tmp_block_state; let h3 = ST.get () in c.state.frame_invariant #i (c.state.footprint h2 tmp_block_state) block_state h2 h3; stateful_frame_preserves_freeable #index #c.state #i (c.state.footprint h2 tmp_block_state) block_state h2 h3; optional_frame #_ #i #c.km #c.key (c.state.footprint h2 tmp_block_state) k' h2 h3; // Process as many blocks as possible (but leave at least one block for update_last) let prev_len = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 r) in // The data length to give to update_last [@inline_let] let r_last = rest_finish c i r in // The data length to process with update_multi before calling update_last [@inline_let] let r_multi = U32.(r -^ r_last) in // Split the buffer according to the computed lengths let buf_last = B.sub buf_ r_multi (Ghost.hide r_last) in let buf_multi = B.sub buf_ 0ul r_multi in [@inline_let] let state_is_block = c.block_len i = c.blocks_state_len i in assert(state_is_block ==> U32.v r_multi = 0); assert(state_is_block ==> r_last = r); // This will get simplified and will allow some simplifications in the generated code. // In particular, it should allow to simplify a bit update_multi [@inline_let] let r_multi = if state_is_block then 0ul else r_multi in [@inline_let] let r_last = if state_is_block then r else r_last in c.update_multi (G.hide i) tmp_block_state prev_len buf_multi r_multi; let h4 = get () in optional_frame #_ #i #c.km #c.key (c.state.footprint #i h3 tmp_block_state) k' h3 h4; // Functional correctness digest_process_begin_functional_correctness #index c i t t' state output l h0 h4 tmp_block_state; split_at_last_finish c i (all_seen c i h0 state); // Process the remaining data assert(UInt32.v r_last <= UInt32.v (Block?.block_len c (Ghost.reveal (Ghost.hide i)))); let prev_len_last = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 r_last) in begin // Proving: prev_len_last % block_len = 0 assert(U64.v prev_len_last = U64.v prev_len + U32.v r_multi); Math.Lemmas.modulo_distributivity (U64.v prev_len) (U32.v r_multi) (U32.v (c.block_len i)); Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); assert(U64.v prev_len_last % U32.v (c.block_len i) = 0) end; c.update_last (G.hide i) tmp_block_state prev_len_last buf_last r_last; let h5 = ST.get () in c.state.frame_invariant #i (c.state.footprint h3 tmp_block_state) block_state h3 h5; stateful_frame_preserves_freeable #index #c.state #i (c.state.footprint h3 tmp_block_state) block_state h3 h5; optional_frame #_ #i #c.km #c.key (c.state.footprint h3 tmp_block_state) k' h3 h5; c.finish (G.hide i) k' tmp_block_state output l; let h6 = ST.get () in begin let r = r_last in let all_seen = all_seen c i h0 state in let blocks_state_length = U32.v (c.blocks_state_len i) in let block_length = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem block_length (S.length all_seen)) in let blocks, rest_ = Lib.UpdateMulti.split_at_last_lazy block_length all_seen in let k = optional_reveal #_ #i #c.km #c.key h0 k' in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); assert(0 % U32.v (c.block_len i) = 0); assert(B.as_seq h3 buf_last == rest_); calc (S.equal) { B.as_seq h6 output; (S.equal) { } c.finish_s i k (c.state.v i h5 tmp_block_state) l; (S.equal) { } c.finish_s i k ( c.update_last_s i (c.state.v i h4 tmp_block_state) (n * block_length) (B.as_seq h4 buf_last)) l; (S.equal) { } c.finish_s i k ( c.update_last_s i (c.state.v i h4 tmp_block_state) (n * block_length) rest_) l; (S.equal) { } c.finish_s i k ( c.update_last_s i (c.update_multi_s i (c.init_s i k) 0 (S.slice all_seen 0 (n * block_length))) (n * block_length) rest_) l; (S.equal) { c.spec_is_incremental i k seen l } c.spec_s i k seen l; } end; c.state.frame_invariant #i B.(loc_buffer output `loc_union` c.state.footprint h5 tmp_block_state) block_state h5 h6; stateful_frame_preserves_freeable #index #c.state #i B.(loc_buffer output `loc_union` c.state.footprint h5 tmp_block_state) block_state h5 h6; optional_frame #_ #i #c.km #c.key B.(loc_buffer output `loc_union` c.state.footprint h5 tmp_block_state) k' h5 h6; pop_frame (); let h7 = ST.get () in c.state.frame_invariant #i B.(loc_region_only false (HS.get_tip h6)) block_state h6 h7; stateful_frame_preserves_freeable #index #c.state #i B.(loc_region_only false (HS.get_tip h6)) block_state h6 h7; optional_frame #_ #i #c.km #c.key B.(loc_region_only false (HS.get_tip h6)) k' h6 h7; assert (seen_h c i h7 state `S.equal` (G.reveal seen)); // JP: this is not the right way to prove do this proof. Need to use // modifies_fresh_frame_popped instead, see e.g. // https://github.com/project-everest/everquic-crypto/blob/d812be94e9b1a77261f001c9accb2040b80b7c39/src/QUIC.Impl.fst#L1111 // for an example let mloc = B.loc_union (B.loc_buffer output) (footprint c i h0 state) in B.modifies_remove_fresh_frame h0 h1 h7 mloc; B.popped_modifies h6 h7; assert (B.(modifies mloc h0 h7)) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> Hacl.Streaming.Functor.free_st c i t t')
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Hacl.Streaming.Spec.uint8", "LowStar.Monotonic.Buffer.free", "Hacl.Streaming.Functor.state_s", "Prims.unit", "Hacl.Streaming.Interface.__proj__Stateful__item__free", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_invariant", "Hacl.Streaming.Functor.optional_footprint", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_freeable", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.BufferOps.op_Bang_Star", "FStar.Pervasives.allow_inversion", "Hacl.Streaming.Interface.key_management" ]
[]
false
false
false
false
false
let free #index c i t t' state =
let _ = allow_inversion key_management in let open LowStar.BufferOps in let State block_state buf _ _ k' = !*state in let h0 = ST.get () in (match c.km with | Runtime -> c.key.free i k' | Erased -> ()); let h1 = ST.get () in c.state.frame_freeable #i (optional_footprint #index #i #c.km #c.key h0 k') block_state h0 h1; c.state.frame_invariant #i (optional_footprint #index #i #c.km #c.key h0 k') block_state h0 h1; c.state.free i block_state; B.free buf; B.free state
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.update
val update: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> update_st #index c i t t')
val update: #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> update_st #index c i t t')
let update #index c i t t' state chunk chunk_len = let open LowStar.BufferOps in let s = !*state in let State block_state buf_ total_len seen k' = s in let i = c.index_of_state i block_state in if FStar.UInt64.(FStar.Int.Cast.uint32_to_uint64 chunk_len >^ c.max_input_len i -^ total_len) then Hacl.Streaming.Types.MaximumLengthExceeded else let sz = rest c i total_len in if chunk_len `U32.lte` (c.blocks_state_len i `U32.sub` sz) then update_small c i t t' state chunk chunk_len else if sz = 0ul then update_empty_or_full_buf c i t t' state chunk chunk_len else begin let h0 = ST.get () in let diff = c.blocks_state_len i `U32.sub` sz in let chunk1 = B.sub chunk 0ul diff in let chunk2 = B.sub chunk diff (chunk_len `U32.sub` diff) in update_round c i t t' state chunk1 diff; let h1 = ST.get () in update_empty_or_full_buf c i t t' state chunk2 (chunk_len `U32.sub` diff); let h2 = ST.get () in ( let seen = G.reveal seen in assert (seen_h c i h1 state `S.equal` (S.append seen (B.as_seq h0 chunk1))); assert (seen_h c i h2 state `S.equal` (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2))); S.append_assoc seen (B.as_seq h0 chunk1) (B.as_seq h0 chunk2); assert (S.equal (S.append (B.as_seq h0 chunk1) (B.as_seq h0 chunk2)) (B.as_seq h0 chunk)); assert (S.equal (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2)) (S.append seen (B.as_seq h0 chunk))); assert (seen_h c i h2 state `S.equal` (S.append seen (B.as_seq h0 chunk))); () ) end; Hacl.Streaming.Types.Success
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 1529, "start_col": 0, "start_line": 1493 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)))))) let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1 /// Small helper which we use to factor out functional correctness proof obligations. /// It states that a state was correctly updated to process some data between two /// memory snapshots (the key is the same, the seen data was updated, etc.). /// /// Note that we don't specify anything about the buffer and the block_state: they /// might have been updated differently depending on the case. unfold val state_is_updated : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Type0) #push-options "--z3cliopt smt.arith.nl=false" let state_is_updated #index c i t t' p data len h0 h1 = // Functional conditions about the memory updates let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in block_state1 == block_state0 /\ buf1 == buf0 /\ U64.v total_len1 == U64.v total_len0 + U32.v len /\ key1 == key0 /\ seen1 `S.equal` (seen0 `S.append` (B.as_seq h0 data)) /\ optional_reveal #index #i #c.km #c.key h1 key1 == optional_reveal #index #i #c.km #c.key h0 key0 #pop-options /// The functional part of the invariant unfold val invariant_s_funct : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Pure Type0 (requires update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ state_is_updated c i t t' s data len h0 h1) (ensures (fun _ -> True))) let invariant_s_funct #index c i t t' p data len h0 h1 = let blocks, rest = split_at_last_all_seen c i h1 p in let s = B.get h1 p 0 in let State block_state buf_ total_len seen key = s in let key_v = optional_reveal #index #i #c.km #c.key h0 key in let init_s = c.init_s i key_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); c.state.v i h1 block_state == c.update_multi_s i init_s 0 blocks /\ S.equal (S.slice (B.as_seq h1 buf_) 0 (Seq.length rest)) rest /// We isolate the functional correctness proof obligations for [update_small] val update_small_functional_correctness : #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // The precondition of [small_update] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s)) /\ // Generic conditions state_is_updated c i t t' s data len h0 h1 /\ // Functional conditions about the memory updates begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let sz = rest c i total_len0 in let buf = buf0 in let data_v0 = B.as_seq h0 data in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in buf_part_v1 == S.append buf_beg_v0 data_v0 /\ c.state.v i h1 block_state1 == c.state.v i h0 block_state0 end )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #push-options "--z3cliopt smt.arith.nl=false" let update_small_functional_correctness #index c i t t' p data len h0 h1 = let s0 = B.get h0 p 0 in let s1 = B.get h1 p 0 in let State block_state buf total_len0 seen0 key = s0 in let seen0 = G.reveal seen0 in let i = Ghost.reveal i in let key_v0 = optional_reveal #_ #i #c.km #c.key h0 key in let init_v0 = c.init_input_s i key_v0 in let all_seen0 = S.append init_v0 seen0 in let blocks0, rest0 = split_at_last c i all_seen0 in let State block_state buf total_len1 seen1 key = s1 in let seen1 = G.reveal seen1 in let i = Ghost.reveal i in let key_v1 = optional_reveal #_ #i #c.km #c.key h1 key in assert(key_v1 == key_v0); let init_v1 = c.init_input_s i key_v1 in assert(init_v1 == init_v0); let all_seen1 = S.append init_v1 seen1 in let blocks1, rest1 = split_at_last c i all_seen1 in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); let data_v0 = B.as_seq h0 data in split_at_last_small c i all_seen0 data_v0; // The first problematic condition assert(blocks1 `S.equal` blocks0); assert(c.state.v i h1 block_state == c.update_multi_s i (c.init_s i key_v1) 0 blocks1); // The second problematic condition assert(S.equal (S.slice (B.as_seq h1 buf) 0 (Seq.length rest1)) rest1) #pop-options // The absence of loc_disjoint_includes makes reasoning a little more difficult. // Notably, we lose all of the important disjointness properties between the // outer point p and the buffer within B.deref h p. These need to be // re-established by hand. Another thing that we lose without this pattern is // knowing that loc_buffer b is included within loc_addr_of_buffer b. This is // important for reasoning about the preservation of e.g. the contents of data. #restart-solver #push-options "--z3rlimit 300 --z3cliopt smt.arith.nl=false --z3refresh \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2,-FStar.Seq.Properties.slice_slice,-LowStar.Monotonic.Buffer.loc_disjoint_includes_r'" let update_small #index c i t t' p data len = let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen_ k' = s in [@inline_let] let block_state: c.state.s i = block_state in // Functional reasoning. let sz = rest c i total_len in add_len_small c i total_len len; let h0 = ST.get () in let buf1 = B.sub buf 0ul sz in let buf2 = B.sub buf sz len in // Memory reasoning. c.state.invariant_loc_in_footprint h0 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h0 k'; // key_invariant_loc_in_footprint #index c i h0 p; B.(loc_disjoint_includes_r (loc_buffer data) (footprint c i h0 p) (loc_buffer buf2)); // FIRST STATEFUL OPERATION B.blit data 0ul buf2 0ul len; // Memory reasoning. let h1 = ST.get () in modifies_footprint c i p data len h0 h1; c.state.invariant_loc_in_footprint h1 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h1 k'; // Functional reasoning on data begin let buf1_v0 = B.as_seq h0 buf1 in let buf1_v1 = B.as_seq h1 buf1 in let buf2_v1 = B.as_seq h1 buf2 in let buf_beg_v0 = S.slice (B.as_seq h0 buf) 0 (U32.v sz) in let buf_part_v1 = S.slice (B.as_seq h1 buf) 0 (U32.v sz + U32.v len) in let data_v0 = B.as_seq h0 data in assert(buf1_v1 == buf1_v0); assert(buf1_v0 == buf_beg_v0); assert(buf2_v1 `S.equal` data_v0); assert(buf_part_v1 `S.equal` S.append buf_beg_v0 data_v0) end; // SECOND STATEFUL OPERATION let total_len = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len (G.hide (G.reveal seen_ `S.append` (B.as_seq h0 data))) k' in p *= tmp; // Memory reasoning. let h2 = ST.get () in modifies_footprint' c i p data len h1 h2; c.state.invariant_loc_in_footprint h2 block_state; if c.km = Runtime then c.key.invariant_loc_in_footprint #i h2 k'; ST.lemma_equal_domains_trans h0 h1 h2; // Prove the invariant update_small_functional_correctness c i t t' p data len h0 h2 #pop-options // Stupid name collisions noextract let seen_h = seen noextract let all_seen_h = all_seen /// Case 2: we have no buffered data (ie: the buffer was just initialized), or the /// internal buffer is full meaning that we can just hash it to go to the case where /// there is no buffered data. Of course, the data we append has to be non-empty, /// otherwise we might end-up with an empty internal buffer. /// Auxiliary lemma which groups the functional correctness proof obligations /// for [update_empty_or_full]. #push-options "--z3cliopt smt.arith.nl=false" val update_empty_or_full_functional_correctness : #index:Type0 -> c:block index -> i:G.erased index -> ( let i = G.reveal i in t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer Lib.IntTypes.uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( // Same precondition as [update_empty_or_full_buf] update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ (rest c i (total_len_h c i h0 s) = 0ul \/ rest c i (total_len_h c i h0 s) = c.blocks_state_len i) /\ U32.v len > 0 /\ // Generic additional preconditions state_is_updated c i t t' s data len h0 h1 /\ // Additional preconditions begin let s0 = B.get h0 s 0 in let s1 = B.get h1 s 0 in let State block_state0 buf0 total_len0 seen0 key0 = s0 in let State block_state1 buf1 total_len1 seen1 key1 = s1 in let seen0 = G.reveal seen0 in let seen1 = G.reveal seen1 in let block_state = block_state0 in let buf = buf0 in let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.v n_blocks * U32.v (c.blocks_state_len i) <= U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.gsub data 0ul data1_len in let data2 = B.gsub data data1_len data2_len in let all_seen0 = all_seen c i h0 s in let all_seen1 = all_seen c i h1 s in let blocks0, res0 = split_at_last c i all_seen0 in let blocks1, res1 = split_at_last c i all_seen1 in let data1_v = B.as_seq h0 data1 in let data2_v = B.as_seq h0 data2 in let key = optional_reveal #index #i #c.km #c.key h0 key0 in let init_s = c.init_s i key in let all_seen_data1 = S.append all_seen0 data1_v in (**) Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); S.length all_seen0 % U32.v (c.block_len i) = 0 /\ // TODO: should be proved automatically S.length all_seen_data1 % U32.v (c.block_len i) = 0 /\ // TODO: should be proved automatically c.state.v i h1 block_state == c.update_multi_s i init_s 0 all_seen_data1 /\ S.slice (B.as_seq h1 buf) 0 (Seq.length data2_v) `S.equal` data2_v /\ True end /\ True )) (ensures (invariant_s_funct c i t t' s data len h0 h1))) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let update_empty_or_full_functional_correctness #index c i t t' p data len h0 h1 = let s = B.get h0 p 0 in let State block_state buf_ total_len seen0 key = s in let init_s = c.init_s i (optional_reveal #index #i #c.km #c.key h0 key) in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.gsub data 0ul data1_len in let data2 = B.gsub data data1_len data2_len in let data_v = B.as_seq h0 data in let init_input = init_input c i h0 p in let seen1 = seen c i h1 p in let all_seen0 = all_seen c i h0 p in let all_seen1 = all_seen c i h1 p in let blocks0, rest0 = split_at_last_all_seen c i h0 p in let blocks1, rest1 = split_at_last_all_seen c i h1 p in let data_blocks, data_rest = split_at_last c i data_v in split_at_last_blocks c i all_seen0 data_v; assert(Seq.equal all_seen1 (S.append all_seen0 data_v)); assert(S.equal blocks1 (S.append all_seen0 data_blocks)); assert(S.equal data_rest rest1) #pop-options inline_for_extraction noextract val update_empty_or_full_buf: #index:Type0 -> c:block index -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer Lib.IntTypes.uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ (rest c i (total_len_h c i h0 s) = 0ul \/ rest c i (total_len_h c i h0 s) = c.blocks_state_len i) /\ U32.v len > 0) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) #push-options "--z3cliopt smt.arith.nl=false --z3rlimit 500" let update_empty_or_full_buf #index c i t t' p data len = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in [@inline_let] let _ = c.update_multi_associative i in let open LowStar.BufferOps in let s = !*p in let State block_state buf total_len seen k' = s in [@inline_let] let block_state: c.state.s i = block_state in let sz = rest c i total_len in let h0 = ST.get () in Math.Lemmas.modulo_lemma 0 (U32.v (c.block_len i)); assert(0 % U32.v (c.block_len i) = 0); let init_key : Ghost.erased _ = optional_reveal h0 (k' <: optional_key i c.km c.key) in let init_state : Ghost.erased _ = c.init_s i init_key in assert( let all_seen = all_seen c i h0 p in let blocks, rest = split_at_last c i all_seen in Seq.length rest = U32.v sz /\ c.state.v i h0 block_state == c.update_multi_s i init_state 0 blocks); (* Start by "flushing" the buffer: hash it so that all the data seen so far * has been processed and we can consider the buffer as empty *) if U32.(sz =^ 0ul) then begin assert( let all_seen = all_seen c i h0 p in c.state.v i h0 block_state == c.update_multi_s i init_state 0 all_seen) end else begin let prevlen = U64.(total_len `sub` FStar.Int.Cast.uint32_to_uint64 sz) in c.update_multi (G.hide i) block_state prevlen buf (c.blocks_state_len i); begin let h1 = ST.get () in let all_seen = all_seen c i h0 p in let blocks, rest = split_at_last c i all_seen in assert(Seq.length blocks = U64.v prevlen); assert(c.state.v i h0 block_state == c.update_multi_s i init_state 0 blocks); assert(c.state.v i h1 block_state == c.update_multi_s i (c.update_multi_s i init_state 0 blocks) (U64.v prevlen) rest); assert(all_seen `Seq.equal` Seq.append blocks rest); (* TODO: the pattern of ``update_multi_associative`` is not triggered *) c.update_multi_associative i init_state 0 (U64.v prevlen) blocks rest; assert(c.state.v i h1 block_state == c.update_multi_s i init_state 0 all_seen) end end; let h1 = ST.get () in assert( let all_seen = all_seen c i h0 p in c.state.v i h1 block_state == c.update_multi_s i init_state 0 all_seen); split_at_last_blocks c i (all_seen c i h0 p) (B.as_seq h0 data); // TODO: remove? let n_blocks = nblocks c i len in (**) split_at_last_num_blocks_lem c i (U32.v len); (**) assert(U32.(FStar.UInt.size (v n_blocks * v (c.blocks_state_len i)) n)); let data1_len = n_blocks `U32.mul` c.blocks_state_len i in let data2_len = len `U32.sub` data1_len in let data1 = B.sub data 0ul data1_len in let data2 = B.sub data data1_len data2_len in c.update_multi (G.hide i) block_state total_len data1 data1_len; let h01 = ST.get () in optional_frame #_ #i #c.km #c.key (c.state.footprint h0 block_state) k' h0 h01; assert(preserves_freeable c i p h0 h01); begin let all_seen = all_seen c i h0 p in let data1_v = B.as_seq h01 data1 in c.update_multi_associative i init_state 0 (Seq.length all_seen) all_seen data1_v; assert(c.state.v i h01 block_state == c.update_multi_s i init_state 0 (Seq.append all_seen data1_v)) end; let dst = B.sub buf 0ul data2_len in let h1 = ST.get () in B.blit data2 0ul dst 0ul data2_len; let h2 = ST.get () in c.state.frame_invariant (B.loc_buffer buf) block_state h1 h2; optional_frame #_ #i #c.km #c.key (B.loc_buffer buf) k' h1 h2; stateful_frame_preserves_freeable #index #(Block?.state c) #i (B.loc_buffer dst) (State?.block_state s) h1 h2; assert(preserves_freeable c i p h01 h2); [@inline_let] let total_len' = add_len c i total_len len in [@inline_let] let tmp: state_s c i t t' = State #index #c #i block_state buf total_len' (seen `S.append` B.as_seq h0 data) k' in p *= tmp; let h3 = ST.get () in c.state.frame_invariant (B.loc_buffer p) block_state h2 h3; optional_frame #_ #i #c.km #c.key (B.loc_buffer p) k' h2 h3; stateful_frame_preserves_freeable #index #(Block?.state c) #i (B.loc_buffer p) (State?.block_state s) h2 h3; assert(preserves_freeable c i p h2 h3); assert(preserves_freeable c i p h0 h3); update_empty_or_full_functional_correctness #index c i t t' p data len h0 h3; (* The following proof obligation is the difficult one - keep it here for * easy debugging when updating the definitions/proofs *) assert(invariant_s c i h3 (B.get h3 p 0)) #pop-options /// Case 3: we are given just enough data to end up on the boundary. It is just /// a sub-case of [update_small], but with a little bit more precise pre and post /// conditions. inline_for_extraction noextract val update_round: #index:Type0 -> c:block index -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ ( let r = rest c i (total_len_h c i h0 s) in U32.v len + U32.v r = U32.v (c.blocks_state_len i) /\ r <> 0ul)) (ensures fun h0 _ h1 -> update_post c i s data len h0 h1 /\ begin let blocks, rest = split_at_last_all_seen c i h0 s in let blocks', rest' = split_at_last_all_seen c i h1 s in blocks' `S.equal` blocks /\ rest' `S.equal` S.append rest (B.as_seq h0 data) /\ S.length rest' = U32.v (c.blocks_state_len i) end)) #push-options "--z3rlimit 200 --z3cliopt smt.arith.nl=false" let update_round #index c i t t' p data len = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.update_multi_associative i in let open LowStar.BufferOps in (**) let h0 = ST.get() in update_small #index c i t t' p data len; (**) let h1 = ST.get() in (**) split_at_last_small c i (all_seen c i h0 p) (B.as_seq h0 data); (**) begin // For some reason, the proof fails if we don't call those (**) let blocks, rest = split_at_last_all_seen c i h0 p in (**) let blocks', rest' = split_at_last_all_seen c i h1 p in (**) () (**) end #pop-options /// General update function, as a decomposition of the three sub-cases /// ==================================================================
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in t: Type0{t == Stateful?.s (Block?.state c) i} -> t': Type0{t' == Hacl.Streaming.Interface.optional_key i (Block?.km c) (Block?.key c)} -> Hacl.Streaming.Functor.update_st c i t t')
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "FStar.Ghost.reveal", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Functor.state", "LowStar.Buffer.buffer", "Hacl.Streaming.Spec.uint8", "FStar.UInt32.t", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "FStar.UInt64.op_Greater_Hat", "FStar.Int.Cast.uint32_to_uint64", "FStar.UInt64.op_Subtraction_Hat", "Hacl.Streaming.Interface.__proj__Block__item__max_input_len", "Hacl.Streaming.Types.MaximumLengthExceeded", "Hacl.Streaming.Types.error_code", "Prims.bool", "Hacl.Streaming.Types.Success", "Prims.unit", "FStar.UInt32.lte", "FStar.UInt32.sub", "Hacl.Streaming.Functor.update_small", "FStar.UInt32.__uint_to_t", "Hacl.Streaming.Functor.update_empty_or_full_buf", "Prims._assert", "FStar.Seq.Base.equal", "Hacl.Streaming.Functor.seen_h", "FStar.Seq.Base.append", "LowStar.Monotonic.Buffer.as_seq", "FStar.Seq.Base.append_assoc", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Streaming.Functor.update_round", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "Hacl.Streaming.Spec.split_at_last_num_blocks", "FStar.UInt64.v", "FStar.UInt32.v", "Prims.int", "Prims.op_Subtraction", "Hacl.Streaming.Functor.rest", "Hacl.Streaming.Interface.__proj__Block__item__index_of_state", "Hacl.Streaming.Functor.state_s", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
false
false
false
false
let update #index c i t t' state chunk chunk_len =
let open LowStar.BufferOps in let s = !*state in let State block_state buf_ total_len seen k' = s in let i = c.index_of_state i block_state in if let open FStar.UInt64 in FStar.Int.Cast.uint32_to_uint64 chunk_len >^ c.max_input_len i -^ total_len then Hacl.Streaming.Types.MaximumLengthExceeded else let sz = rest c i total_len in if chunk_len `U32.lte` ((c.blocks_state_len i) `U32.sub` sz) then update_small c i t t' state chunk chunk_len else if sz = 0ul then update_empty_or_full_buf c i t t' state chunk chunk_len else (let h0 = ST.get () in let diff = (c.blocks_state_len i) `U32.sub` sz in let chunk1 = B.sub chunk 0ul diff in let chunk2 = B.sub chunk diff (chunk_len `U32.sub` diff) in update_round c i t t' state chunk1 diff; let h1 = ST.get () in update_empty_or_full_buf c i t t' state chunk2 (chunk_len `U32.sub` diff); let h2 = ST.get () in (let seen = G.reveal seen in assert ((seen_h c i h1 state) `S.equal` (S.append seen (B.as_seq h0 chunk1))); assert ((seen_h c i h2 state) `S.equal` (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2))); S.append_assoc seen (B.as_seq h0 chunk1) (B.as_seq h0 chunk2); assert (S.equal (S.append (B.as_seq h0 chunk1) (B.as_seq h0 chunk2)) (B.as_seq h0 chunk)); assert (S.equal (S.append (S.append seen (B.as_seq h0 chunk1)) (B.as_seq h0 chunk2)) (S.append seen (B.as_seq h0 chunk))); assert ((seen_h c i h2 state) `S.equal` (S.append seen (B.as_seq h0 chunk))); ())); Hacl.Streaming.Types.Success
false
LowParse.Low.VCList.fst
LowParse.Low.VCList.valid_nlist_nil_recip
val valid_nlist_nil_recip (#k: parser_kind) (#t: Type) (p: parser k t) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_nlist 0 p) h sl pos)) (ensures (valid_content_pos (parse_nlist 0 p) h sl pos [] pos))
val valid_nlist_nil_recip (#k: parser_kind) (#t: Type) (p: parser k t) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_nlist 0 p) h sl pos)) (ensures (valid_content_pos (parse_nlist 0 p) h sl pos [] pos))
let valid_nlist_nil_recip (#k: parser_kind) (#t: Type) (p: parser k t) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_nlist 0 p) h sl pos)) (ensures (valid_content_pos (parse_nlist 0 p) h sl pos [] pos)) = valid_facts (parse_nlist 0 p) h sl pos; parse_nlist_eq 0 p (bytes_of_slice_from h sl pos)
{ "file_name": "src/lowparse/LowParse.Low.VCList.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 51, "end_line": 39, "start_col": 0, "start_line": 27 }
module LowParse.Low.VCList include LowParse.Spec.VCList include LowParse.Low.List module L = FStar.List.Tot module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module B = LowStar.Buffer module Cast = FStar.Int.Cast module U64 = FStar.UInt64 let valid_nlist_nil (#k: parser_kind) (#t: Type) (p: parser k t) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (live_slice h sl /\ U32.v pos <= U32.v sl.len)) (ensures (valid_content_pos (parse_nlist 0 p) h sl pos [] pos)) = valid_facts (parse_nlist 0 p) h sl pos; parse_nlist_eq 0 p (bytes_of_slice_from h sl pos)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.VCList.fsti.checked", "LowParse.Low.List.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.VCList.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Low.List", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VCList", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.VCList.parse_nlist 0 p) h sl pos) (ensures LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VCList.parse_nlist 0 p) h sl pos [] pos)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.VCList.parse_nlist_eq", "LowParse.Slice.bytes_of_slice_from", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.VCList.parse_nlist_kind", "LowParse.Spec.VCList.nlist", "LowParse.Spec.VCList.parse_nlist", "LowParse.Low.Base.Spec.valid", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let valid_nlist_nil_recip (#k: parser_kind) (#t: Type) (p: parser k t) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_nlist 0 p) h sl pos)) (ensures (valid_content_pos (parse_nlist 0 p) h sl pos [] pos)) =
valid_facts (parse_nlist 0 p) h sl pos; parse_nlist_eq 0 p (bytes_of_slice_from h sl pos)
false
Hacl.Streaming.Functor.fst
Hacl.Streaming.Functor.modifies_footprint'
val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none))))))
val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none))))))
let modifies_footprint' c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1
{ "file_name": "code/streaming/Hacl.Streaming.Functor.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 962, "start_col": 0, "start_line": 950 }
module Hacl.Streaming.Functor /// Provided an instance of the type class, this creates a streaming API on top. /// This means that every function in this module takes two extra arguments /// compared to the previous streaming module specialized for hashes: the type /// of the index, and a type class for that index. Then, as usual, a given value /// for the index as a parameter. #set-options "--max_fuel 0 --max_ifuel 0 \ --using_facts_from '*,-LowStar.Monotonic.Buffer.unused_in_not_unused_in_disjoint_2' --z3rlimit 50" module ST = FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module U32 = FStar.UInt32 module U64 = FStar.UInt64 open Hacl.Streaming.Interface open FStar.HyperStack.ST open LowStar.BufferOps open FStar.Mul open Hacl.Streaming.Spec /// State machinery /// =============== /// Little bit of trickery here to make sure state_s is parameterized over /// something at Type0, not Type0 -> Type0 -- otherwise it wouldn't monomorphize /// in KaRaMeL. noeq type state_s #index (c: block index) (i: index) (t: Type0 { t == c.state.s i }) (t': Type0 { t' == optional_key i c.km c.key }) = | State: block_state: t -> buf: B.buffer Lib.IntTypes.uint8 { B.len buf = c.blocks_state_len i } -> total_len: UInt64.t -> seen: G.erased (S.seq uint8) -> // Stupid name conflict on overloaded projectors leads to inscrutable // interleaving errors. Need a field name that does not conflict with the // one in Hacl.Streaming.Interface. Sigh!! p_key: t' -> state_s #index c i t t' /// Defining a series of helpers to deal with the indexed type of the key. This /// makes proofs easier. let optional_freeable #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.freeable #i h k let optional_invariant #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> True | Runtime -> key.invariant #i h k let optional_footprint #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> B.loc_none | Runtime -> key.footprint #i h k let optional_reveal #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: optional_key i km key) = allow_inversion key_management; match km with | Erased -> G.reveal k | Runtime -> key.v i h k let optional_hide #index (#i: index) (#km: key_management) (#key: stateful index) (h: HS.mem) (k: key.s i): optional_key i km key = allow_inversion key_management; match km with | Erased -> G.hide (key.v i h k) | Runtime -> k /// This lemma is used to convert the Hacl.Streaming.Interface.stateful.frame_freeable /// lemma, written with freeable in its precondition, into a lemma of the form: /// [> freeable h0 s => freeable h1 s val stateful_frame_preserves_freeable: #index:Type0 -> #sc:stateful index -> #i:index -> l:B.loc -> s:sc.s i -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( sc.freeable h0 s ==> sc.freeable h1 s)) let stateful_frame_preserves_freeable #index #sc #i l s h0 h1 = let lem h0 h1 : Lemma (requires ( sc.invariant h0 s /\ B.loc_disjoint l (sc.footprint h0 s) /\ B.modifies l h0 h1 /\ sc.freeable h0 s)) (ensures ( sc.freeable h1 s)) [SMTPat (sc.freeable h0 s); SMTPat (sc.freeable h1 s)] = sc.frame_freeable l s h0 h1 in () let optional_frame #index (#i: index) (#km: key_management) (#key: stateful index) (l: B.loc) (s: optional_key i km key) (h0 h1: HS.mem): Lemma (requires ( optional_invariant h0 s /\ B.loc_disjoint l (optional_footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( optional_invariant h1 s /\ optional_reveal h0 s == optional_reveal h1 s /\ optional_footprint h1 s == optional_footprint h0 s /\ (optional_freeable h0 s ==> optional_freeable h1 s))) = allow_inversion key_management; match km with | Erased -> () | Runtime -> key.frame_invariant #i l s h0 h1; stateful_frame_preserves_freeable #index #key #i l s h0 h1 let footprint_s #index (c: block index) (i: index) (h: HS.mem) s = let State block_state buf_ _ _ p_key = s in B.(loc_addr_of_buffer buf_ `loc_union` c.state.footprint h block_state `loc_union` optional_footprint h p_key) /// Invariants /// ========== #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let invariant_s #index (c: block index) (i: index) h s = let State block_state buf_ total_len seen key = s in let seen = G.reveal seen in let key_v = optional_reveal h key in let all_seen = S.append (c.init_input_s i key_v) seen in let blocks, rest = split_at_last c i all_seen in (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % U32.v (Block?.block_len c i) = 0); (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.blocks_state_len c i)); (**) assert(0 % U32.v (Block?.blocks_state_len c i) = 0); // Liveness and disjointness (administrative) B.live h buf_ /\ c.state.invariant #i h block_state /\ optional_invariant h key /\ B.(loc_disjoint (loc_buffer buf_) (c.state.footprint h block_state)) /\ B.(loc_disjoint (loc_buffer buf_) (optional_footprint h key)) /\ B.(loc_disjoint (optional_footprint h key) (c.state.footprint h block_state)) /\ // Formerly, the "hashes" predicate S.length blocks + S.length rest = U64.v total_len /\ U32.v (c.init_input_len i) + S.length seen = U64.v total_len /\ U64.v total_len <= U64.v (c.max_input_len i) /\ // Note the double equals here, we now no longer know that this is a sequence. c.state.v i h block_state == c.update_multi_s i (c.init_s i key_v) 0 blocks /\ S.equal (S.slice (B.as_seq h buf_) 0 (Seq.length rest)) rest #pop-options inline_for_extraction noextract let freeable_s (#index: Type0) (c: block index) (i: index) (h: HS.mem) (s: state_s' c i): Type0 = let State block_state buf_ total_len seen key = s in B.freeable buf_ /\ c.state.freeable h block_state /\ optional_freeable h key let freeable (#index : Type0) (c: block index) (i: index) (h: HS.mem) (s: state' c i) = freeable_s c i h (B.get h s 0) /\ B.freeable s #push-options "--max_ifuel 1" let invariant_loc_in_footprint #index c i s m = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in () #pop-options let seen #index c i h s = G.reveal (State?.seen (B.deref h s)) let seen_bounded #index c i h s = () let reveal_key #index c i h s = optional_reveal h (State?.p_key (B.deref h s)) let init_input (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = c.init_input_s i (reveal_key c i h s) let all_seen (#index:Type0) (c:block index) (i:index) (h:HS.mem) (s:state' c i) : GTot bytes = S.append (init_input c i h s) (seen c i h s) let frame_invariant #index c i l s h0 h1 = let state_t = B.deref h0 s in let State block_state _ _ _ p_key = state_t in c.state.frame_invariant #i l block_state h0 h1; stateful_frame_preserves_freeable #index #c.state #i l block_state h0 h1; allow_inversion key_management; match c.km with | Erased -> () | Runtime -> stateful_frame_preserves_freeable #index #c.key #i l p_key h0 h1; c.key.frame_invariant #i l p_key h0 h1 let frame_seen #_ _ _ _ _ _ _ = () /// Stateful API /// ============ let index_of_state #index c i t t' s = let open LowStar.BufferOps in let State block_state _ _ _ _ = !*s in c.index_of_state i block_state let seen_length #index c i t t' s = let open LowStar.BufferOps in let State _ _ total_len _ _ = !*s in total_len (* TODO: malloc and alloca have big portions of proofs in common, so it may * be possible to factorize them, but it is not clear how *) #restart-solver #push-options "--z3rlimit 500" let malloc #index c i t t' key r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none key h0 h1; let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none key h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none key h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) c.state.frame_freeable B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 key); (**) assert B.(loc_disjoint (c.key.footprint #i h3 key) (c.key.footprint #i h3 k')); c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') key h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 key) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none key h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) key buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let s = B.get h8 p 0 in (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true r) (footprint c i h8 p)); (**) assert (ST.equal_stack_domains h1 h8); (**) assert (ST.equal_stack_domains h0 h1); p #pop-options #push-options "--z3rlimit 100" let copy #index c i t t' state r = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; // All source state is suffixed by 0. let State block_state0 buf0 total_len0 seen0 k0 = !*state in let i = c.index_of_state i block_state0 in (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.malloc r (Lib.IntTypes.u8 0) (c.blocks_state_len i) in B.blit buf0 0ul buf 0ul (c.blocks_state_len i); (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h0 h1; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h1 state); let block_state = c.state.create_in i r in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h1 h2; (**) c.state.frame_invariant #i B.loc_none block_state0 h0 h1; (**) assert (invariant c i h2 state); c.state.copy (G.hide i) block_state0 block_state; (**) let h2 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) if c.km = Runtime then (**) c.key.frame_invariant #i (c.state.footprint #i h2 block_state) k0 h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.create_in i r in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant #i B.loc_none k0 h2 h3; (**) c.state.frame_invariant #i B.loc_none block_state h2 h3; (**) c.state.frame_freeable #i B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k0); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k0) (c.key.footprint #i h3 k')); c.key.copy i k0 k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant #i (c.key.footprint #i h3 k') k0 h3 h4; (**) c.state.frame_invariant #i (c.key.footprint #i h3 k') block_state h3 h4; (**) c.state.frame_freeable #i (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> k0 in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); let s = State block_state buf total_len0 seen0 k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.malloc r s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) if c.km = Runtime then (**) c.key.frame_invariant #i B.loc_none k0 h5 h6; (**) c.state.frame_invariant #i B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) c.state.frame_freeable B.loc_none block_state h5 h6; (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); p #pop-options #push-options "--z3rlimit 200" let alloca #index c i t t' k = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; (**) let h0 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h0; let buf = B.alloca (Lib.IntTypes.u8 0) (c.blocks_state_len i) in (**) let h1 = ST.get () in (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h1); (**) B.loc_unused_in_not_unused_in_disjoint h1; (**) B.(modifies_only_not_unused_in loc_none h0 h1); (**) c.key.frame_invariant B.loc_none k h0 h1; let block_state = c.state.alloca i in (**) let h2 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h2 block_state) h0 h2); (**) B.loc_unused_in_not_unused_in_disjoint h2; (**) B.(modifies_only_not_unused_in loc_none h1 h2); (**) c.key.frame_invariant B.loc_none k h1 h2; let k': optional_key i c.km c.key = match c.km with | Runtime -> let k' = c.key.alloca i in (**) let h3 = ST.get () in (**) B.loc_unused_in_not_unused_in_disjoint h3; (**) B.(modifies_only_not_unused_in loc_none h2 h3); (**) c.key.frame_invariant B.loc_none k h2 h3; (**) c.state.frame_invariant B.loc_none block_state h2 h3; (**) assert (B.fresh_loc (c.key.footprint #i h3 k') h0 h3); (**) assert (c.key.invariant #i h3 k'); (**) assert (c.key.invariant #i h3 k); (**) assert B.(loc_disjoint (c.key.footprint #i h3 k) (c.key.footprint #i h3 k')); c.key.copy i k k'; (**) let h4 = ST.get () in (**) assert (B.fresh_loc (c.key.footprint #i h4 k') h0 h4); (**) B.loc_unused_in_not_unused_in_disjoint h4; (**) B.(modifies_only_not_unused_in loc_none h2 h4); (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h3 k') k h3 h4; (**) c.state.frame_invariant (c.key.footprint #i h3 k') block_state h3 h4; k' | Erased -> G.hide (c.key.v i h0 k) in (**) let h5 = ST.get () in (**) assert (B.fresh_loc (optional_footprint h5 k') h0 h5); (**) assert (B.fresh_loc (c.state.footprint #i h5 block_state) h0 h5); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let s = State block_state buf total_len (G.hide S.empty) k' in (**) assert (B.fresh_loc (footprint_s c i h5 s) h0 h5); (**) B.loc_unused_in_not_unused_in_disjoint h5; let p = B.alloca s 1ul in (**) let h6 = ST.get () in (**) B.(modifies_only_not_unused_in loc_none h5 h6); (**) B.(modifies_only_not_unused_in loc_none h0 h6); (**) c.key.frame_invariant B.loc_none k h5 h6; (**) c.state.frame_invariant B.loc_none block_state h5 h6; (**) optional_frame B.loc_none k' h5 h6; (**) assert (B.fresh_loc (B.loc_addr_of_buffer p) h0 h6); (**) assert (B.fresh_loc (footprint_s c i h6 s) h0 h6); (**) assert (optional_reveal h5 k' == optional_reveal h6 k'); c.init (G.hide i) k buf block_state; (**) let h7 = ST.get () in (**) assert (B.fresh_loc (c.state.footprint #i h7 block_state) h0 h7); (**) assert (B.fresh_loc (B.loc_buffer buf) h0 h7); (**) optional_frame (B.loc_union (c.state.footprint #i h7 block_state) (B.loc_buffer buf)) k' h6 h7; (**) c.update_multi_zero i (c.state.v i h7 block_state) 0; (**) B.modifies_only_not_unused_in B.loc_none h0 h7; (**) assert (c.state.v i h7 block_state == c.init_s i (optional_reveal h6 k')); (**) let h8 = ST.get () in (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h8 p in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert(invariant_s c i h8 s) (**) end; (**) assert (invariant c i h8 p); (**) assert (seen c i h8 p == S.empty); (**) assert B.(modifies loc_none h0 h8); (**) assert (B.fresh_loc (footprint c i h8 p) h0 h8); (**) assert B.(loc_includes (loc_region_only true (HS.get_tip h8)) (footprint c i h8 p)); (**) assert(ST.same_refs_in_non_tip_regions h0 h8); p #pop-options #push-options "--z3cliopt smt.arith.nl=false" let reset #index c i t t' state key = [@inline_let] let _ = c.state.invariant_loc_in_footprint #i in [@inline_let] let _ = c.key.invariant_loc_in_footprint #i in allow_inversion key_management; let open LowStar.BufferOps in (**) let h1 = ST.get () in let State block_state buf _ _ k' = !*state in let i = c.index_of_state i block_state in LowStar.Ignore.ignore i; // This is only used in types and proofs [@inline_let] let block_state: c.state.s i = block_state in c.init (G.hide i) key buf block_state; (**) let h2 = ST.get () in (**) optional_frame #_ #i #c.km #c.key (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) k' h1 h2; (**) c.key.frame_invariant (B.loc_union (c.state.footprint #i h1 block_state) (B.loc_buffer buf)) key h1 h2; (**) Math.Lemmas.modulo_lemma 0 (U32.v (Block?.block_len c i)); (**) assert(0 % UInt32.v (Block?.block_len c i) = 0); (**) assert (reveal_key c i h1 state == reveal_key c i h2 state); (**) c.update_multi_zero i (c.state.v i h2 block_state) 0; let k': optional_key i c.km c.key = match c.km with | Runtime -> c.key.copy i key k'; (**) let h4 = ST.get () in (**) assert (c.key.invariant #i h4 k'); (**) c.key.frame_invariant (c.key.footprint #i h2 k') key h2 h4; (**) c.state.frame_invariant (c.key.footprint #i h2 k') block_state h2 h4; (**) stateful_frame_preserves_freeable (c.key.footprint #i h2 k') block_state h2 h4; k' | Erased -> G.hide (c.key.v i h1 key) in (**) let h2 = ST.get () in (**) assert(preserves_freeable c i state h1 h2); [@inline_let] let total_len = Int.Cast.uint32_to_uint64 (c.init_input_len i) in let tmp: state_s c i t t' = State block_state buf total_len (G.hide S.empty) k' in B.upd state 0ul tmp; (**) let h3 = ST.get () in (**) c.state.frame_invariant B.(loc_buffer state) block_state h2 h3; (**) c.key.frame_invariant B.(loc_buffer state) key h2 h3; (**) optional_frame #_ #i #c.km #c.key B.(loc_buffer state) k' h2 h3; (**) stateful_frame_preserves_freeable B.(loc_buffer state) block_state h2 h3; (**) assert(preserves_freeable c i state h2 h3); // This seems to cause insurmountable difficulties. Puzzled. ST.lemma_equal_domains_trans h1 h2 h3; // AR: 07/22: same old `Seq.equal` and `==` story (**) assert (Seq.equal (seen c i h3 state) Seq.empty); (**) assert (footprint c i h1 state == footprint c i h3 state); (**) assert (B.(modifies (footprint c i h1 state) h1 h3)); (**) assert (U64.v total_len <= U64.v (c.max_input_len i)); (**) begin (**) let key_v = reveal_key c i h3 state in (**) let all_seen_ = all_seen c i h3 state in // SH (11/22): the proof fails if we don't introduce the call to [split_at_last] (**) let blocks, rest = split_at_last c i all_seen_ in (**) let init_input = c.init_input_s i key_v in (**) split_at_last_init c i init_input; (**) assert (invariant_s c i h3 (B.get h3 state 0)) (**) end; (**) assert(preserves_freeable c i state h1 h3) #pop-options /// Some helpers to minimize modulo-reasoning /// ========================================= val split_at_last_num_blocks_lem (#index : Type0) (c: block index) (i: index) (b: nat): Lemma ( let n_blocks = split_at_last_num_blocks c i b in let blocks = n_blocks * U32.v (c.blocks_state_len i) in 0 <= blocks /\ blocks <= b) let split_at_last_num_blocks_lem #index c i b = () /// The ``rest`` function below allows computing, based ``total_len`` stored in /// the state, the length of useful data currently stored in ``buf``. /// Unsurprisingly, there's a fair amount of modulo reasoning here because of /// 64-bit-to-32-bit conversions, so we do them once and for all in a helper. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest #index (c: block index) (i: index) (total_len: UInt64.t): (x:UInt32.t { let n = split_at_last_num_blocks c i (U64.v total_len) in let l = U32.v (c.blocks_state_len i) in 0 <= n * l /\ n * l <= U64.v total_len /\ U32.v x = U64.v total_len - (n * l)}) = let open FStar.Int.Cast in [@inline_let] let l = uint32_to_uint64 (c.blocks_state_len i) in [@inline_let] let r = total_len `U64.rem` l in (**) let total_len_v : Ghost.erased nat = U64.v total_len in (**) let l_v : Ghost.erased nat = U64.v l in (**) let r_v : Ghost.erased nat = U64.v r in (**) assert(Ghost.reveal r_v = total_len_v - ((total_len_v / l_v) * l_v)); (**) Math.Lemmas.euclidean_division_definition total_len_v l_v; (**) assert(Ghost.reveal r_v = total_len_v % l_v); (**) assert(r_v < l_v); if U64.(r =^ uint_to_t 0) && U64.(total_len >^ uint_to_t 0) then begin (**) split_at_last_num_blocks_lem c i (U64.v total_len); c.blocks_state_len i end else begin [@inline_let] let r' = FStar.Int.Cast.uint64_to_uint32 r in (**) FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32); (**) calc (==) { (**) U32.v r'; (**) (==) { } (**) U64.v r % pow2 32; (**) (==) { FStar.Math.Lemmas.small_modulo_lemma_1 (U64.v r) (pow2 32) } (**) U64.v r; (**) (==) { FStar.Math.Lemmas.euclidean_division_definition (U64.v total_len) (U64.v (uint32_to_uint64 (c.blocks_state_len i))) } (**) U64.v total_len % U64.v (uint32_to_uint64 (c.blocks_state_len i) ); (**) (==) { } (**) U64.v total_len % U32.v (c.blocks_state_len i); (**) }; (**) assert( (**) let n = split_at_last_num_blocks c i (U64.v total_len) in (**) let l = U32.v (c.blocks_state_len i) in (**) U32.v r' = U64.v total_len - (n * l)); r' end #pop-options /// The ``nblocks`` function below allows computing, given ``total_len`` stored in /// the state, the number of blocks of data which have been processed (the remaining /// unprocessed data being left in ``buf``). #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let nblocks #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.blocks_state_len i) in U32.v x * l <= U32.v len /\ U32.v x = split_at_last_num_blocks c i (U32.v len) }) = let open FStar.Int.Cast in [@inline_let] let l = c.blocks_state_len i in [@inline_let] let r = rest c i (uint32_to_uint64 len) in (**) let len_v : Ghost.erased nat = U32.v len in (**) let l_v : Ghost.erased nat = U32.v l in (**) let r_v : Ghost.erased nat = U32.v r in (**) let n_s : Ghost.erased nat = split_at_last_num_blocks c i len_v in (**) assert(Ghost.reveal len_v = n_s * l_v + r_v); (**) Math.Lemmas.nat_times_nat_is_nat n_s l_v; (**) assert(U32.v r <= U32.v len); [@inline_let] let blocks = len `U32.sub` r in (**) let blocks_v : Ghost.erased nat = U32.v blocks in (**) assert(blocks_v % l_v = 0); [@inline_let] let n = blocks `U32.div` l in (**) let n_v : Ghost.erased nat = U32.v n in (**) assert(n_v * l_v = Ghost.reveal blocks_v); (**) split_at_last_num_blocks_spec c i len_v n_v r_v; n #pop-options /// The ``rest`` function to call on the unprocessed data length in the ``finish`` /// function. #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let rest_finish #index (c: block index) (i: index) (len: UInt32.t): (x:UInt32.t { let l = U32.v (c.block_len i) in let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in 0 <= n * l /\ n * l <= U32.v len /\ U32.v x = U32.v len - (n * l)}) = [@inline_let] let l = c.block_len i in [@inline_let] let r = len `U32.rem` l in (**) split_at_last_num_blocks_lem c i (U32.v len); if U32.(r =^ uint_to_t 0) && U32.(len >^ uint_to_t 0) then begin (**) begin (**) let l = U32.v (c.block_len i) in (**) let n = fst (Lib.UpdateMulti.split_at_last_lazy_nb_rem l (U32.v len)) in (**) Math.Lemmas.nat_times_nat_is_nat n l (**) end; c.block_len i end else r #pop-options /// We always add 32-bit lengths to 64-bit lengths. Having a helper for that allows /// doing modulo reasoning once and for all. inline_for_extraction noextract let add_len #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Pure UInt64.t (requires U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures fun x -> U64.v x = U64.v total_len + U32.v len /\ U64.v x <= U64.v (c.max_input_len i)) = total_len `U64.add` Int.Cast.uint32_to_uint64 len #push-options "--z3cliopt smt.arith.nl=false" inline_for_extraction noextract let add_len_small #index (c: block index) (i: index) (total_len: UInt64.t) (len: UInt32.t): Lemma (requires U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i total_len) /\ U64.v total_len + U32.v len <= U64.v (c.max_input_len i)) (ensures (rest c i (add_len c i total_len len) = rest c i total_len `U32.add` len)) = let total_len_v = U64.v total_len in let l = U32.v (c.blocks_state_len i) in let b = total_len_v + U32.v len in let n = split_at_last_num_blocks c i total_len_v in let r = U32.v (rest c i total_len) in assert(total_len_v = n * l + r); let r' = U32.v (rest c i total_len) + U32.v len in assert(r' <= l); assert(r' = 0 ==> b = 0); Math.Lemmas.euclidean_division_definition b l; assert(b = n * l + r'); split_at_last_num_blocks_spec c i b n r' #pop-options /// Beginning of the three sub-cases (see Hacl.Streaming.Spec) /// ========================================================== noextract let total_len_h #index (c: block index) (i: index) h (p: state' c i) = State?.total_len (B.deref h p) noextract let split_at_last_all_seen #index (c: block index) (i: index) h (p: state' c i) = let all_seen = all_seen c i h p in let blocks, rest = split_at_last c i all_seen in blocks, rest inline_for_extraction noextract val update_small: #index:Type0 -> (c: block index) -> i:index -> ( t:Type0 { t == c.state.s i } -> t':Type0 { t' == optional_key i c.km c.key } -> s:state c i t t' -> data: B.buffer uint8 -> len: UInt32.t -> Stack unit (requires fun h0 -> update_pre c i s data len h0 /\ U32.v (c.init_input_len i) + S.length (seen c i h0 s) + U32.v len <= U64.v (c.max_input_len i) /\ U32.v len <= U32.v (c.blocks_state_len i) - U32.v (rest c i (total_len_h c i h0 s))) (ensures fun h0 s' h1 -> update_post c i s data len h0 h1)) /// SH: The proof obligations for update_small have problem succeeding in command /// line mode: hence the restart-solver instruction, the crazy rlimit and the /// intermediate lemma. Interestingly (and frustratingly), the proof succeeds /// quite quickly locally on command-line with this rlimit, but fails with a lower /// one. Besides, the lemma is needed only for the CI regression. let split_at_last_rest_eq (#index : Type0) (c: block index) (i: index) (t:Type0 { t == c.state.s i }) (t':Type0 { t' == optional_key i c.km c.key }) (s: state c i t t') (h0: HS.mem) : Lemma (requires ( invariant c i h0 s)) (ensures ( let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in Seq.length r == U32.v sz)) = let s = B.get h0 s 0 in let State block_state buf total_len seen_ k' = s in let key_v = optional_reveal #index #i #c.km #c.key h0 k' in let all_seen = S.append (c.init_input_s i key_v) seen_ in let _, r = split_at_last c i all_seen in let sz = rest c i total_len in () /// Particularly difficult proof. Z3 profiling indicates that a pattern goes off /// the rails. So I disabled all of the known "bad" patterns, then did the proof /// by hand. Fortunately, there were only two stateful operations. The idea was /// to do all ofthe modifies-reasoning in the two lemmas above, then disable the /// bad pattern for the main function. /// /// This style is a little tedious, because it requires a little bit of digging /// to understand what needs to hold in order to be able to prove that e.g. the /// sequence remains unmodified from h0 to h2, but this seems more robust? val modifies_footprint: #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in s:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State _ buf_ _ _ _ = B.deref h0 s in ( update_pre c i s data len h0 /\ B.(modifies (loc_buffer buf_) h0 h1)))) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 s in let State bs1 buf1 _ _ k1 = B.deref h1 s in ( footprint c i h0 s == footprint c i h1 s /\ preserves_freeable c i s h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1 /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (loc_addr_of_buffer buf1)) /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.state.footprint h1 bs1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer buf1)) /\ B.(loc_disjoint (loc_buffer s) (loc_buffer data)) /\ B.(loc_disjoint (loc_buffer s) (c.state.footprint h1 bs1)) /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer s) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer s) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer s) loc_none) /\ True))))) let modifies_footprint c i p data len h0 h1 = let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf0 _ _ k1 = s1 in c.state.frame_invariant (B.loc_buffer buf0) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_buffer buf0) k0 h0 h1 val modifies_footprint': #index:Type0 -> (c: block index) -> i:G.erased index -> ( let i = G.reveal i in p:state' c i -> data: B.buffer uint8 -> len: UInt32.t -> h0: HS.mem -> h1: HS.mem -> Lemma (requires ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h0 p /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h0 bs0)) /\ B.(loc_disjoint (loc_addr_of_buffer p) (loc_addr_of_buffer buf0)) /\ c.state.invariant h0 bs0 /\ (if c.km = Runtime then B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h0 k0)) /\ c.key.invariant #i h0 k0 else B.(loc_disjoint (loc_addr_of_buffer p) loc_none)) /\ B.(modifies (loc_buffer p) h0 h1)) /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1)) (ensures ( let State bs0 buf0 _ _ k0 = B.deref h0 p in let State bs1 buf1 _ _ k1 = B.deref h1 p in ( B.live h1 p /\ footprint c i h0 p == footprint c i h1 p /\ preserves_freeable c i p h0 h1 /\ B.(loc_disjoint (loc_addr_of_buffer p) (footprint_s c i h1 (B.deref h1 p))) /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.state.footprint #i h1 bs1)) /\ B.(loc_disjoint (loc_buffer p) (c.state.footprint #i h1 bs1)) /\ c.state.invariant h1 bs1 /\ c.state.v i h1 bs1 == c.state.v i h0 bs0 /\ c.state.footprint h1 bs1 == c.state.footprint h0 bs0 /\ (if c.km = Runtime then c.key.invariant #i h1 k1 /\ c.key.v i h1 k1 == c.key.v i h0 k0 /\ c.key.footprint #i h1 k1 == c.key.footprint #i h0 k0 /\ B.(loc_disjoint (loc_addr_of_buffer p) (c.key.footprint #i h1 k1)) /\ B.(loc_disjoint (loc_buffer p) (c.key.footprint #i h1 k1)) else B.(loc_disjoint (loc_addr_of_buffer p) loc_none))))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Streaming.Types.fst.checked", "Hacl.Streaming.Spec.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Functor.fst" }
[ { "abbrev": false, "full_module": "Hacl.Streaming.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Hacl.Streaming.Interface.block index -> i: FStar.Ghost.erased index -> (let i = FStar.Ghost.reveal i in p: Hacl.Streaming.Functor.state' c i -> data: LowStar.Buffer.buffer Hacl.Streaming.Spec.uint8 -> len: FStar.UInt32.t -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires (let _ = LowStar.Monotonic.Buffer.deref h0 p in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs0 buf0 _ _ k0 = _ in let _ = LowStar.Monotonic.Buffer.deref h1 p in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs1 buf1 _ _ k1 = _ in LowStar.Monotonic.Buffer.live h0 p /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (Stateful?.footprint (Block?.state c) h0 bs0) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (LowStar.Monotonic.Buffer.loc_addr_of_buffer buf0) /\ Stateful?.invariant (Block?.state c) h0 bs0 /\ (match Block?.km c = Hacl.Streaming.Interface.Runtime with | true -> LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (Stateful?.footprint (Block?.key c) h0 k0) /\ Stateful?.invariant (Block?.key c) h0 k0 | _ -> LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) LowStar.Monotonic.Buffer.loc_none) /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer p) h0 h1 /\ bs0 == bs1 /\ buf0 == buf1 /\ k0 == k1) <: Type0) <: Type0)) (ensures (let _ = LowStar.Monotonic.Buffer.deref h0 p in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs0 _ _ _ k0 = _ in let _ = LowStar.Monotonic.Buffer.deref h1 p in (let Hacl.Streaming.Functor.State #_ #_ #_ #_ #_ bs1 _ _ _ k1 = _ in LowStar.Monotonic.Buffer.live h1 p /\ Hacl.Streaming.Functor.footprint c i h0 p == Hacl.Streaming.Functor.footprint c i h1 p /\ Hacl.Streaming.Functor.preserves_freeable c i p h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (Hacl.Streaming.Functor.footprint_s c i h1 (LowStar.Monotonic.Buffer.deref h1 p)) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (Stateful?.footprint (Block?.state c) h1 bs1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer p) (Stateful?.footprint (Block?.state c) h1 bs1) /\ Stateful?.invariant (Block?.state c) h1 bs1 /\ Stateful?.v (Block?.state c) i h1 bs1 == Stateful?.v (Block?.state c) i h0 bs0 /\ Stateful?.footprint (Block?.state c) h1 bs1 == Stateful?.footprint (Block?.state c) h0 bs0 /\ (match Block?.km c = Hacl.Streaming.Interface.Runtime with | true -> Stateful?.invariant (Block?.key c) h1 k1 /\ Stateful?.v (Block?.key c) i h1 k1 == Stateful?.v (Block?.key c) i h0 k0 /\ Stateful?.footprint (Block?.key c) h1 k1 == Stateful?.footprint (Block?.key c) h0 k0 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) (Stateful?.footprint (Block?.key c) h1 k1) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer p ) (Stateful?.footprint (Block?.key c) h1 k1) | _ -> LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_addr_of_buffer p) LowStar.Monotonic.Buffer.loc_none)) <: Type0) <: Type0)))
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Interface.block", "FStar.Ghost.erased", "Hacl.Streaming.Functor.state'", "FStar.Ghost.reveal", "LowStar.Buffer.buffer", "Hacl.Streaming.Spec.uint8", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.Interface.__proj__Block__item__state", "Lib.IntTypes.uint8", "Prims.b2t", "Prims.op_Equality", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Interface.__proj__Block__item__blocks_state_len", "FStar.UInt64.t", "FStar.Seq.Base.seq", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.__proj__Block__item__km", "Hacl.Streaming.Interface.__proj__Block__item__key", "Hacl.Streaming.Interface.key_management", "Hacl.Streaming.Interface.Runtime", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_invariant", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "Hacl.Streaming.Functor.state_s", "Prims.bool", "Prims.unit", "LowStar.Monotonic.Buffer.deref", "FStar.Pervasives.allow_inversion", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "Hacl.Streaming.Interface.__proj__Stateful__item__invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Streaming.Interface.__proj__Stateful__item__footprint", "LowStar.Monotonic.Buffer.modifies", "Prims.squash", "Prims.eq2", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Hacl.Streaming.Interface.__proj__Stateful__item__freeable", "Hacl.Streaming.Interface.__proj__Stateful__item__frame_freeable" ]
[]
false
false
false
false
false
let modifies_footprint' c i p data len h0 h1 =
let _ = c.state.frame_freeable #i in let _ = c.key.frame_freeable #i in let _ = c.state.frame_invariant #i in let _ = c.key.frame_invariant #i in let _ = allow_inversion key_management in let s0 = B.deref h0 p in let s1 = B.deref h0 p in let State bs0 buf0 _ _ k0 = s0 in let State bs1 buf1 _ _ k1 = s1 in c.state.frame_invariant (B.loc_addr_of_buffer p) bs0 h0 h1; if c.km = Runtime then c.key.frame_invariant #i (B.loc_addr_of_buffer p) k0 h0 h1
false