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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.Transformers.Locations.fsti | Vale.Transformers.Locations.filter_state | val filter_state : s: Vale.X64.Machine_Semantics_s.machine_state ->
flags: Vale.X64.Machine_Semantics_s.flags_t ->
ok: Prims.bool ->
trace: Prims.list Vale.X64.Machine_s.observation
-> Vale.X64.Machine_Semantics_s.machine_state | let filter_state (s:machine_state) (flags:flags_t) (ok:bool) (trace:list observation) =
{ s with
ms_flags = FunctionalExtensionality.on_dom flag
(fun f ->
if f = fCarry then
s.ms_flags fCarry
else if f = fOverflow then
s.ms_flags fOverflow
else
flags f ) ;
ms_ok = ok ;
ms_trace = trace } | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 115,
"start_col": 0,
"start_line": 104
} | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys
(** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *)
val downgrade_val_raise_val_u0_u1 :
#a:Type0 ->
x:a ->
Lemma
(ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x)
[SMTPat (FStar.Universe.raise_val x)]
(** [location_val_t a] is the type of the value represented by the location [a]. *)
val location_val_t : location -> Type u#1
(** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *)
val location_val_eqt : location -> eqtype
(** Locations where location_val_t is an eqtype *)
let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)}
(** Coerce location_val_eqt to location_val_t *)
let raise_location_val_eqt (#l:location_eq) (v:location_val_eqt l) : location_val_t l =
coerce (FStar.Universe.raise_val v)
(** [eval_location a s] gives the value at location [a] in state [s]. *)
val eval_location :
a:location ->
machine_state ->
location_val_t a
(** [update_location a v s0] gives a new state with location [a] updated to [v]. *)
val update_location :
a:location ->
v:location_val_t a ->
machine_state ->
s:machine_state{eval_location a s == v}
(** Updating one location does not affect a different location. *)
val lemma_locations_truly_disjoint :
a:location ->
a_change:location ->
v:location_val_t a_change ->
s:machine_state ->
Lemma
(requires (a <> a_change))
(ensures (eval_location a s == eval_location a (update_location a_change v s))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: Vale.X64.Machine_Semantics_s.machine_state ->
flags: Vale.X64.Machine_Semantics_s.flags_t ->
ok: Prims.bool ->
trace: Prims.list Vale.X64.Machine_s.observation
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.flags_t",
"Prims.bool",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"FStar.FunctionalExtensionality.on_dom",
"Vale.X64.Machine_s.flag",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Prims.op_Equality",
"Vale.X64.Machine_s.fCarry",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_s.fOverflow",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint"
] | [] | false | false | false | true | false | let filter_state (s: machine_state) (flags: flags_t) (ok: bool) (trace: list observation) =
| {
s with
ms_flags
=
FunctionalExtensionality.on_dom flag
(fun f ->
if f = fCarry
then s.ms_flags fCarry
else if f = fOverflow then s.ms_flags fOverflow else flags f);
ms_ok = ok;
ms_trace = trace
} | false |
|
FStar.InteractiveHelpers.PostProcess.fst | FStar.InteractiveHelpers.PostProcess.find_equality_from_post | val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term) | val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term) | let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 487,
"start_col": 0,
"start_line": 468
} | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"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": 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": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dbg: Prims.bool ->
ge0: FStar.InteractiveHelpers.Base.genv ->
tm: FStar.Stubs.Reflection.Types.term ->
let_bv: FStar.Stubs.Reflection.Types.bv ->
let_bvty: FStar.Stubs.Reflection.Types.typ ->
ret_value: FStar.Stubs.Reflection.Types.term ->
einfo: FStar.InteractiveHelpers.Effectful.effect_info ->
parents: Prims.list FStar.Stubs.Reflection.V1.Data.term_view ->
children: Prims.list FStar.Stubs.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.Base.genv *
FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.bv",
"FStar.Stubs.Reflection.Types.typ",
"FStar.InteractiveHelpers.Effectful.effect_info",
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.PostProcess.find_subequality",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.Stubs.Tactics.V1.Builtins.term_to_string",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Effectful.pre_post_to_propositions",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_type",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.mk_binder",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_pre",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_post",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type"
] | [] | false | true | false | false | false | let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
| print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty)) tinfo
einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm | false |
Vale.Transformers.Locations.fsti | Vale.Transformers.Locations.lemma_disjoint_locations_symmetric | val lemma_disjoint_locations_symmetric (l1 l2: _)
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) | val lemma_disjoint_locations_symmetric (l1 l2: _)
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) | let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 57,
"start_col": 0,
"start_line": 45
} | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l1: Vale.Transformers.Locations.locations -> l2: Vale.Transformers.Locations.locations
-> FStar.Pervasives.Lemma
(ensures
!!(Vale.Transformers.Locations.disjoint_locations l1 l2) =
!!(Vale.Transformers.Locations.disjoint_locations l2 l1))
(decreases FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Vale.Transformers.Locations.locations",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.lemma_disjoint_locations_symmetric",
"Prims.Nil",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_locations",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_disjoint_locations_symmetric l1 l2
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
| match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] -> lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys | false |
Vale.Transformers.Locations.fsti | Vale.Transformers.Locations.raise_location_val_eqt | val raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l | val raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l | let raise_location_val_eqt (#l:location_eq) (v:location_val_eqt l) : location_val_t l =
coerce (FStar.Universe.raise_val v) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 78,
"start_col": 0,
"start_line": 77
} | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys
(** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *)
val downgrade_val_raise_val_u0_u1 :
#a:Type0 ->
x:a ->
Lemma
(ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x)
[SMTPat (FStar.Universe.raise_val x)]
(** [location_val_t a] is the type of the value represented by the location [a]. *)
val location_val_t : location -> Type u#1
(** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *)
val location_val_eqt : location -> eqtype
(** Locations where location_val_t is an eqtype *)
let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapTypes_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Vale.Transformers.Locations.location_val_eqt l -> Vale.Transformers.Locations.location_val_t l | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Vale.X64.Instruction_s.coerce",
"Vale.Transformers.Locations.location_val_t",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val"
] | [] | false | false | false | false | false | let raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l =
| coerce (FStar.Universe.raise_val v) | false |
FStar.InteractiveHelpers.PostProcess.fst | FStar.InteractiveHelpers.PostProcess.unfold_in_assert_or_assume | val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit | val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit | let unfold_in_assert_or_assume dbg ares =
print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res);
(* Find the focused term inside the assert, and on which side of the
* equality if the assert is an equality *)
let find_focused_in_term t =
find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t
in
let find_in_whole_term () : Tac _ =
match find_focused_in_term ares.res with
| Some res ->
ares.res, res, (fun x -> x <: Tac term), true
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
in
(* - subterm: the subterm of the assertion in which we found the focused term
* (if an equality, left or right operand, otherwise whole assertion)
* - unf_res: the result of the exploration for the focused term inside the
* assertion, which gives the term to unfold
* - rebuild: a Tot function which, given a term, rebuilds the equality by
* replacing the above subterm with the given term
* - insert_before: whether to insert the new assertion before or after the
* current assertion in the user file *)
let subterm, unf_res, (rebuild : term -> Tac term), insert_before =
let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in
match is_eq dbg ares.res with
| Some (kd, l, r) ->
print_dbg dbg "The assertion is an equality";
begin match find_focused_in_term l with
| Some res ->
print_dbg dbg ("Found focused term in left operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild t : Tac term = mk_eq kd t r in
l, res, rebuild, true
| None ->
begin match find_focused_in_term r with
| Some res ->
print_dbg dbg ("Found focused term in right operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild (t : term) : Tac term = mk_eq kd l t in
r, res, rebuild, false
| None ->
mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
end
end
| None ->
print_dbg dbg "The assertion is not an equality";
find_in_whole_term ()
in
print_dbg dbg ("Found subterm in assertion/assumption:\n" ^
"- subterm: " ^ term_to_string subterm ^ "\n" ^
"- focused term: " ^ term_to_string unf_res.res);
(* Unfold the term *)
let res_view = inspect unf_res.res in
let ge1, opt_unf_tm =
match res_view with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ares.ge, Some subterm'
| _ ->
(* Look for an equality given by a previous post-condition. In the case
* the term is a bv, we can also use the let-binding which introduces it,
* if it is pure. *)
let parents = List.Tot.map snd ares.parents in
let opt_bvty : option (bv & typ) =
match res_view with
| Tv_Var bv ->
print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv);
(* Check that the binder was not introduced by an abstraction inside the assertion *)
if not (Some? (genv_get ares.ge bv)) then
mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion";
Some (bv, pack_ln Tv_Unknown) // FIXME
| _ ->
print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res);
None
in
let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in
(* Check if we found an equality *)
let opt_eq_tm =
match eq_tm with
| Some eq_tm -> Some eq_tm
| _ -> None
in
(* Apply it *)
let subterm' =
match opt_bvty, opt_eq_tm with
| Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)])
| None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm)
| _ -> None
in
ge1, subterm'
in
(* If we couldn't unfold the term, check if it is a top-level identifier with
* implicit parameters (it may happen that the user calls the command on a
* top-level identifier which has implicit parameters without providing
* those parameters, in which case the focused term is the identifier applied
* to those implicits inferred by F*, and thus an app and not an fvar).
* Note that so far we have no way to check if the implicit parameters have
* been explicitly provided by the user or not, which is why we can't do better
* than greedy tests.*)
let ge2, unf_tm =
match opt_unf_tm with
| Some unf_tm -> ge1, unf_tm
| None ->
begin match inspect (strip_implicit_parameters unf_res.res) with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier with implicit parameters: "
^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ge1, subterm'
| _ ->
mfail ("unfold_in_assert_or_assume: " ^
"couldn't find equalities with which to rewrite: " ^
term_to_string unf_res.res)
end
in
(* Create the assertions to output *)
let final_assert = rebuild unf_tm in
let final_assert = prettify_term dbg final_assert in
print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert);
let asserts =
if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert]
in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in
(* Output *)
printout_success ge3 asserts | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 735,
"start_col": 0,
"start_line": 600
} | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm
/// Given a list of parent terms (as generated by ``explore_term``), look for an
/// equality given by a post-condition which can be used to replace a term.
val find_context_equality :
dbg:bool
-> ge0:genv
-> tm:term
-> parents:list term_view
-> children:list term_view
-> Tac (genv & option term)
/// Auxiliary function which actually performs the search
let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv)
(parents children : list term_view) :
Tac (genv & option term) =
match parents with
| [] -> ge0, None
| tv :: parents' ->
print_dbg dbg ("[> find_context_equality:\n" ^
"- term : " ^ term_to_string tm ^ "\n" ^
"- parent: " ^ term_to_string tv);
(* We only consider let-bindings *)
match tv with
| Tv_Let _ _ bv' ty def _ ->
print_dbg dbg "Is Tv_Let";
let tm_info = compute_eterm_info dbg ge0.env def in
let einfo = tm_info.einfo in
(* If the searched term is a bv and the current let is the one which
* introduces it:
* - if the term is effectful, use it
* - otherwise, try to use its postcondition. If we don't find any
* equalities, some there *)
let let_bv_is_tm =
match opt_bv with
| Some tm_bv -> bv_eq tm_bv bv'
| None -> false
in
if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def
else
let ret_value = pack (Tv_Var bv') in
begin match find_equality_from_post dbg ge0 tm bv' ty ret_value
einfo parents children with
| ge1, Some p -> ge1, Some p
| _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
end
| _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
let find_context_equality dbg ge0 tm parents children =
let opt_bv =
match inspect tm with
| Tv_Var bv -> Some bv
| _ -> None
in
find_context_equality_aux dbg ge0 tm opt_bv parents children
/// Replace a subterm by another term
val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *)
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
(* GM 2023-04-27: leaving ty untouched, old code did not
descend into sort. *)
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation
(* Auxiliary function to explore the branches *)
let explore_branch (br : branch) : Tac branch =
(* Only explore the branch body *)
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ ->
(* Unknown *)
tm
val strip_implicit_parameters : term -> Tac term
let rec strip_implicit_parameters tm =
match inspect tm with
| Tv_App hd (a,qualif) ->
if Q_Implicit? qualif then strip_implicit_parameters hd else tm
| _ -> tm | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"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": 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": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dbg: Prims.bool ->
ares: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Stubs.Reflection.Types.term",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Propositions.assertions",
"FStar.InteractiveHelpers.Output.printout_success",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Output.subst_shadowed_with_abs_in_assertions",
"FStar.Pervasives.Native.None",
"FStar.Stubs.Reflection.Types.bv",
"FStar.InteractiveHelpers.Propositions.mk_assertions",
"Prims.Cons",
"FStar.InteractiveHelpers.Propositions.proposition",
"Prims.Nil",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.Stubs.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Base.prettify_term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Tactics.V1.Builtins.norm_term_env",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.zeta",
"FStar.Reflection.V1.Derived.flatten_name",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.V1.Derived.fv_to_string",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.Base.mfail",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.Stubs.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge",
"FStar.Pervasives.Native.Some",
"FStar.Stubs.Reflection.Types.typ",
"FStar.InteractiveHelpers.Base.apply_subst",
"FStar.InteractiveHelpers.PostProcess.replace_term_in",
"FStar.InteractiveHelpers.PostProcess.find_context_equality",
"FStar.Stubs.Reflection.V1.Builtins.pack_ln",
"FStar.Stubs.Reflection.V1.Data.Tv_Unknown",
"Prims.op_Negation",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Base.genv_get",
"FStar.Tactics.V1.Derived.bv_to_string",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.snd",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents",
"FStar.Pervasives.Native.tuple4",
"FStar.InteractiveHelpers.PostProcess.eq_kind",
"FStar.Pervasives.Native.Mktuple4",
"FStar.InteractiveHelpers.PostProcess.mk_eq",
"FStar.InteractiveHelpers.PostProcess.is_eq",
"FStar.InteractiveHelpers.PostProcess.find_focused_term",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp"
] | [] | false | true | false | false | false | let unfold_in_assert_or_assume dbg ares =
| print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res);
let find_focused_in_term t = find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t in
let find_in_whole_term () : Tac _ =
match find_focused_in_term ares.res with
| Some res -> ares.res, res, (fun x -> x <: Tac term), true
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
in
let subterm, unf_res, (rebuild: (term -> Tac term)), insert_before =
let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in
match is_eq dbg ares.res with
| Some (kd, l, r) ->
print_dbg dbg "The assertion is an equality";
(match find_focused_in_term l with
| Some res ->
print_dbg dbg
("Found focused term in left operand:" ^
"\n- left : " ^
term_to_string l ^
"\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res);
let rebuild t : Tac term = mk_eq kd t r in
l, res, rebuild, true
| None ->
match find_focused_in_term r with
| Some res ->
print_dbg dbg
("Found focused term in right operand:" ^
"\n- left : " ^
term_to_string l ^
"\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res);
let rebuild (t: term) : Tac term = mk_eq kd l t in
r, res, rebuild, false
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert")
| None ->
print_dbg dbg "The assertion is not an equality";
find_in_whole_term ()
in
print_dbg dbg
("Found subterm in assertion/assumption:\n" ^
"- subterm: " ^ term_to_string subterm ^ "\n" ^ "- focused term: " ^ term_to_string unf_res.res);
let res_view = inspect unf_res.res in
let ge1, opt_unf_tm =
match res_view with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv);
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ares.ge, Some subterm'
| _ ->
let parents = List.Tot.map snd ares.parents in
let opt_bvty:option (bv & typ) =
match res_view with
| Tv_Var bv ->
print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv);
if not (Some? (genv_get ares.ge bv))
then
mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion"
;
Some (bv, pack_ln Tv_Unknown)
| _ ->
print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res);
None
in
let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in
let opt_eq_tm =
match eq_tm with
| Some eq_tm -> Some eq_tm
| _ -> None
in
let subterm' =
match opt_bvty, opt_eq_tm with
| Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)])
| None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm)
| _ -> None
in
ge1, subterm'
in
let ge2, unf_tm =
match opt_unf_tm with
| Some unf_tm -> ge1, unf_tm
| None ->
match inspect (strip_implicit_parameters unf_res.res) with
| Tv_FVar fv ->
print_dbg dbg
("The focused term is a top identifier with implicit parameters: " ^ fv_to_string fv);
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ge1, subterm'
| _ ->
mfail ("unfold_in_assert_or_assume: " ^
"couldn't find equalities with which to rewrite: " ^ term_to_string unf_res.res)
in
let final_assert = rebuild unf_tm in
let final_assert = prettify_term dbg final_assert in
print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert);
let asserts =
if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert]
in
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in
printout_success ge3 asserts | false |
Spec.Cipher.Expansion.fsti | Spec.Cipher.Expansion.xkey | val xkey : a: Spec.Agile.Cipher.cipher_alg -> Type0 | let xkey a = Lib.ByteSequence.lbytes (xkey_length a) | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 36,
"start_col": 0,
"start_line": 36
} | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256
let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256
/// Length of an expanded key per the AES specification.
val xkey_length (a: cipher_alg): Lib.IntTypes.size_nat | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Agile.Cipher.cipher_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.Cipher.cipher_alg",
"Lib.ByteSequence.lbytes",
"Spec.Cipher.Expansion.xkey_length"
] | [] | false | false | false | true | true | let xkey a =
| Lib.ByteSequence.lbytes (xkey_length a) | false |
|
Spec.Cipher.Expansion.fsti | Spec.Cipher.Expansion.concrete_xkey | val concrete_xkey : i: Spec.Cipher.Expansion.impl -> Type0 | let concrete_xkey (i: impl) = Lib.ByteSequence.lbytes (concrete_xkey_length i) | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256
let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256
/// Length of an expanded key per the AES specification.
val xkey_length (a: cipher_alg): Lib.IntTypes.size_nat
let xkey a = Lib.ByteSequence.lbytes (xkey_length a)
/// Length of the concrete representation of an expanded key, for a given implementation.
val concrete_xkey_length (i: impl): Lib.IntTypes.size_nat | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Spec.Cipher.Expansion.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Cipher.Expansion.impl",
"Lib.ByteSequence.lbytes",
"Spec.Cipher.Expansion.concrete_xkey_length"
] | [] | false | false | false | true | true | let concrete_xkey (i: impl) =
| Lib.ByteSequence.lbytes (concrete_xkey_length i) | false |
|
Spec.Cipher.Expansion.fsti | Spec.Cipher.Expansion.cipher_alg_of_impl | val cipher_alg_of_impl (i: impl) : cipher_alg | val cipher_alg_of_impl (i: impl) : cipher_alg | let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256 | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 31,
"start_col": 0,
"start_line": 27
} | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256 | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Spec.Cipher.Expansion.impl -> Spec.Agile.Cipher.cipher_alg | Prims.Tot | [
"total"
] | [] | [
"Spec.Cipher.Expansion.impl",
"Spec.Agile.Cipher.CHACHA20",
"Spec.Agile.Cipher.AES128",
"Spec.Agile.Cipher.AES256",
"Spec.Agile.Cipher.cipher_alg"
] | [] | false | false | false | true | false | let cipher_alg_of_impl (i: impl) : cipher_alg =
| match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256 | false |
Hacl.Impl.Chacha20Poly1305.PolyCore.fst | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st | val poly1305_padded_st : w: Hacl.Impl.Poly1305.Fields.field_spec -> Type0 | let poly1305_padded_st (w:field_spec) =
ctx:Poly.poly1305_ctx w
-> len:size_t
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ disjoint ctx text /\
Poly.state_inv_t h ctx)
(ensures fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\
Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx)) | {
"file_name": "code/chacha20poly1305/Hacl.Impl.Chacha20Poly1305.PolyCore.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 33,
"start_col": 0,
"start_line": 20
} | module Hacl.Impl.Chacha20Poly1305.PolyCore
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20Poly1305
module Poly = Hacl.Impl.Poly1305
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 1 --record_options" | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20Poly1305.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Poly1305",
"short_module": "Poly"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20Poly1305",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"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 | w: Hacl.Impl.Poly1305.Fields.field_spec -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Poly1305.Fields.field_spec",
"Hacl.Impl.Poly1305.poly1305_ctx",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Poly1305.Fields.limb",
"Lib.Buffer.disjoint",
"Hacl.Impl.Poly1305.state_inv_t",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Poly1305.felem",
"Hacl.Impl.Poly1305.as_get_r",
"Hacl.Impl.Poly1305.as_get_acc",
"Spec.Chacha20Poly1305.poly1305_padded",
"Lib.Buffer.as_seq"
] | [] | false | false | false | true | true | let poly1305_padded_st (w: field_spec) =
| ctx: Poly.poly1305_ctx w -> len: size_t -> text: lbuffer uint8 len
-> Stack unit
(requires fun h -> live h ctx /\ live h text /\ disjoint ctx text /\ Poly.state_inv_t h ctx)
(ensures
fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\ Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx)) | false |
|
LowParse.Spec.VLData.fst | LowParse.Spec.VLData.parse_vldata_gen | val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) | val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) | let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p) | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 26,
"start_col": 0,
"start_line": 11
} | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.VLData.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"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": 64,
"max_ifuel": 64,
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> LowParse.Spec.Base.parser (LowParse.Spec.VLData.parse_vldata_gen_kind sz k) t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Combinators.and_then",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_payload",
"Prims.unit",
"LowParse.Spec.VLData.parse_vldata_gen_kind_correct",
"LowParse.Spec.VLData.parse_fldata_and_then_cases_injective",
"LowParse.Spec.VLData.parse_vldata_gen_kind"
] | [] | false | false | false | false | false | let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) =
| parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then #_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.obs_args | val obs_args : args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | let obs_args = S.obs_args | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 15,
"start_col": 7,
"start_line": 15
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.obs_args"
] | [] | false | false | false | false | false | let obs_args =
| S.obs_args | false |
|
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.obs_inouts | val obs_inouts : inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | let obs_inouts = S.obs_inouts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 16,
"start_col": 7,
"start_line": 16
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.obs_inouts"
] | [] | false | false | false | false | false | let obs_inouts =
| S.obs_inouts | false |
|
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.machine_eval_code | val machine_eval_code : c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | let machine_eval_code = S.machine_eval_code | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 17,
"start_col": 7,
"start_line": 17
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | Prims.Tot | [
"total",
""
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_eval_code"
] | [] | false | false | false | true | false | let machine_eval_code =
| S.machine_eval_code | false |
|
LowParse.Spec.VLData.fst | LowParse.Spec.VLData.parse_vldata_gen_eq_def | val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) | val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) | let parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 36,
"end_line": 46,
"start_col": 0,
"start_line": 28
} | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.VLData.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"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": 64,
"max_ifuel": 64,
"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": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.and_then_cases_injective (LowParse.Spec.VLData.parse_vldata_payload sz
f
p) /\
LowParse.Spec.VLData.parse_vldata_gen_kind sz k ==
LowParse.Spec.Combinators.and_then_kind (LowParse.Spec.Combinators.parse_filter_kind (LowParse.Spec.BoundedInt.parse_bounded_integer_kind
sz))
(LowParse.Spec.VLData.parse_vldata_payload_kind sz k) /\
LowParse.Spec.VLData.parse_vldata_gen sz f p ==
LowParse.Spec.Combinators.and_then (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.BoundedInt.parse_bounded_integer
sz)
f)
(LowParse.Spec.VLData.parse_vldata_payload sz f p)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.VLData.parse_vldata_gen_kind_correct",
"Prims.unit",
"LowParse.Spec.VLData.parse_fldata_and_then_cases_injective",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.and_then_cases_injective",
"Prims.eq2",
"LowParse.Spec.VLData.parse_vldata_payload",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.Combinators.and_then",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k ==
and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then #_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) =
| parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k | false |
LowParse.Low.Combinators.fst | LowParse.Low.Combinators.gaccessor_synth_inv | val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) | val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) | let gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
= gaccessor_prop_equiv p1 (parse_synth p1 f) (clens_synth_inv g f) (gaccessor_synth_inv' p1 f g u);
gaccessor_synth_inv' p1 f g u | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 51,
"start_col": 0,
"start_line": 41
} | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
#set-options "--z3rlimit 16"
let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u
let gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Combinators.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"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": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u584:
Prims.squash (LowParse.Spec.Combinators.synth_inverse f g /\
LowParse.Spec.Combinators.synth_injective f)
-> LowParse.Low.Base.Spec.gaccessor p1
(LowParse.Spec.Combinators.parse_synth p1 f)
(LowParse.Low.Combinators.clens_synth_inv g f) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.gaccessor_synth_inv'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth_inv",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) =
| gaccessor_prop_equiv p1 (parse_synth p1 f) (clens_synth_inv g f) (gaccessor_synth_inv' p1 f g u);
gaccessor_synth_inv' p1 f g u | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.valid_addr32 | val valid_addr32 (ptr: int) (mem: S.machine_heap) : bool | val valid_addr32 (ptr: int) (mem: S.machine_heap) : bool | let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 270,
"start_col": 0,
"start_line": 266
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> mem: Vale.Arch.MachineHeap_s.machine_heap -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.op_AmpAmp",
"Vale.Arch.MachineHeap_s.valid_addr",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_addr32 (ptr: int) (mem: S.machine_heap) : bool =
| S.valid_addr (ptr + 0) mem && S.valid_addr (ptr + 1) mem && S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem | false |
LowParse.Low.Combinators.fst | LowParse.Low.Combinators.gaccessor_synth | val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) | val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) | let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 26,
"start_col": 0,
"start_line": 15
} | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
#set-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Combinators.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"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": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u492:
Prims.squash (LowParse.Spec.Combinators.synth_inverse f g /\
LowParse.Spec.Combinators.synth_injective f)
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Combinators.parse_synth p1 f)
p1
(LowParse.Low.Combinators.clens_synth g f) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.gaccessor_synth'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth",
"LowParse.Spec.Combinators.synth_injective_synth_inverse_synth_inverse_recip",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) =
| synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.reveal_machine_eval_code_ins | val reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] | val reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] | let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 24,
"start_col": 0,
"start_line": 19
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Machine_Semantics_s.machine_eval_code_ins i s ==
Vale.X64.Machine_Semantics_s.machine_eval_code_ins_def i s)
[SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code_ins i s)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.reveal_opaque",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins_def",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] =
| reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_implicit | val check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool | val check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool | let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 74,
"start_col": 0,
"start_line": 66
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Vale.X64.Instruction_s.instr_operand_implicit ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_s.operand64",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Prims.bool"
] | [] | false | false | false | true | false | let check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool =
| match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_explicit | val check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool | val check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool | let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 114,
"end_line": 64,
"start_col": 0,
"start_line": 57
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b'' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Vale.X64.Instruction_s.instr_operand_explicit ->
o: Vale.X64.Instruction_s.instr_operand_t i ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Prims.bool"
] | [] | false | false | false | false | false | let check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool =
| match i with
| IOp64 ->
operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm ->
operand_does_not_use_secrets #quad32 #reg_xmm o ts &&
operand_taint_allowed #quad32 #reg_xmm o t_out | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.instr_set_taint_explicit | val instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints | val instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints | let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 203,
"start_col": 0,
"start_line": 198
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Vale.X64.Instruction_s.instr_operand_explicit ->
o: Vale.X64.Instruction_s.instr_operand_t i ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.operand128"
] | [] | false | false | false | false | false | let instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints =
| match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.instr_set_taint_implicit | val instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints | val instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints | let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 211,
"start_col": 0,
"start_line": 206
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Vale.X64.Instruction_s.instr_operand_implicit ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Leakage_Helpers.set_taint_cf_and_flags",
"Vale.X64.Leakage_Helpers.set_taint_of_and_flags"
] | [] | false | false | false | true | false | let instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints =
| match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args | val check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) | val check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) | let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b'' | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 55,
"start_col": 0,
"start_line": 26
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.operand128",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_True",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.eq2",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Ins.obs_args"
] | [
"recursion"
] | false | false | false | false | false | let rec check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) =
| allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| IOpEx i :: args ->
let (o: instr_operand_t i), (oprs: instr_operands_t_args args) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| IOpIm i :: args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b'' | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.valid_addr128 | val valid_addr128 (ptr: int) (mem: S.machine_heap) : bool | val valid_addr128 (ptr: int) (mem: S.machine_heap) : bool | let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 342,
"start_col": 0,
"start_line": 338
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> mem: Vale.Arch.MachineHeap_s.machine_heap -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Ins.valid_addr32",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_addr128 (ptr: int) (mem: S.machine_heap) : bool =
| valid_addr32 (ptr + 0) mem && valid_addr32 (ptr + 4) mem && valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.instr_set_taints | val instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints | val instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints | let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 226,
"start_col": 0,
"start_line": 213
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Leakage_Ins.instr_set_taints",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Ins.instr_set_taint_explicit",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.instr_set_taint_implicit"
] | [
"recursion"
] | false | false | false | false | false | let rec instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints =
| match outs with
| [] -> ts
| (_, i) :: outs ->
(match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.update_heap32_val | val update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 | val update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 | let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 264,
"start_col": 0,
"start_line": 255
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.nat32 -> i: Prims.int -> Vale.Def.Types_s.nat8 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Prims.op_Subtraction",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four"
] | [] | false | false | false | true | false | let update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 =
| let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.update_heap64_val | val update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 | val update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 | let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 306,
"start_col": 0,
"start_line": 290
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.X64.Machine_s.nat64 -> i: Prims.int -> Vale.Def.Types_s.nat8 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Prims.op_Subtraction",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words_s.__proj__Mktwo__item__hi",
"Vale.Def.Words_s.__proj__Mktwo__item__lo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two"
] | [] | false | false | false | true | false | let update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 =
| let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.update_heap128_val | val update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 | val update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 | let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 336,
"start_col": 0,
"start_line": 329
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> i: Prims.int -> Vale.Def.Types_s.nat8 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.X64.Leakage_Ins.update_heap32_val",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Prims.bool",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 =
| let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4
then update_heap32_val (ptr + 0) v.lo0 i
else
if 4 <= j && j < 8
then update_heap32_val (ptr + 4) v.lo1 i
else
if 8 <= j && j < 12
then update_heap32_val (ptr + 8) v.hi2 i
else if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else 0 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap32_domain | val lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] | val lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] | let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 287,
"start_col": 0,
"start_line": 281
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.nat32 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Leakage_Ins.valid_addr32 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem) == FStar.Map.domain mem)
[SMTPat (FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap32",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Prims.b2t",
"Vale.X64.Leakage_Ins.valid_addr32",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] =
| S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem)) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap32_val | val lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] | val lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] | let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 279,
"start_col": 0,
"start_line": 272
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ptr: Prims.int ->
v: Vale.Def.Types_s.nat32 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap32 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 4 with
| true -> Vale.X64.Leakage_Ins.update_heap32_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem).[ i ]] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap32_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap32",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] =
| S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok | val lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) | val lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) | let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 252,
"start_col": 0,
"start_line": 228
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
vs: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.instr_write_outputs outs
args
vs
oprs
s_orig
s)) (ensures Mkmachine_state?.ms_ok s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Machine_Semantics_s.instr_write_output_explicit",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_write_output_implicit",
"Prims.unit",
"FStar.Pervasives.Native.Mktuple2",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) =
| match outs with
| [] -> ()
| (_, i) :: outs ->
(let (v: instr_val_t i), (vs: instr_ret_t outs) =
match outs with
| [] -> (vs, ())
| _ :: _ ->
let vs = coerce vs in
(fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s') | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap64_val | val lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] | val lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] | let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 317,
"start_col": 0,
"start_line": 308
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ptr: Prims.int ->
v: Vale.X64.Machine_s.nat64 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap64 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 8 with
| true -> Vale.X64.Leakage_Ins.update_heap64_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem).[ i ]] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap64_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] =
| S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs | val check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) | val check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) | let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b'' | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 98,
"start_col": 0,
"start_line": 76
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_implicit",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_True",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.eq2",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Ins.obs_inouts"
] | [
"recursion"
] | false | false | false | false | false | let rec check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) =
| allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i) :: outs ->
let (o: instr_operand_t i), (oprs: instr_operands_t outs args) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i) :: outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b'' | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap128_val | val lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] | val lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] | let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 353,
"start_col": 0,
"start_line": 344
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ptr: Prims.int ->
v: Vale.Def.Types_s.quad32 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap128 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 16 with
| true -> Vale.X64.Leakage_Ins.update_heap128_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem).[ i ]] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap128_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] =
| S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_preserve_valid128 | val lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) | val lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) | let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 375,
"start_col": 0,
"start_line": 370
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Arch.MachineHeap_s.machine_heap -> m': Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires FStar.Set.equal (FStar.Map.domain m) (FStar.Map.domain m'))
(ensures
forall (i: Prims.int). {:pattern Vale.Arch.MachineHeap_s.valid_addr128 i m'}
Vale.Arch.MachineHeap_s.valid_addr128 i m ==> Vale.Arch.MachineHeap_s.valid_addr128 i m') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Prims.int",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Prims.unit",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) =
| reveal_opaque (`%S.valid_addr128) S.valid_addr128 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_preserve_valid64 | val lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) | val lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) | let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 368,
"start_col": 0,
"start_line": 363
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Arch.MachineHeap_s.machine_heap -> m': Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires FStar.Set.equal (FStar.Map.domain m) (FStar.Map.domain m'))
(ensures
forall (i: Prims.int). {:pattern Vale.Arch.MachineHeap_s.valid_addr64 i m'}
Vale.Arch.MachineHeap_s.valid_addr64 i m ==> Vale.Arch.MachineHeap_s.valid_addr64 i m') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Prims.int",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Prims.unit",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) =
| reveal_opaque (`%S.valid_addr64) S.valid_addr64 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap64_domain | val lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] | val lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] | let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 326,
"start_col": 0,
"start_line": 319
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.X64.Machine_s.nat64 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.valid_addr64 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem) == FStar.Map.domain mem)
[SMTPat (FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"FStar.Pervasives.reveal_opaque",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Prims.b2t",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] =
| reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem)) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_args_taint | val lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) | val lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) | let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 144,
"start_col": 0,
"start_line": 102
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_args_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Leakage_s.constTimeInvariant (AnalysisTaints?.lts ts) s1 s2 /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1) /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args args oprs ts /\
Vale.X64.Leakage_Helpers.args_taint args oprs ts == Vale.Arch.HeapTypes_s.Public)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_args_t",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Leakage_Ins.lemma_args_taint",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val32_reveal",
"Vale.X64.Instruction_s.arrow",
"Vale.X64.Instruction_s.coerce",
"FStar.Pervasives.Native.tuple3",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_and",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_args",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.args_taint",
"Vale.Arch.HeapTypes_s.Public",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) =
| allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i :: args ->
let v1, v2, oprs:option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let o, (oprs: instr_operands_t_args args) = coerce oprs in
(S.instr_eval_operand_explicit i o s1, S.instr_eval_operand_explicit i o s2, oprs)
| IOpIm i ->
let oprs = coerce oprs in
(S.instr_eval_operand_implicit i s1, S.instr_eval_operand_implicit i s2, oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_update_heap128_domain | val lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] | val lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] | let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 361,
"start_col": 0,
"start_line": 355
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Leakage_Ins.valid_addr128 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem) == FStar.Map.domain mem)
[SMTPat (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"Prims.b2t",
"Vale.X64.Leakage_Ins.valid_addr128",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] =
| S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem)) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_arr | val collect_arr : typ -> Tac (list typ * comp) | val collect_arr : typ -> Tac (list typ * comp) | let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 33,
"start_col": 0,
"start_line": 30
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Stubs.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.typ * FStar.Tactics.NamedView.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Base.map",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__sort",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.SyntaxHelpers.collect_arr'",
"Prims.Nil",
"FStar.Stubs.Reflection.V2.Data.C_Total"
] | [] | false | true | false | false | false | let collect_arr t =
| let bs, c = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b: binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_arr_bs | val collect_arr_bs : typ -> Tac (list binder * comp) | val collect_arr_bs : typ -> Tac (list binder * comp) | let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 27,
"start_col": 0,
"start_line": 25
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Stubs.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.SyntaxHelpers.collect_arr'",
"Prims.Nil",
"FStar.Stubs.Reflection.V2.Data.C_Total"
] | [] | false | true | false | false | false | let collect_arr_bs t =
| let bs, c = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_arr' | val collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) | val collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) | let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 22,
"start_col": 0,
"start_line": 12
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.Tactics.NamedView.binder -> c: FStar.Tactics.NamedView.comp
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.comp",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V2.SyntaxHelpers.collect_arr'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.NamedView.inspect",
"FStar.Stubs.Reflection.V2.Data.comp_view"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) =
| match c with
| C_Total t ->
(match inspect t with
| Tv_Arrow b c -> collect_arr' (b :: bs) c
| _ -> (bs, c))
| _ -> (bs, c) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_abs' | val collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) | val collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) | let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 40,
"start_col": 0,
"start_line": 36
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.term) | FStar.Tactics.Effect.Tac | [
""
] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.SyntaxHelpers.collect_abs'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.NamedView.inspect"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) =
| match inspect t with
| Tv_Abs b t' -> collect_abs' (b :: bs) t'
| _ -> (bs, t) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_xor_consumes_fixed_time | val check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | val check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 537,
"start_col": 0,
"start_line": 522
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Machine_s.operand64",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.Arch.HeapTypes_s.Public",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpIm",
"Vale.X64.Instruction_s.IOpFlagsCf",
"Vale.X64.Instruction_s.IOpFlagsOf",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotateXor64",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) =
| let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_abs | val collect_abs : term -> Tac (list binder * term) | val collect_abs : term -> Tac (list binder * term) | let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t') | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 45,
"start_col": 0,
"start_line": 43
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.SyntaxHelpers.collect_abs'",
"Prims.Nil"
] | [] | false | true | false | false | false | let collect_abs t =
| let bs, t' = collect_abs' [] t in
(List.Tot.Base.rev bs, t') | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.fail | val fail : m: Prims.string -> FStar.Tactics.Effect.Tac a | let fail (#a:Type) (m:string) = raise #a (TacticFailure m) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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: Prims.string -> FStar.Tactics.Effect.Tac a | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Stubs.Tactics.Common.TacticFailure"
] | [] | false | true | false | false | false | let fail (#a: Type) (m: string) =
| raise #a (TacticFailure m) | false |
|
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_alloc_consumes_fixed_time | val check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) | val check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) | let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 12,
"end_line": 577,
"start_col": 0,
"start_line": 573
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Alloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) =
| (true, ts) | false |
Hacl.Impl.Curve25519.AddAndDouble.fst | Hacl.Impl.Curve25519.AddAndDouble.point_add_and_double1 | val point_add_and_double1:
#s:field_spec
-> nq:point s
-> nq_p1:point s
-> tmp1:lbuffer (limb s) (4ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq /\ live h0 nq_p1 /\ live h0 tmp1 /\ live h0 tmp2 /\
disjoint nq nq_p1 /\ disjoint nq tmp1 /\ disjoint nq tmp2 /\
disjoint nq_p1 tmp1 /\ disjoint nq_p1 tmp2 /\ disjoint tmp1 tmp2 /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
point_post_add_t h0 (gsub tmp1 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub tmp1 (nlimb s) (nlimb s)) /\
point_post_add_t h0 (get_x nq_p1) /\ point_post_sub_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 ->
modifies (loc nq |+| loc nq_p1 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 nq, fget_xz h1 nq_p1) ==
S.add_and_double1_1 (feval h0 (gsub tmp1 0ul (nlimb s)))
(feval h0 (gsub tmp1 (nlimb s) (nlimb s))) (fget_xz h0 nq_p1)) | val point_add_and_double1:
#s:field_spec
-> nq:point s
-> nq_p1:point s
-> tmp1:lbuffer (limb s) (4ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq /\ live h0 nq_p1 /\ live h0 tmp1 /\ live h0 tmp2 /\
disjoint nq nq_p1 /\ disjoint nq tmp1 /\ disjoint nq tmp2 /\
disjoint nq_p1 tmp1 /\ disjoint nq_p1 tmp2 /\ disjoint tmp1 tmp2 /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
point_post_add_t h0 (gsub tmp1 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub tmp1 (nlimb s) (nlimb s)) /\
point_post_add_t h0 (get_x nq_p1) /\ point_post_sub_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 ->
modifies (loc nq |+| loc nq_p1 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 nq, fget_xz h1 nq_p1) ==
S.add_and_double1_1 (feval h0 (gsub tmp1 0ul (nlimb s)))
(feval h0 (gsub tmp1 (nlimb s) (nlimb s))) (fget_xz h0 nq_p1)) | let point_add_and_double1 #s nq nq_p1 tmp1 tmp2 =
let x2 = sub nq 0ul (nlimb s) in
let z2 = sub nq (nlimb s) (nlimb s) in
let x3 = sub nq_p1 0ul (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a : felem s = sub tmp1 0ul (nlimb s) in
let b : felem s = sub tmp1 (nlimb s) (nlimb s) in
let d : felem s = sub tmp1 (2ul *! nlimb s) (nlimb s) in
let c : felem s = sub tmp1 (3ul *! nlimb s) (nlimb s) in
let ab : felem2 s = sub tmp1 0ul (2ul *! nlimb s) in
let dc : felem2 s = sub tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
(* CAN RUN IN PARALLEL *)
//fsqr d a; // d = aa = a^2
//fsqr c b; // c = bb = b^2
fsqr2 dc ab tmp2; // d|c = aa | bb
(* CAN RUN IN PARALLEL *)
//fsqr x3 x3; // x3 = (da + cb) ^ 2
//fsqr z3 z3; // z3 = (da - cb) ^ 2
fsqr2 nq_p1 nq_p1 tmp2; // x3|z3 = x3*x3|z3*z3
copy_felem a c; // a = bb
fsub c d c; // c = e = aa - bb
assert_norm (121665 < pow2 17);
fmul1 b c (u64 121665); // b = e * 121665
fadd b b d; // b = (e * 121665) + aa
(* CAN RUN IN PARALLEL *)
//fmul x2 d a; // x2 = aa * bb
//fmul z2 c b; // z2 = e * (aa + (e * 121665))
fmul2 nq dc ab tmp2 | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.AddAndDouble.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 143,
"start_col": 0,
"start_line": 112
} | module Hacl.Impl.Curve25519.AddAndDouble
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Curve25519.Field51
module F64 = Hacl.Impl.Curve25519.Field64
module P = Spec.Curve25519
module S = Hacl.Spec.Curve25519.AddAndDouble
#reset-options "--z3rlimit 300 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq' --record_options"
inline_for_extraction noextract
let point (s:field_spec) = lbuffer (limb s) (nlimb s +! nlimb s)
(* NEEDED ONLY FOR WRAPPERS *)
inline_for_extraction noextract
let point51 = lbuffer uint64 10ul
inline_for_extraction noextract
let point64 = lbuffer uint64 8ul
(* NEEDED ONLY FOR WRAPPERS *)
let get_x #s (p:point s) = gsub p 0ul (nlimb s)
let get_z #s (p:point s) = gsub p (nlimb s) (nlimb s)
let fget_x (#s:field_spec) (h:mem) (p:point s) = feval h (gsub p 0ul (nlimb s))
let fget_z (#s:field_spec) (h:mem) (p:point s) = feval h (gsub p (nlimb s) (nlimb s))
let fget_xz (#s:field_spec) (h:mem) (p:point s) = fget_x h p, fget_z h p
val point_post_sub_t:#s:field_spec -> h:mem -> f:felem s -> Type0
let point_post_sub_t #s h f =
match s with
| M51 -> F51.felem_fits h f (9, 10, 9, 9, 9)
| M64 -> True
val point_post_add_t:#s:field_spec -> h:mem -> f:felem s -> Type0
let point_post_add_t #s h f =
match s with
| M51 -> F51.felem_fits h f (2, 4, 2, 2, 2)
| M64 -> True
val point_add_and_double0:
#s:field_spec
-> nq_p1:point s
-> ab:lbuffer (limb s) (2ul *! nlimb s)
-> dc:lbuffer (limb s) (2ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq_p1 /\ live h0 ab /\ live h0 dc /\ live h0 tmp2 /\
disjoint nq_p1 ab /\ disjoint nq_p1 dc /\ disjoint nq_p1 tmp2 /\
disjoint ab dc /\ disjoint ab tmp2 /\ disjoint dc tmp2 /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1) /\
point_post_add_t h0 (gsub ab 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub ab (nlimb s) (nlimb s)))
(ensures fun h0 _ h1 ->
modifies (loc nq_p1 |+| loc dc |+| loc tmp2) h0 h1 /\
point_post_add_t h1 (get_x nq_p1) /\ point_post_sub_t h1 (get_z nq_p1) /\
fget_xz h1 nq_p1 == S.add_and_double1_0 (fget_x h0 ab) (fget_z h0 ab) (fget_xz h0 nq_p1))
[@ Meta.Attribute.inline_ ]
let point_add_and_double0 #s nq_p1 ab dc tmp2 =
let x3 = sub nq_p1 0ul (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a : felem s = sub ab 0ul (nlimb s) in
let b : felem s = sub ab (nlimb s) (nlimb s) in
let d : felem s = sub dc 0ul (nlimb s) in
let c : felem s = sub dc (nlimb s) (nlimb s) in
fadd c x3 z3; // c = x3 + z3
fsub d x3 z3; // d = x3 - z3
(* CAN RUN IN PARALLEL *)
//fmul d d a; // d = da = d * a
//fmul c c b; // c = cb = c * b
fmul2 dc dc ab tmp2; // d|c = d*a|c*b
fadd x3 d c; // x3 = da + cb
fsub z3 d c // z3 = da - cb
val point_add_and_double1:
#s:field_spec
-> nq:point s
-> nq_p1:point s
-> tmp1:lbuffer (limb s) (4ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq /\ live h0 nq_p1 /\ live h0 tmp1 /\ live h0 tmp2 /\
disjoint nq nq_p1 /\ disjoint nq tmp1 /\ disjoint nq tmp2 /\
disjoint nq_p1 tmp1 /\ disjoint nq_p1 tmp2 /\ disjoint tmp1 tmp2 /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
point_post_add_t h0 (gsub tmp1 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub tmp1 (nlimb s) (nlimb s)) /\
point_post_add_t h0 (get_x nq_p1) /\ point_post_sub_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 ->
modifies (loc nq |+| loc nq_p1 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 nq, fget_xz h1 nq_p1) ==
S.add_and_double1_1 (feval h0 (gsub tmp1 0ul (nlimb s)))
(feval h0 (gsub tmp1 (nlimb s) (nlimb s))) (fget_xz h0 nq_p1)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"Hacl.Impl.Curve25519.Field51.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.AddAndDouble.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field51",
"short_module": "F51"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
nq: Hacl.Impl.Curve25519.AddAndDouble.point s ->
nq_p1: Hacl.Impl.Curve25519.AddAndDouble.point s ->
tmp1:
Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s)
(4ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) ->
tmp2: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.AddAndDouble.point",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"Hacl.Impl.Curve25519.Fields.Core.fmul2",
"Prims.unit",
"Hacl.Impl.Curve25519.Fields.Core.fadd",
"Hacl.Impl.Curve25519.Fields.Core.fmul1",
"Lib.IntTypes.u64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Hacl.Impl.Curve25519.Fields.Core.fsub",
"Hacl.Impl.Curve25519.Fields.copy_felem",
"Hacl.Impl.Curve25519.Fields.Core.fsqr2",
"Hacl.Impl.Curve25519.Fields.Core.felem2",
"Lib.Buffer.sub",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.IntTypes.op_Plus_Bang"
] | [] | false | true | false | false | false | let point_add_and_double1 #s nq nq_p1 tmp1 tmp2 =
| let x2 = sub nq 0ul (nlimb s) in
let z2 = sub nq (nlimb s) (nlimb s) in
let x3 = sub nq_p1 0ul (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a:felem s = sub tmp1 0ul (nlimb s) in
let b:felem s = sub tmp1 (nlimb s) (nlimb s) in
let d:felem s = sub tmp1 (2ul *! nlimb s) (nlimb s) in
let c:felem s = sub tmp1 (3ul *! nlimb s) (nlimb s) in
let ab:felem2 s = sub tmp1 0ul (2ul *! nlimb s) in
let dc:felem2 s = sub tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
fsqr2 dc ab tmp2;
fsqr2 nq_p1 nq_p1 tmp2;
copy_felem a c;
fsub c d c;
assert_norm (121665 < pow2 17);
fmul1 b c (u64 121665);
fadd b b d;
fmul2 nq dc ab tmp2 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.coerce_to_normal | val coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} | val coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} | let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 520,
"start_col": 0,
"start_line": 520
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> y: Vale.X64.Instruction_s.normal a {x == y} | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.normal",
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} =
| x | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time | val check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | val check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 554,
"start_col": 0,
"start_line": 539
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotatePxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) =
| let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_vpxor_consumes_fixed_time | val check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | val check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 571,
"start_col": 0,
"start_line": 556
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotateVPxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) =
| let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs
in
let _, (o2, (o3, ())) = oprs in
if o2 = o3
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_app | val collect_app : t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(FStar.Tactics.NamedView.term * Prims.list FStar.Stubs.Reflection.V2.Data.argv) | let collect_app = collect_app' [] | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 88,
"start_col": 0,
"start_line": 88
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod)))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod)))
let lookup_lb (lbs:list letbinding) (nm:name) : Tac letbinding =
let o = FStar.List.Tot.Base.find
(fun lb -> (inspect_fv lb.lb_fv) = nm)
lbs
in
match o with
| Some lb -> lb
| None -> fail "lookup_letbinding: Name not in let group"
let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(FStar.Tactics.NamedView.term * Prims.list FStar.Stubs.Reflection.V2.Data.argv) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.V2.SyntaxHelpers.collect_app'",
"Prims.Nil",
"FStar.Stubs.Reflection.V2.Data.argv"
] | [] | false | true | false | false | false | let collect_app =
| collect_app' [] | false |
|
Steel.Channel.Simplex.fsti | Steel.Channel.Simplex.prot | val prot:Type u#1 | val prot:Type u#1 | let prot : Type u#1 = protocol unit | {
"file_name": "lib/steel/Steel.Channel.Simplex.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 35,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2020 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 Steel.Channel.Simplex
open Steel.Channel.Protocol
open Steel.Memory
open Steel.Effect
/// This library provides a model of unidirectional, protocol-indexed channels.
/// One party is allowed to send messages on the channel, while the other is allowed
/// to receive messages on the same channel.
/// Protocols are specified using the structure in Steel.Channel.Protocol
/// Msg int (fun x -> Msg (y:int { y > x }) (fun _ -> Ret unit))
/// | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.fsti.checked",
"Steel.Channel.Protocol.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Channel.Simplex.fsti"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel.Protocol",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"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 | Type | Prims.Tot | [
"total"
] | [] | [
"Steel.Channel.Protocol.protocol",
"Prims.unit"
] | [] | false | false | false | true | true | let prot:Type u#1 =
| protocol unit | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.collect_app' | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 86,
"start_col": 0,
"start_line": 81
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod)))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod)))
let lookup_lb (lbs:list letbinding) (nm:name) : Tac letbinding =
let o = FStar.List.Tot.Base.find
(fun lb -> (inspect_fv lb.lb_fv) = nm)
lbs
in
match o with
| Some lb -> lb
| None -> fail "lookup_letbinding: Name not in let group"
let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | args: Prims.list FStar.Stubs.Reflection.V2.Data.argv -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(FStar.Tactics.NamedView.term * Prims.list FStar.Stubs.Reflection.V2.Data.argv) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.SyntaxHelpers.collect_app'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.NamedView.term_view",
"Prims.b2t",
"FStar.Tactics.NamedView.notAscription",
"FStar.Tactics.V2.SyntaxHelpers.inspect_unascribe"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_app' (args: list argv) (t: term) : Tac (term * list argv) =
| match inspect_unascribe t with
| Tv_App l r -> collect_app' (r :: args) l
| _ -> (t, args) | false |
GenericSort.fst | GenericSort.sorted | val sorted: list 'a -> key:('a -> Tot int) -> Tot bool | val sorted: list 'a -> key:('a -> Tot int) -> Tot bool | let rec sorted l key = match l with
| [] | [_] -> true
| x::y::xs -> (key x <= key y) && (sorted (y::xs) key) | {
"file_name": "examples/algorithms/GenericSort.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 31,
"start_col": 0,
"start_line": 29
} | (*
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.
*)
(**
@summary: This module defines properties of sortedness on a generic list.
@author: A Manning
**)
module GenericSort
open FStar.List.Tot
open FStar.List.Tot
(**
Checks that a list is sorted.
**) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericSort.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list 'a -> key: (_: 'a -> Prims.int) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.int",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"GenericSort.sorted",
"Prims.Cons",
"Prims.bool"
] | [
"recursion"
] | false | false | false | true | false | let rec sorted l key =
| match l with
| [] | [_] -> true
| x :: y :: xs -> (key x <= key y) && (sorted (y :: xs) key) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_inouts_taint | val lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) | val lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) | let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 196,
"start_col": 0,
"start_line": 147
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_inouts_t outs inouts args ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Leakage_s.constTimeInvariant (AnalysisTaints?.lts ts) s1 s2 /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs inouts
args
oprs
ts
Vale.Arch.HeapTypes_s.Public /\
Vale.X64.Leakage_Helpers.inouts_taint inouts args oprs ts == Vale.Arch.HeapTypes_s.Public)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_inouts_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_Ins.lemma_args_taint",
"Vale.X64.Leakage_Ins.lemma_inouts_taint",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_explicit",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val32_reveal",
"Vale.X64.Instruction_s.arrow",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_and",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) =
| allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i) :: inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i) :: inouts ->
let v1, v2, oprs:option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let o, (oprs: instr_operands_t inouts args) = coerce oprs in
let oprs = coerce oprs in
(S.instr_eval_operand_explicit i o s1, S.instr_eval_operand_explicit i o s2, oprs)
| IOpIm i ->
let oprs = coerce oprs in
(S.instr_eval_operand_implicit i s1, S.instr_eval_operand_implicit i s2, oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time | val check_if_ins_consumes_fixed_time (ins:Vale.X64.Machine_Semantics_s.ins) (ts:analysis_taints)
: (res:(bool & analysis_taints){ins_consumes_fixed_time ins ts res}) | val check_if_ins_consumes_fixed_time (ins:Vale.X64.Machine_Semantics_s.ins) (ts:analysis_taints)
: (res:(bool & analysis_taints){ins_consumes_fixed_time ins ts res}) | let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 612,
"start_col": 0,
"start_line": 603
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> res:
(Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints)
{Vale.X64.Leakage_Helpers.ins_consumes_fixed_time ins ts res} | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Prims.Cons",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Leakage_Ins.check_if_xor_consumes_fixed_time",
"Vale.X64.Instruction_s.opXmm",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Leakage_Ins.check_if_vpxor_consumes_fixed_time",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_pop_consumes_fixed_time",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Leakage_Ins.check_if_alloc_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_ins_consumes_fixed_time ins ts =
| match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts | false |
GenericSort.fst | GenericSort.sorted_smaller | val sorted_smaller: #a:eqtype
-> x:a
-> y:a
-> l:list a
-> key:(a -> Tot int)
-> Lemma (requires (sorted (x::l) key /\ mem y l))
(ensures (key x <= key y))
[SMTPat (sorted (x::l) key); SMTPat (mem y l)] | val sorted_smaller: #a:eqtype
-> x:a
-> y:a
-> l:list a
-> key:(a -> Tot int)
-> Lemma (requires (sorted (x::l) key /\ mem y l))
(ensures (key x <= key y))
[SMTPat (sorted (x::l) key); SMTPat (mem y l)] | let rec sorted_smaller #a x y l key = match l with
| [] -> ()
| z::zs -> if key z = key y then () else sorted_smaller x y zs key | {
"file_name": "examples/algorithms/GenericSort.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 53,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
(**
@summary: This module defines properties of sortedness on a generic list.
@author: A Manning
**)
module GenericSort
open FStar.List.Tot
open FStar.List.Tot
(**
Checks that a list is sorted.
**)
val sorted: list 'a -> key:('a -> Tot int) -> Tot bool
let rec sorted l key = match l with
| [] | [_] -> true
| x::y::xs -> (key x <= key y) && (sorted (y::xs) key)
val test_sorted: x:'a -> l:list 'a -> key:('a -> Tot int) ->
Lemma ((sorted (x::l) key /\ Cons? l) ==> key x <= key (Cons?.hd l))
let test_sorted x l key = ()
val test_sorted2: unit -> key:('a -> Tot int) -> Tot (m:list 'a{sorted m key})
let test_sorted2 () key = Nil
(**
Lemmata about sorted.
**)
val sorted_smaller: #a:eqtype
-> x:a
-> y:a
-> l:list a
-> key:(a -> Tot int)
-> Lemma (requires (sorted (x::l) key /\ mem y l))
(ensures (key x <= key y)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericSort.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | x: a -> y: a -> l: Prims.list a -> key: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(requires GenericSort.sorted (x :: l) key /\ FStar.List.Tot.Base.mem y l)
(ensures key x <= key y)
[SMTPat (GenericSort.sorted (x :: l) key); SMTPat (FStar.List.Tot.Base.mem y l)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"Prims.op_Equality",
"Prims.bool",
"GenericSort.sorted_smaller",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec sorted_smaller #a x y l key =
| match l with
| [] -> ()
| z :: zs -> if key z = key y then () else sorted_smaller x y zs key | false |
GenericSort.fst | GenericSort.test_sorted2 | val test_sorted2: unit -> key:('a -> Tot int) -> Tot (m:list 'a{sorted m key}) | val test_sorted2: unit -> key:('a -> Tot int) -> Tot (m:list 'a{sorted m key}) | let test_sorted2 () key = Nil | {
"file_name": "examples/algorithms/GenericSort.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | (*
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.
*)
(**
@summary: This module defines properties of sortedness on a generic list.
@author: A Manning
**)
module GenericSort
open FStar.List.Tot
open FStar.List.Tot
(**
Checks that a list is sorted.
**)
val sorted: list 'a -> key:('a -> Tot int) -> Tot bool
let rec sorted l key = match l with
| [] | [_] -> true
| x::y::xs -> (key x <= key y) && (sorted (y::xs) key)
val test_sorted: x:'a -> l:list 'a -> key:('a -> Tot int) ->
Lemma ((sorted (x::l) key /\ Cons? l) ==> key x <= key (Cons?.hd l))
let test_sorted x l key = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericSort.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Prims.unit -> key: (_: 'a -> Prims.int) -> m: Prims.list 'a {GenericSort.sorted m key} | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Prims.int",
"Prims.Nil",
"Prims.list",
"Prims.b2t",
"GenericSort.sorted"
] | [] | false | false | false | false | false | let test_sorted2 () key =
| Nil | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time | val check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) | val check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) | let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 12,
"end_line": 583,
"start_col": 0,
"start_line": 579
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Dealloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) =
| (true, ts) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time | val check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) | val check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) | let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 518,
"start_col": 0,
"start_line": 506
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.Arch.HeapTypes_s.Secret",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) =
| let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> flags
in
let cf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> cf
in
let ovf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> ovf
in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.mk_tot_arr | val mk_tot_arr (bs: list binder) (cod: term) : Tac term | val mk_tot_arr (bs: list binder) (cod: term) : Tac term | let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod))) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 62,
"start_col": 0,
"start_line": 58
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.Tactics.NamedView.binder -> cod: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.Tv_Arrow",
"FStar.Tactics.NamedView.comp",
"FStar.Stubs.Reflection.V2.Data.C_Total",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V2.SyntaxHelpers.mk_tot_arr"
] | [
"recursion"
] | false | true | false | false | false | let rec mk_tot_arr (bs: list binder) (cod: term) : Tac term =
| match bs with
| [] -> cod
| b :: bs -> pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod))) | false |
GenericSort.fst | GenericSort.sorted_tl | val sorted_tl: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (sorted (Cons?.tl l) k)) | val sorted_tl: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (sorted (Cons?.tl l) k)) | let rec sorted_tl #a l k =
match l with
| [_] -> ()
| a::b::xs -> sorted_tl (b::xs) k | {
"file_name": "examples/algorithms/GenericSort.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | (*
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.
*)
(**
@summary: This module defines properties of sortedness on a generic list.
@author: A Manning
**)
module GenericSort
open FStar.List.Tot
open FStar.List.Tot
(**
Checks that a list is sorted.
**)
val sorted: list 'a -> key:('a -> Tot int) -> Tot bool
let rec sorted l key = match l with
| [] | [_] -> true
| x::y::xs -> (key x <= key y) && (sorted (y::xs) key)
val test_sorted: x:'a -> l:list 'a -> key:('a -> Tot int) ->
Lemma ((sorted (x::l) key /\ Cons? l) ==> key x <= key (Cons?.hd l))
let test_sorted x l key = ()
val test_sorted2: unit -> key:('a -> Tot int) -> Tot (m:list 'a{sorted m key})
let test_sorted2 () key = Nil
(**
Lemmata about sorted.
**)
val sorted_smaller: #a:eqtype
-> x:a
-> y:a
-> l:list a
-> key:(a -> Tot int)
-> Lemma (requires (sorted (x::l) key /\ mem y l))
(ensures (key x <= key y))
[SMTPat (sorted (x::l) key); SMTPat (mem y l)]
let rec sorted_smaller #a x y l key = match l with
| [] -> ()
| z::zs -> if key z = key y then () else sorted_smaller x y zs key
val sorted_tl: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericSort.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list a {Cons? l} -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma (requires GenericSort.sorted l k)
(ensures GenericSort.sorted (Cons?.tl l) k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.b2t",
"Prims.uu___is_Cons",
"Prims.int",
"GenericSort.sorted_tl",
"Prims.Cons",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec sorted_tl #a l k =
| match l with
| [_] -> ()
| a :: b :: xs -> sorted_tl (b :: xs) k | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.mk_arr | val mk_arr (bs: list binder) (cod: comp) : Tac term | val mk_arr (bs: list binder) (cod: comp) : Tac term | let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod))) | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 56,
"start_col": 0,
"start_line": 51
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.Tactics.NamedView.binder -> cod: FStar.Tactics.NamedView.comp
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.comp",
"FStar.Tactics.V2.SyntaxHelpers.fail",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Arrow",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Stubs.Reflection.V2.Data.C_Total",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V2.SyntaxHelpers.mk_arr"
] | [
"recursion"
] | false | true | false | false | false | let rec mk_arr (bs: list binder) (cod: comp) : Tac term =
| match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| b :: bs -> pack (Tv_Arrow b (C_Total (mk_arr bs cod))) | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.inspect_unascribe | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 78,
"start_col": 0,
"start_line": 73
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod)))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod)))
let lookup_lb (lbs:list letbinding) (nm:name) : Tac letbinding =
let o = FStar.List.Tot.Base.find
(fun lb -> (inspect_fv lb.lb_fv) = nm)
lbs
in
match o with
| Some lb -> lb
| None -> fail "lookup_letbinding: Name not in let group" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac
(tv: FStar.Tactics.NamedView.term_view{FStar.Tactics.NamedView.notAscription tv}) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Tactics.V2.SyntaxHelpers.inspect_unascribe",
"FStar.Tactics.NamedView.term_view",
"Prims.b2t",
"FStar.Tactics.NamedView.notAscription",
"FStar.Tactics.NamedView.comp",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.inspect"
] | [
"recursion"
] | false | true | false | false | false | let rec inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) =
| match inspect t with
| Tv_AscribedT t _ _ _ | Tv_AscribedC t _ _ _ -> inspect_unascribe t
| tv -> tv | false |
FStar.Tactics.V2.SyntaxHelpers.fst | FStar.Tactics.V2.SyntaxHelpers.lookup_lb | val lookup_lb (lbs: list letbinding) (nm: name) : Tac letbinding | val lookup_lb (lbs: list letbinding) (nm: name) : Tac letbinding | let lookup_lb (lbs:list letbinding) (nm:name) : Tac letbinding =
let o = FStar.List.Tot.Base.find
(fun lb -> (inspect_fv lb.lb_fv) = nm)
lbs
in
match o with
| Some lb -> lb
| None -> fail "lookup_letbinding: Name not in let group" | {
"file_name": "ulib/FStar.Tactics.V2.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 71,
"start_col": 0,
"start_line": 64
} | module FStar.Tactics.V2.SyntaxHelpers
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.NamedView
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (C_Total t) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (C_Total t) in
let ts = List.Tot.Base.map (fun (b:binder) -> b.sort) bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.V2.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_arr bs cod)))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (C_Total (mk_tot_arr bs cod))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | lbs: Prims.list FStar.Tactics.NamedView.letbinding -> nm: FStar.Stubs.Reflection.Types.name
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.letbinding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.letbinding",
"FStar.Stubs.Reflection.Types.name",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"FStar.Tactics.NamedView.__proj__Mkletbinding__item__lb_fv",
"FStar.Tactics.V2.SyntaxHelpers.fail",
"FStar.Pervasives.Native.option",
"FStar.List.Tot.Base.find",
"Prims.bool"
] | [] | false | true | false | false | false | let lookup_lb (lbs: list letbinding) (nm: name) : Tac letbinding =
| let o = FStar.List.Tot.Base.find (fun lb -> (inspect_fv lb.lb_fv) = nm) lbs in
match o with
| Some lb -> lb
| None -> fail "lookup_letbinding: Name not in let group" | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time | val check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) | val check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) | let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 130,
"end_line": 593,
"start_col": 0,
"start_line": 587
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_AmpAmp",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.Lib.MapTree.sel",
"Vale.X64.Machine_s.reg",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__rts",
"Vale.X64.Machine_s.reg_Rsp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Prims.op_BarBar",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.Public",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Leakage_Helpers.operand_taint",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Push",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) =
| let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts &&
(t_out = Public || t_stk = Secret),
ts) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.check_if_pop_consumes_fixed_time | val check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) | val check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) | let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 125,
"end_line": 601,
"start_col": 0,
"start_line": 595
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | Prims.Pure | [] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_AmpAmp",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.Lib.MapTree.sel",
"Vale.X64.Machine_s.reg",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__rts",
"Vale.X64.Machine_s.reg_Rsp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Pop",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | false | false | false | false | false | let check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) =
| let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed,
set_taint 0 dst ts t_stk) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_instr_set_taints | val lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) | val lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) | let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 504,
"start_col": 0,
"start_line": 448
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
vs1: Vale.X64.Instruction_s.instr_ret_t outs ->
vs2: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts_orig: Vale.X64.Leakage_Helpers.analysis_taints ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint ->
s1_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let s1_state' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs1 oprs s1_orig s1
in
let s2_state' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs2 oprs s2_orig s2
in
Mkmachine_state?.ms_ok s1_state' /\ Mkmachine_state?.ms_ok s2_state' /\
(t_out == Vale.Arch.HeapTypes_s.Public ==> vs1 == vs2) /\
FStar.Set.equal (FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s1_orig
)))
(FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s1))) /\
FStar.Set.equal (FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s2_orig
)))
(FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s2))) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts_orig) s1_orig s2_orig /\
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts) s1 s2))
(ensures
(let s1' = Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs2 oprs s2_orig s2
in
let ts' = Vale.X64.Leakage_Ins.instr_set_taints outs args oprs ts t_out in
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts') s1' s2')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints",
"Prims.unit",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints_explicit",
"Vale.X64.Leakage_Ins.instr_set_taint_explicit",
"Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok",
"Vale.X64.Machine_Semantics_s.instr_write_output_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints_implicit",
"Vale.X64.Leakage_Ins.instr_set_taint_implicit",
"Vale.X64.Machine_Semantics_s.instr_write_output_implicit",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Prims.l_imp",
"Prims.eq2",
"Vale.Arch.HeapTypes_s.Public",
"FStar.Set.equal",
"Prims.int",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_s.publicValuesAreSame",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.squash",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) =
| match outs with
| [] -> ()
| (_, i) :: outs ->
(let (v1: instr_val_t i), (vs1: instr_ret_t outs) =
match outs with
| [] -> (vs1, ())
| _ :: _ ->
let vs1 = coerce vs1 in
(fst vs1, snd vs1)
in
let (v2: instr_val_t i), (vs2: instr_ret_t outs) =
match outs with
| [] -> (vs2, ())
| _ :: _ ->
let vs2 = coerce vs2 in
(fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let o, oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig
s2') | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_ins_leakage_free | val lemma_ins_leakage_free (ts:analysis_taints) (ins:Vale.X64.Machine_Semantics_s.ins) : Lemma
(let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
(b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | val lemma_ins_leakage_free (ts:analysis_taints) (ins:Vale.X64.Machine_Semantics_s.ins) : Lemma
(let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
(b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | let lemma_ins_leakage_free ts ins =
let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> lemma_xor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotatePxor _) -> lemma_pxor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotateVPxor _) -> lemma_vpxor_leakage_free ts ins
| BC.Instr _ _ _ -> lemma_instr_leakage_free ts ins
| BC.Alloc _ -> ()
| BC.Dealloc _ -> lemma_dealloc_leakage_free ts ins
| BC.Push _ _ -> lemma_push_leakage_free ts ins
| BC.Pop _ _ -> lemma_pop_leakage_free ts ins | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 842,
"start_col": 0,
"start_line": 832
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
)
let lemma_push_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Push? ins)
(ensures (
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret then ()
else (
let aux () : Lemma (v1 == v2)
= match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux()
)
in
()
)
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_pop_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Pop? ins)
(ensures (
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
allow_inversion maddr;
allow_inversion tmaddr;
let BC.Pop dst t_stk = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let stack_op = OStack (MReg reg_Rsp 0, Public) in
let v1 = S.eval_operand stack_op s1 in
let v2 = S.eval_operand stack_op s2 in
if t_stk = Public then (
S.get_heap_val64_reveal ();
assert (v1 == v2)
);
Classical.forall_intro_3 (fun s x (stack1:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro_3 (fun s x (stack2:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
()
)
#reset-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 4 --max_fuel 4 --z3rlimit 40"
let lemma_xor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_xor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
FStar.Classical.forall_intro_with_pat (fun n -> Vale.Def.Types_s.ixor n n) Vale.Arch.Types.lemma_BitwiseXorCancel64
else
lemma_instr_leakage_free ts ins
let lemma_pxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins
let lemma_vpxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_vpxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o1, (o2, ()))) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 20" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 1,
"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 | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Prims.Cons",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Leakage_Ins.lemma_xor_leakage_free",
"Vale.X64.Instruction_s.opXmm",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Leakage_Ins.lemma_pxor_leakage_free",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Leakage_Ins.lemma_vpxor_leakage_free",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Ins.lemma_instr_leakage_free",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Leakage_Ins.lemma_dealloc_leakage_free",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.lemma_push_leakage_free",
"Vale.X64.Leakage_Ins.lemma_pop_leakage_free",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time"
] | [] | false | false | true | false | false | let lemma_ins_leakage_free ts ins =
| let b, ts' = check_if_ins_consumes_fixed_time ins ts in
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> lemma_xor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotatePxor _) -> lemma_pxor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotateVPxor _) -> lemma_vpxor_leakage_free ts ins
| BC.Instr _ _ _ -> lemma_instr_leakage_free ts ins
| BC.Alloc _ -> ()
| BC.Dealloc _ -> lemma_dealloc_leakage_free ts ins
| BC.Push _ _ -> lemma_push_leakage_free ts ins
| BC.Pop _ _ -> lemma_pop_leakage_free ts ins | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_dealloc_leakage_free | val lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | val lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 702,
"start_col": 0,
"start_line": 670
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Dealloc? ins)
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Prims.unit",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.squash",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Vale.X64.Machine_s.nat64",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Prims.int",
"Vale.Def.Types_s.nat8",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Vale.X64.Leakage_s.publicStackValueIsSame",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"FStar.Classical.move_requires",
"FStar.Set.set",
"Prims.eq2",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"FStar.Map.restrict",
"Vale.Lib.Set.lemma_sel_restrict",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Leakage_Ins.machine_eval_code",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_s.Ins",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time",
"Vale.X64.Bytes_Code_s.uu___is_Dealloc",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isLeakageFree"
] | [] | false | false | true | false | false | let lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) =
| let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
if b
then
(let code = Ins ins in
let lem (s1 s2: S.machine_state) (fuel: nat)
: Lemma (requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)] =
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x: int)
: Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures
publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x) =
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
Classical.forall_intro (Classical.move_requires aux)
in
()) | false |
Hacl.Spec.K256.Field52.Lemmas3.fst | Hacl.Spec.K256.Field52.Lemmas3.fmul5_lemma | val fmul5_lemma: a:felem5 -> b:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64) /\
felem_fits5 b (64,64,64,64,64))
(ensures (let res = fmul5 a b in
as_nat5 res % S.prime == as_nat5 a * as_nat5 b % S.prime /\
felem_fits5 res (1,1,1,1,2))) | val fmul5_lemma: a:felem5 -> b:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64) /\
felem_fits5 b (64,64,64,64,64))
(ensures (let res = fmul5 a b in
as_nat5 res % S.prime == as_nat5 a * as_nat5 b % S.prime /\
felem_fits5 res (1,1,1,1,2))) | let fmul5_lemma a b =
let (a0,a1,a2,a3,a4) = a in
let (b0,b1,b2,b3,b4) = b in
let r = u64 0x1000003D10 in
let d0 = mul64_wide a0 b3
+. mul64_wide a1 b2
+. mul64_wide a2 b1
+. mul64_wide a3 b0 in
lemma_four_mul64_wide a0 a1 a2 a3 b0 b1 b2 b3;
assert (v d0 = v a0 * v b3 + v a1 * v b2 + v a2 * v b1 + v a3 * v b0);
assert (v d0 <= 16384 * (max52 * max52));
let c0 = mul64_wide a4 b4 in
lemma_bound_mul64_wide 64 64 max48 max48 a4 b4;
assert (v c0 = v a4 * v b4);
assert (v c0 <= 4096 * (max48 * max48));
let d1 = d0 +. mul64_wide r (to_u64 c0) in let c1 = to_u64 (c0 >>. 64ul) in
lemma_bound_add_mul64_wide_r 16384 d0 c0;
assert (v d1 = v d0 + v r * (v c0 % pow2 64));
assert (v d1 <= 16385 * (max52 * max52));
lemma_bound_rsh64_to c0;
assert (v c1 = v c0 / pow2 64);
lemma_bound_c0 c0;
assert (v c1 <= pow2 44);
let t3 = to_u64 d1 &. mask52 in let d2 = d1 >>. 52ul in
lemma_bound_mask52_rsh52 16385 d1;
assert (v t3 = v d1 % pow2 52);
assert (felem_fits1 t3 1);
assert (v d2 = v d1 / pow2 52);
assert (v d2 <= 16385 * max52);
let d3 = d2
+. mul64_wide a0 b4
+. mul64_wide a1 b3
+. mul64_wide a2 b2
+. mul64_wide a3 b1
+. mul64_wide a4 b0 in
lemma_add_five_mul64_wide 16385 d2 a0 a1 a2 a3 a4 b0 b1 b2 b3 b4;
assert (v d3 == v d2 + v a0 * v b4 + v a1 * v b3 + v a2 * v b2 + v a3 * v b1 + v a4 * v b0);
assert (v d3 <= 12801 * (max52 * max52));
let d4 = d3 +. mul64_wide (r <<. 12ul) c1 in
lemma_bound_add_mul64_wide_r_lsh12 12801 d3 c1;
assert (v d4 == v d3 + v r * pow2 12 * v c1);
assert (v d4 <= 12802 * (max52 * max52));
let t4 = to_u64 d4 &. mask52 in let d5 = d4 >>. 52ul in
lemma_bound_mask52_rsh52 12802 d4;
assert (v t4 = v d4 % pow2 52);
assert (felem_fits1 t4 1);
assert (v d5 = v d4 / pow2 52);
assert (v d5 <= 12802 * max52);
let tx = t4 >>. 48ul in let t4' = t4 &. mask48 in
lemma_bound_mask48_rsh48 t4;
assert (v tx = v t4 / pow2 48);
assert (v tx < pow2 4);
assert (v t4' = v t4 % pow2 48);
assert (felem_fits_last1 t4' 1);
let c2 = mul64_wide a0 b0 in
lemma_bound_mul64_wide 64 64 max52 max52 a0 b0;
assert (v c2 = v a0 * v b0);
assert (v c2 <= 4096 * (max52 * max52));
let d6 = d5
+. mul64_wide a1 b4
+. mul64_wide a2 b3
+. mul64_wide a3 b2
+. mul64_wide a4 b1 in
lemma_add_four_mul64_wide 12802 d5 a1 a2 a3 a4 b1 b2 b3 b4;
assert (v d6 == v d5 + v a1 * v b4 + v a2 * v b3 + v a3 * v b2 + v a4 * v b1);
assert (v d6 <= 8705 * (max52 * max52));
let u0 = to_u64 d6 &. mask52 in let d7 = d6 >>. 52ul in
lemma_bound_mask52_rsh52 8705 d6;
assert (v u0 = v d6 % pow2 52);
assert (felem_fits1 u0 1);
assert (v d7 = v d6 / pow2 52);
assert (v d7 <= 8705 * max52);
let u0' = tx |. (u0 <<. 4ul) in
lemma_tx_logor_u0_lsh4 tx u0;
assert (v u0' == v tx + v u0 * pow2 4);
assert (v u0' < pow2 56);
let c3 = c2 +. mul64_wide u0' (r >>. 4ul) in
lemma_bound_add_mul64_wide_r_rsh4 4096 c2 u0';
assert (v c3 = v c2 + v u0' * (v r / pow2 4));
assert (v c3 <= 4097 * (max52 * max52));
let r0 = to_u64 c3 &. mask52 in let c4 = c3 >>. 52ul in
lemma_bound_mask52_rsh52 4097 c3;
assert (v r0 = v c3 % pow2 52);
assert (felem_fits1 r0 1);
assert (v c4 = v c3 / pow2 52);
assert (v c4 <= 4097 * max52);
let c5 = c4
+. mul64_wide a0 b1
+. mul64_wide a1 b0 in
lemma_add_two_mul64_wide52 4097 c4 a0 a1 b0 b1;
assert (v c5 = v c4 + v a0 * v b1 + v a1 * v b0);
assert (v c5 <= 8193 * (max52 * max52));
let d8 = d7
+. mul64_wide a2 b4
+. mul64_wide a3 b3
+. mul64_wide a4 b2 in
lemma_add_three_mul64_wide 8705 d7 a2 a3 a4 b2 b3 b4;
assert (v d8 = v d7 + v a2 * v b4 + v a3 * v b3 + v a4 * v b2);
assert (v d8 <= 4609 * (max52 * max52));
let c6 = c5 +. mul64_wide (to_u64 d8 &. mask52) r in let d9 = d8 >>. 52ul in
lemma_bound_add_mul64_wide_r_mask52 8193 d8 c5;
assert (v d9 = v d8 / pow2 52);
assert (v d9 <= 8193 * max52);
assert (v c6 = v c5 + v d8 % pow2 52 * v r);
assert (v c6 <= 8194 * (max52 * max52));
let r1 = to_u64 c6 &. mask52 in let c7 = c6 >>. 52ul in
lemma_bound_mask52_rsh52 8194 c6;
assert (v r1 = v c6 % pow2 52);
assert (felem_fits1 r1 1);
assert (v c7 = v c6 / pow2 52);
assert (v c7 <= 8194 * max52);
let c8 = c7
+. mul64_wide a0 b2
+. mul64_wide a1 b1
+. mul64_wide a2 b0 in
lemma_add_three_mul64_wide52 8194 c7 a0 a1 a2 b0 b1 b2;
assert (v c8 == v c7 + v a0 * v b2 + v a1 * v b1 + v a2 * v b0);
assert (v c8 <= 12289 * (max52 * max52));
let d10 = d9
+. mul64_wide a3 b4
+. mul64_wide a4 b3 in
lemma_add_two_mul64_wide 8193 d9 a3 a4 b3 b4;
assert (v d10 == v d9 + v a3 * v b4 + v a4 * v b3);
assert (v d10 <= 513 * (max52 * max52));
let c9 = c8 +. mul64_wide r (to_u64 d10) in let d11 = to_u64 (d10 >>. 64ul) in
lemma_bound_add_mul64_wide_r 12289 c8 d10;
assert (v c9 = v c8 + v r * (v d10 % pow2 64));
assert (v c9 <= 12290 * (max52 * max52));
lemma_bound_rsh64_to d10;
assert (v d11 = v d10 / pow2 64);
lemma_bound_d10 d10;
assert (v d11 < pow2 50);
let r2 = to_u64 c9 &. mask52 in let c10 = c9 >>. 52ul in
lemma_bound_mask52_rsh52 12290 c9;
assert (v r2 = v c9 % pow2 52);
assert (felem_fits1 r2 1);
assert (v c10 = v c9 / pow2 52);
assert (v c10 <= 12290 * max52);
let c11 = c10 +. mul64_wide (r <<. 12ul) d11 +. to_u128 t3 in
lemma_bound_add_mul64_wide_r_lsh12_add 12290 c10 d11 t3;
assert (v c11 = v c10 + v r * pow2 12 * v d11 + v t3);
assert (v c11 < pow2 100);
let r3 = to_u64 c11 &. mask52 in let c12 = to_u64 (c11 >>. 52ul) in
lemma_bound_mask52_rsh52_sp c11;
assert (v r3 = v c11 % pow2 52);
assert (felem_fits1 r3 1);
assert (v c12 = v c11 / pow2 52);
assert (v c12 < pow2 48);
let r4 = c12 +. t4' in
lemma_mod_add_last c12 t4';
assert (v r4 = v c12 + v t4');
assert (felem_fits_last1 r4 2);
let res = (r0,r1,r2,r3,r4) in
assert (res == fmul5 a b);
assert (felem_fits5 res (1,1,1,1,2));
L4.lemma_fmul_simplify (v r0) (v r1) (v r2) (v r3) (v r4)
(v c3) (v c6) (v c9) (v c11) (v d4) (v d8) (v d10) (v d11)
(v t3) (v a0) (v a1) (v a2) (v a3) (v a4) (v b0) (v b1) (v b2) (v b3) (v b4) | {
"file_name": "code/k256/Hacl.Spec.K256.Field52.Lemmas3.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 209,
"start_col": 0,
"start_line": 24
} | module Hacl.Spec.K256.Field52.Lemmas3
open FStar.Mul
open Lib.IntTypes
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
include Hacl.Spec.K256.Field52
module L4 = Hacl.Spec.K256.Field52.Lemmas4
open Hacl.Spec.K256.Field52.Lemmas5
#set-options "--z3rlimit 150 --fuel 0 --ifuel 0"
val fmul5_lemma: a:felem5 -> b:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64) /\
felem_fits5 b (64,64,64,64,64))
(ensures (let res = fmul5 a b in
as_nat5 res % S.prime == as_nat5 a * as_nat5 b % S.prime /\
felem_fits5 res (1,1,1,1,2))) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas5.fst.checked",
"Hacl.Spec.K256.Field52.Lemmas4.fst.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Field52.Lemmas3.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Lemmas5",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas4",
"short_module": "L4"
},
{
"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": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.K256.Field52.Definitions.felem5 -> b: Hacl.Spec.K256.Field52.Definitions.felem5
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.K256.Field52.Definitions.felem_fits5 a (64, 64, 64, 64, 64) /\
Hacl.Spec.K256.Field52.Definitions.felem_fits5 b (64, 64, 64, 64, 64))
(ensures
(let res = Hacl.Spec.K256.Field52.fmul5 a b in
Hacl.Spec.K256.Field52.Definitions.as_nat5 res % Spec.K256.PointOps.prime ==
Hacl.Spec.K256.Field52.Definitions.as_nat5 a *
Hacl.Spec.K256.Field52.Definitions.as_nat5 b %
Spec.K256.PointOps.prime /\
Hacl.Spec.K256.Field52.Definitions.felem_fits5 res (1, 1, 1, 1, 2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.K256.Field52.Definitions.felem5",
"Lib.IntTypes.uint64",
"Hacl.Spec.K256.Field52.Lemmas4.lemma_fmul_simplify",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U128",
"Prims.unit",
"Prims._assert",
"Hacl.Spec.K256.Field52.Definitions.felem_fits5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.eq2",
"FStar.Pervasives.Native.tuple5",
"Hacl.Spec.K256.Field52.fmul5",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Hacl.Spec.K256.Field52.Definitions.felem_fits_last1",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_mod_add_last",
"Lib.IntTypes.op_Plus_Dot",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Division",
"Hacl.Spec.K256.Field52.Definitions.felem_fits1",
"Prims.op_Modulus",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_mask52_rsh52_sp",
"Lib.IntTypes.to_u64",
"Lib.IntTypes.op_Greater_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Amp_Dot",
"Hacl.Spec.K256.Field52.Definitions.mask52",
"FStar.Mul.op_Star",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r_lsh12_add",
"Lib.IntTypes.mul64_wide",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.to_u128",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.K256.Field52.Definitions.max52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_mask52_rsh52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_d10",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_rsh64_to",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_two_mul64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_three_mul64_wide52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r_mask52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_three_mul64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_two_mul64_wide52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r_rsh4",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_tx_logor_u0_lsh4",
"Lib.IntTypes.op_Bar_Dot",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_four_mul64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_mul64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_mask48_rsh48",
"Hacl.Spec.K256.Field52.Definitions.mask48",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r_lsh12",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_five_mul64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_c0",
"Hacl.Spec.K256.Field52.Definitions.max48",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_four_mul64_wide",
"Lib.IntTypes.range",
"Lib.IntTypes.u64"
] | [] | false | false | true | false | false | let fmul5_lemma a b =
| let a0, a1, a2, a3, a4 = a in
let b0, b1, b2, b3, b4 = b in
let r = u64 0x1000003D10 in
let d0 = mul64_wide a0 b3 +. mul64_wide a1 b2 +. mul64_wide a2 b1 +. mul64_wide a3 b0 in
lemma_four_mul64_wide a0 a1 a2 a3 b0 b1 b2 b3;
assert (v d0 = v a0 * v b3 + v a1 * v b2 + v a2 * v b1 + v a3 * v b0);
assert (v d0 <= 16384 * (max52 * max52));
let c0 = mul64_wide a4 b4 in
lemma_bound_mul64_wide 64 64 max48 max48 a4 b4;
assert (v c0 = v a4 * v b4);
assert (v c0 <= 4096 * (max48 * max48));
let d1 = d0 +. mul64_wide r (to_u64 c0) in
let c1 = to_u64 (c0 >>. 64ul) in
lemma_bound_add_mul64_wide_r 16384 d0 c0;
assert (v d1 = v d0 + v r * (v c0 % pow2 64));
assert (v d1 <= 16385 * (max52 * max52));
lemma_bound_rsh64_to c0;
assert (v c1 = v c0 / pow2 64);
lemma_bound_c0 c0;
assert (v c1 <= pow2 44);
let t3 = to_u64 d1 &. mask52 in
let d2 = d1 >>. 52ul in
lemma_bound_mask52_rsh52 16385 d1;
assert (v t3 = v d1 % pow2 52);
assert (felem_fits1 t3 1);
assert (v d2 = v d1 / pow2 52);
assert (v d2 <= 16385 * max52);
let d3 =
d2 +. mul64_wide a0 b4 +. mul64_wide a1 b3 +. mul64_wide a2 b2 +. mul64_wide a3 b1 +.
mul64_wide a4 b0
in
lemma_add_five_mul64_wide 16385 d2 a0 a1 a2 a3 a4 b0 b1 b2 b3 b4;
assert (v d3 == v d2 + v a0 * v b4 + v a1 * v b3 + v a2 * v b2 + v a3 * v b1 + v a4 * v b0);
assert (v d3 <= 12801 * (max52 * max52));
let d4 = d3 +. mul64_wide (r <<. 12ul) c1 in
lemma_bound_add_mul64_wide_r_lsh12 12801 d3 c1;
assert (v d4 == v d3 + (v r * pow2 12) * v c1);
assert (v d4 <= 12802 * (max52 * max52));
let t4 = to_u64 d4 &. mask52 in
let d5 = d4 >>. 52ul in
lemma_bound_mask52_rsh52 12802 d4;
assert (v t4 = v d4 % pow2 52);
assert (felem_fits1 t4 1);
assert (v d5 = v d4 / pow2 52);
assert (v d5 <= 12802 * max52);
let tx = t4 >>. 48ul in
let t4' = t4 &. mask48 in
lemma_bound_mask48_rsh48 t4;
assert (v tx = v t4 / pow2 48);
assert (v tx < pow2 4);
assert (v t4' = v t4 % pow2 48);
assert (felem_fits_last1 t4' 1);
let c2 = mul64_wide a0 b0 in
lemma_bound_mul64_wide 64 64 max52 max52 a0 b0;
assert (v c2 = v a0 * v b0);
assert (v c2 <= 4096 * (max52 * max52));
let d6 = d5 +. mul64_wide a1 b4 +. mul64_wide a2 b3 +. mul64_wide a3 b2 +. mul64_wide a4 b1 in
lemma_add_four_mul64_wide 12802 d5 a1 a2 a3 a4 b1 b2 b3 b4;
assert (v d6 == v d5 + v a1 * v b4 + v a2 * v b3 + v a3 * v b2 + v a4 * v b1);
assert (v d6 <= 8705 * (max52 * max52));
let u0 = to_u64 d6 &. mask52 in
let d7 = d6 >>. 52ul in
lemma_bound_mask52_rsh52 8705 d6;
assert (v u0 = v d6 % pow2 52);
assert (felem_fits1 u0 1);
assert (v d7 = v d6 / pow2 52);
assert (v d7 <= 8705 * max52);
let u0' = tx |. (u0 <<. 4ul) in
lemma_tx_logor_u0_lsh4 tx u0;
assert (v u0' == v tx + v u0 * pow2 4);
assert (v u0' < pow2 56);
let c3 = c2 +. mul64_wide u0' (r >>. 4ul) in
lemma_bound_add_mul64_wide_r_rsh4 4096 c2 u0';
assert (v c3 = v c2 + v u0' * (v r / pow2 4));
assert (v c3 <= 4097 * (max52 * max52));
let r0 = to_u64 c3 &. mask52 in
let c4 = c3 >>. 52ul in
lemma_bound_mask52_rsh52 4097 c3;
assert (v r0 = v c3 % pow2 52);
assert (felem_fits1 r0 1);
assert (v c4 = v c3 / pow2 52);
assert (v c4 <= 4097 * max52);
let c5 = c4 +. mul64_wide a0 b1 +. mul64_wide a1 b0 in
lemma_add_two_mul64_wide52 4097 c4 a0 a1 b0 b1;
assert (v c5 = v c4 + v a0 * v b1 + v a1 * v b0);
assert (v c5 <= 8193 * (max52 * max52));
let d8 = d7 +. mul64_wide a2 b4 +. mul64_wide a3 b3 +. mul64_wide a4 b2 in
lemma_add_three_mul64_wide 8705 d7 a2 a3 a4 b2 b3 b4;
assert (v d8 = v d7 + v a2 * v b4 + v a3 * v b3 + v a4 * v b2);
assert (v d8 <= 4609 * (max52 * max52));
let c6 = c5 +. mul64_wide (to_u64 d8 &. mask52) r in
let d9 = d8 >>. 52ul in
lemma_bound_add_mul64_wide_r_mask52 8193 d8 c5;
assert (v d9 = v d8 / pow2 52);
assert (v d9 <= 8193 * max52);
assert (v c6 = v c5 + (v d8 % pow2 52) * v r);
assert (v c6 <= 8194 * (max52 * max52));
let r1 = to_u64 c6 &. mask52 in
let c7 = c6 >>. 52ul in
lemma_bound_mask52_rsh52 8194 c6;
assert (v r1 = v c6 % pow2 52);
assert (felem_fits1 r1 1);
assert (v c7 = v c6 / pow2 52);
assert (v c7 <= 8194 * max52);
let c8 = c7 +. mul64_wide a0 b2 +. mul64_wide a1 b1 +. mul64_wide a2 b0 in
lemma_add_three_mul64_wide52 8194 c7 a0 a1 a2 b0 b1 b2;
assert (v c8 == v c7 + v a0 * v b2 + v a1 * v b1 + v a2 * v b0);
assert (v c8 <= 12289 * (max52 * max52));
let d10 = d9 +. mul64_wide a3 b4 +. mul64_wide a4 b3 in
lemma_add_two_mul64_wide 8193 d9 a3 a4 b3 b4;
assert (v d10 == v d9 + v a3 * v b4 + v a4 * v b3);
assert (v d10 <= 513 * (max52 * max52));
let c9 = c8 +. mul64_wide r (to_u64 d10) in
let d11 = to_u64 (d10 >>. 64ul) in
lemma_bound_add_mul64_wide_r 12289 c8 d10;
assert (v c9 = v c8 + v r * (v d10 % pow2 64));
assert (v c9 <= 12290 * (max52 * max52));
lemma_bound_rsh64_to d10;
assert (v d11 = v d10 / pow2 64);
lemma_bound_d10 d10;
assert (v d11 < pow2 50);
let r2 = to_u64 c9 &. mask52 in
let c10 = c9 >>. 52ul in
lemma_bound_mask52_rsh52 12290 c9;
assert (v r2 = v c9 % pow2 52);
assert (felem_fits1 r2 1);
assert (v c10 = v c9 / pow2 52);
assert (v c10 <= 12290 * max52);
let c11 = c10 +. mul64_wide (r <<. 12ul) d11 +. to_u128 t3 in
lemma_bound_add_mul64_wide_r_lsh12_add 12290 c10 d11 t3;
assert (v c11 = v c10 + (v r * pow2 12) * v d11 + v t3);
assert (v c11 < pow2 100);
let r3 = to_u64 c11 &. mask52 in
let c12 = to_u64 (c11 >>. 52ul) in
lemma_bound_mask52_rsh52_sp c11;
assert (v r3 = v c11 % pow2 52);
assert (felem_fits1 r3 1);
assert (v c12 = v c11 / pow2 52);
assert (v c12 < pow2 48);
let r4 = c12 +. t4' in
lemma_mod_add_last c12 t4';
assert (v r4 = v c12 + v t4');
assert (felem_fits_last1 r4 2);
let res = (r0, r1, r2, r3, r4) in
assert (res == fmul5 a b);
assert (felem_fits5 res (1, 1, 1, 1, 2));
L4.lemma_fmul_simplify (v r0) (v r1) (v r2) (v r3) (v r4) (v c3) (v c6) (v c9) (v c11) (v d4) (v d8)
(v d10) (v d11) (v t3) (v a0) (v a1) (v a2) (v a3) (v a4) (v b0) (v b1) (v b2) (v b3) (v b4) | false |
Hacl.Impl.Chacha20Poly1305.PolyCore.fst | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded | val poly1305_padded: #w:field_spec -> poly1305_padded_st w | val poly1305_padded: #w:field_spec -> poly1305_padded_st w | let poly1305_padded #w ctx len text =
let h0 = ST.get () in
push_frame ();
let h1 = ST.get () in
Poly.reveal_ctx_inv ctx h0 h1;
let n = len /. 16ul in
let r = len %. 16ul in
let blocks = sub text 0ul (n *! 16ul) in
let rem = sub text (n *! 16ul) r in // the extra part of the input data
Poly.poly1305_update #w ctx (n *! 16ul) blocks;
let h2 = ST.get () in
let tmp = create 16ul (u8 0) in
update_sub tmp 0ul r rem;
let h3 = ST.get() in
Poly.reveal_ctx_inv ctx h2 h3;
if r >. 0ul then
Poly.poly1305_update1 ctx tmp;
let h4 = ST.get () in
pop_frame();
let h5 = ST.get () in
Poly.reveal_ctx_inv ctx h4 h5 | {
"file_name": "code/chacha20poly1305/Hacl.Impl.Chacha20Poly1305.PolyCore.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 59,
"start_col": 0,
"start_line": 39
} | module Hacl.Impl.Chacha20Poly1305.PolyCore
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20Poly1305
module Poly = Hacl.Impl.Poly1305
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 1 --record_options"
inline_for_extraction noextract
let poly1305_padded_st (w:field_spec) =
ctx:Poly.poly1305_ctx w
-> len:size_t
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ disjoint ctx text /\
Poly.state_inv_t h ctx)
(ensures fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\
Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx))
inline_for_extraction noextract
val poly1305_padded: #w:field_spec -> poly1305_padded_st w | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20Poly1305.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Poly1305",
"short_module": "Poly"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20Poly1305",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"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 | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st w | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Poly1305.Fields.field_spec",
"Hacl.Impl.Poly1305.poly1305_ctx",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.Poly1305.reveal_ctx_inv",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.op_Greater_Dot",
"Lib.IntTypes.U32",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Poly1305.poly1305_update1",
"Prims.bool",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Hacl.Impl.Poly1305.poly1305_update",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.PUB",
"Lib.Buffer.sub",
"Lib.IntTypes.mul",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let poly1305_padded #w ctx len text =
| let h0 = ST.get () in
push_frame ();
let h1 = ST.get () in
Poly.reveal_ctx_inv ctx h0 h1;
let n = len /. 16ul in
let r = len %. 16ul in
let blocks = sub text 0ul (n *! 16ul) in
let rem = sub text (n *! 16ul) r in
Poly.poly1305_update #w ctx (n *! 16ul) blocks;
let h2 = ST.get () in
let tmp = create 16ul (u8 0) in
update_sub tmp 0ul r rem;
let h3 = ST.get () in
Poly.reveal_ctx_inv ctx h2 h3;
if r >. 0ul then Poly.poly1305_update1 ctx tmp;
let h4 = ST.get () in
pop_frame ();
let h5 = ST.get () in
Poly.reveal_ctx_inv ctx h4 h5 | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_instr_leakage_free | val lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | val lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 668,
"start_col": 0,
"start_line": 615
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Instr? ins)
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Prims.unit",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.squash",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints",
"Vale.X64.Leakage_Ins.lemma_inouts_taint",
"Vale.X64.Instruction_s.instr_eval",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.havoc_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_s.Ins",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Prims.l_imp",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isLeakageFree"
] | [] | false | false | true | false | false | let lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) =
| let b, ts' = check_if_instr_consumes_fixed_time ins ts in
if b
then
(let code = Ins ins in
let lem (s1 s2: S.machine_state) (fuel: nat)
: Lemma (requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)] =
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = { s1 with S.ms_trace = [] } in
let s2 = { s2 with S.ms_trace = [] } in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> { s1 with S.ms_flags = S.havoc_flags }
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> { s2 with S.ms_flags = S.havoc_flags }
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> flags
in
let cf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> cf
in
let ovf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> ovf
in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret
then
(lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
())
else
(let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
())
in
()) | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.finalize_bounded_vlgen | val finalize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) | val finalize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) | let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 263,
"start_col": 0,
"start_line": 221
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sz32: FStar.UInt32.t ->
wk: LowParse.Low.Base.leaf_writer_strong ssk ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.UInt32.t",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.VLGen.finalize_bounded_vlgen_exact",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_pos_valid_exact",
"FStar.UInt32.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"FStar.UInt32.uint_to_t",
"FStar.UInt.uint_t",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen"
] | [] | false | true | false | false | false | let finalize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) =
| let h = HST.get () in
[@@ inline_let ]let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.jump_vlgen | val jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s)) | val jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s)) | let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
() | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 493,
"start_col": 0,
"start_line": 478
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
vk: LowParse.Low.Base.jumper pk ->
rk: LowParse.Low.Base.leaf_reader pk ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond vmin vmax k}
-> LowParse.Low.Base.jumper (LowParse.Spec.VLGen.parse_vlgen vmin vmax pk s) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Low.Base.jumper",
"LowParse.Low.Base.leaf_reader",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Low.Combinators.jump_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLGen.jump_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen",
"LowParse.Spec.VLGen.parse_vlgen"
] | [] | false | false | false | false | false | let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s)) =
| jump_synth (jump_bounded_vlgen vmin vmax vk rk s) (synth_vlgen (vmin) (vmax) s) () | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' | val gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)
) | val gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)
) | let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 522,
"start_col": 0,
"start_line": 495
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Base.consumed_length",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse_strong_prefix",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.seq",
"Prims.bool",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload"
] | [] | false | false | false | false | false | let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)
) =
| fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0)
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ =
match parse p input' with
| None -> ()
| Some _ -> parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_push_leakage_free | val lemma_push_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Push? ins)
(ensures
(let b, ts' = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | val lemma_push_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Push? ins)
(ensures
(let b, ts' = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | let lemma_push_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Push? ins)
(ensures (
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret then ()
else (
let aux () : Lemma (v1 == v2)
= match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux()
)
in
()
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 744,
"start_col": 0,
"start_line": 704
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Push? ins)
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Prims.unit",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.squash",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Prims.int",
"Vale.Def.Types_s.nat8",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.l_True",
"Prims.eq2",
"Vale.Def.Words_s.nat64",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Prims._assert",
"Vale.X64.Machine_Semantics_s.eval_operand",
"Prims.op_Subtraction",
"Vale.X64.Machine_Semantics_s.eval_reg_64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Leakage_Ins.machine_eval_code",
"Vale.X64.Leakage_Helpers.operand_taint",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_s.Ins",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time",
"Vale.X64.Bytes_Code_s.uu___is_Push",
"Prims.l_imp",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isLeakageFree"
] | [] | false | false | true | false | false | let lemma_push_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Push? ins)
(ensures
(let b, ts' = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) =
| let b, ts' = check_if_push_consumes_fixed_time ins ts in
if b
then
(let code = Ins ins in
let lem (s1 s2: S.machine_state) (fuel: nat)
: Lemma (requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)] =
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret
then ()
else
(let aux () : Lemma (v1 == v2) =
match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux ())
in
()) | false |
Vale.X64.Leakage_Ins.fst | Vale.X64.Leakage_Ins.lemma_pxor_leakage_free | val lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | val lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | let lemma_pxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 812,
"start_col": 0,
"start_line": 798
} | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
)
let lemma_push_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Push? ins)
(ensures (
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret then ()
else (
let aux () : Lemma (v1 == v2)
= match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux()
)
in
()
)
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_pop_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Pop? ins)
(ensures (
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
allow_inversion maddr;
allow_inversion tmaddr;
let BC.Pop dst t_stk = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let stack_op = OStack (MReg reg_Rsp 0, Public) in
let v1 = S.eval_operand stack_op s1 in
let v2 = S.eval_operand stack_op s2 in
if t_stk = Public then (
S.get_heap_val64_reveal ();
assert (v1 == v2)
);
Classical.forall_intro_3 (fun s x (stack1:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro_3 (fun s x (stack2:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
()
)
#reset-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 4 --max_fuel 4 --z3rlimit 40"
let lemma_xor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_xor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
FStar.Classical.forall_intro_with_pat (fun n -> Vale.Def.Types_s.ixor n n) Vale.Arch.Types.lemma_BitwiseXorCancel64
else
lemma_instr_leakage_free ts ins | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_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.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": 4,
"initial_ifuel": 2,
"max_fuel": 4,
"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": 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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Instr? ins /\ AnnotatePxor? (Instr?.annotation ins))
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.Arch.Types.lemma_quad32_xor",
"Prims.bool",
"Vale.X64.Leakage_Ins.lemma_instr_leakage_free",
"Prims.unit",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotatePxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Prims.squash",
"Prims.l_imp",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Vale.X64.Leakage_s.isLeakageFree",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) =
| let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2 then Vale.Arch.Types.lemma_quad32_xor () else lemma_instr_leakage_free ts ins | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_injective_2 | val gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) | val gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) | let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 91,
"end_line": 576,
"start_col": 0,
"start_line": 553
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
sl
sl' ==>
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
sl
sl' /\
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload'",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_injective_1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) =
| Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.valid_bounded_vlgen_elim | val valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | val valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2 | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 168,
"start_col": 0,
"start_line": 130
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLGen.parse_bounded_vlgen vmin vmax pk s)
h
input
pos)
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLGen.parse_bounded_vlgen vmin vmax pk s)
h
input
pos /\ LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid_exact p h input pos1 (FStar.UInt32.add pos1 len) /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
let x =
LowParse.Low.Base.Spec.contents_exact p h input pos1 (FStar.UInt32.add pos1 len)
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) == FStar.UInt32.v len /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLGen.parse_bounded_vlgen vmin
vmax
pk
s)
h
input
pos
x
(FStar.UInt32.add pos1 len)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"Prims.unit",
"LowParse.Low.FLData.valid_fldata_gen_elim",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.FLData.parse_fldata_kind",
"LowParse.Spec.FLData.parse_fldata",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.valid_exact",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel
#rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) =
| valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2 | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.accessor_bounded_vlgen_payload | val accessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s)) | val accessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s)) | let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 666,
"start_col": 0,
"start_line": 646
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
jk: LowParse.Low.Base.jumper pk ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.accessor (LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload min max pk s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold_aux",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | false | false | false | false | false | let accessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_vlgen_payload | val gaccessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (gaccessor (parse_vlgen min max pk s) p (clens_id _)) | val gaccessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (gaccessor (parse_vlgen min max pk s) p (clens_id _)) | let gaccessor_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_vlgen min max pk s) p (clens_id _))
= Classical.forall_intro_2 (gaccessor_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_vlgen min max pk s) p (clens_id _) (gaccessor_vlgen_payload' min max pk s);
gaccessor_vlgen_payload' min max pk s | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 814,
"start_col": 0,
"start_line": 801
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer
inline_for_extraction
let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos
let gaccessor_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (gaccessor' (parse_vlgen min max pk s) p (clens_id _))
= fun input ->
parse_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_injective (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s:
LowParse.Spec.Base.serializer p
{ LowParse.Spec.VLGen.parse_vlgen_precond min max k /\
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.VLGen.gaccessor_vlgen_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Low.Base.Spec.clens_id",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.VLGen.gaccessor_vlgen_payload_injective_2",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Base.no_lookahead_on_precond",
"LowParse.Low.VLGen.gaccessor_vlgen_payload_no_lookahead_2",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s:
serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (gaccessor (parse_vlgen min max pk s) p (clens_id _)) =
| Classical.forall_intro_2 (gaccessor_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_vlgen min max pk s)
p
(clens_id _)
(gaccessor_vlgen_payload' min max pk s);
gaccessor_vlgen_payload' min max pk s | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_no_lookahead_2 | val gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) | val gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) | let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 94,
"end_line": 626,
"start_col": 0,
"start_line": 605
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind sk k) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min
max
pk
s)
sl
sl' ==>
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Spec.Base.no_lookahead_on_precond",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload'",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_no_lookahead_1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl'))) =
| Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.valid_bounded_vlgen_elim' | val valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | val valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 62,
"end_line": 128,
"start_col": 0,
"start_line": 93
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLGen.parse_bounded_vlgen vmin vmax pk s)
h
input
pos)
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.VLGen.parse_bounded_vlgen vmin vmax pk s)
h
input
pos /\ LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid (LowParse.Spec.FLData.parse_fldata_strong s
(FStar.UInt32.v len))
h
input
pos1 /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
let x =
LowParse.Low.Base.Spec.contents (LowParse.Spec.FLData.parse_fldata_strong s
(FStar.UInt32.v len))
h
input
pos1
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) == FStar.UInt32.v len /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLGen.parse_bounded_vlgen vmin
vmax
pk
s)
h
input
pos
x
(FStar.UInt32.add pos1 len)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.unit",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold_aux",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.op_Addition",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.valid_content_pos",
"FStar.UInt32.add",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel
#rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma (requires (valid (parse_bounded_vlgen vmin vmax pk s) h input pos))
(ensures
(valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\ valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) =
| valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_vlgen_payload_no_lookahead_2 | val gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) | val gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) | let gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 86,
"end_line": 799,
"start_col": 0,
"start_line": 778
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer
inline_for_extraction
let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos
let gaccessor_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (gaccessor' (parse_vlgen min max pk s) p (clens_id _))
= fun input ->
parse_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_injective (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind sk k) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.VLGen.parse_vlgen min max pk s)
sl
sl' ==>
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Spec.Base.no_lookahead_on_precond",
"LowParse.Low.VLGen.gaccessor_vlgen_payload'",
"LowParse.Low.VLGen.gaccessor_vlgen_payload_no_lookahead_1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) =
| Classical.move_requires (gaccessor_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.finalize_vlgen_exact | val finalize_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) | val finalize_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) | let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 379,
"start_col": 0,
"start_line": 332
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sz32: FStar.UInt32.t ->
wk: LowParse.Low.Base.leaf_writer_strong ssk ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.UInt32.t",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.VLGen.valid_vlgen",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.Spec.contents_exact",
"FStar.UInt32.sub",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"FStar.UInt.uint_t",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.op_Subtraction",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen"
] | [] | false | true | false | false | false | let finalize_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) =
| [@@ inline_let ]let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@@ inline_let ]let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.validate_vlgen | val validate_vlgen
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k})
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s)) | val validate_vlgen
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k})
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s)) | let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
() | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 445,
"start_col": 0,
"start_line": 427
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
min: FStar.UInt32.t{FStar.UInt32.v min == vmin} ->
vmax: LowParse.Spec.DER.der_length_t ->
max: FStar.UInt32.t{FStar.UInt32.v max == vmax /\ FStar.UInt32.v min <= FStar.UInt32.v max} ->
vk: LowParse.Low.Base.validator pk ->
rk: LowParse.Low.Base.leaf_reader pk ->
s:
LowParse.Spec.Base.serializer p
{LowParse.Spec.VLGen.parse_vlgen_precond (FStar.UInt32.v min) (FStar.UInt32.v max) k} ->
v: LowParse.Low.Base.validator p
-> LowParse.Low.Base.validator (LowParse.Spec.VLGen.parse_vlgen vmin vmax pk s) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_max",
"FStar.UInt32.v",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Low.Base.validator",
"LowParse.Low.Base.leaf_reader",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Low.Combinators.validate_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLGen.validate_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen",
"LowParse.Spec.VLGen.parse_vlgen"
] | [] | false | false | false | false | false | let validate_vlgen
(vmin: der_length_t)
(min: U32.t{U32.v min == vmin})
(vmax: der_length_t)
(max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k})
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s)) =
| validate_synth (validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
() | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload | val gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)) | val gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)) | let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 641,
"start_col": 0,
"start_line": 628
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_injective_2",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Base.no_lookahead_on_precond",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_no_lookahead_2",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | false | false | false | false | false | let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot
(gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s)) =
| Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
(gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.valid_vlgen | val valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len))) | val valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len))) | let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 329,
"start_col": 0,
"start_line": 295
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond vmin vmax k} ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid_exact p h input pos1 (FStar.UInt32.add pos1 len)))
(ensures
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
let x =
LowParse.Low.Base.Spec.contents_exact p h input pos1 (FStar.UInt32.add pos1 len)
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) == FStar.UInt32.v len /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLGen.parse_vlgen vmin vmax pk s)
h
input
pos
x
(FStar.UInt32.add pos1 len))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Combinators.valid_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen",
"Prims.unit",
"LowParse.Low.VLGen.valid_bounded_vlgen",
"LowParse.Low.Base.Spec.valid",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.valid_exact",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Low.Base.Spec.contents_exact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (vmin) (vmax) k})
#rrel
#rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len))) =
| valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth h (parse_bounded_vlgen vmin vmax pk s) (synth_vlgen (vmin) (vmax) s) input pos | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.valid_bounded_vlgen | val valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | val valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2 | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 91,
"start_col": 0,
"start_line": 51
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid_exact p h input pos1 (FStar.UInt32.add pos1 len)))
(ensures
LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid_exact p h input pos1 (FStar.UInt32.add pos1 len) /\
(let x =
LowParse.Low.Base.Spec.contents_exact p h input pos1 (FStar.UInt32.add pos1 len)
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) == FStar.UInt32.v len /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLGen.parse_bounded_vlgen vmin
vmax
pk
s)
h
input
pos
x
(FStar.UInt32.add pos1 len)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"Prims.unit",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.FLData.valid_fldata_gen",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.contents_exact",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.Base.Spec.valid",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.valid_exact",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.valid_content_pos",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel
#rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len)))
)
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\ valid_exact p h input pos1 (pos1 `U32.add` len) /\
(let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) =
| valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2 | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.valid_bounded_vlgen' | val valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1)))
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | val valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1)))
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) | let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 62,
"end_line": 49,
"start_col": 0,
"start_line": 14
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
FStar.UInt32.v pos1 + FStar.UInt32.v len < 4294967296 /\
LowParse.Low.Base.Spec.valid (LowParse.Spec.FLData.parse_fldata_strong s
(FStar.UInt32.v len))
h
input
pos1))
(ensures
LowParse.Low.Base.Spec.valid pk h input pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in
let len = LowParse.Low.Base.Spec.contents pk h input pos in
LowParse.Low.Base.Spec.valid (LowParse.Spec.FLData.parse_fldata_strong s
(FStar.UInt32.v len))
h
input
pos1 /\
(let x =
LowParse.Low.Base.Spec.contents (LowParse.Spec.FLData.parse_fldata_strong s
(FStar.UInt32.v len))
h
input
pos1
in
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) == FStar.UInt32.v len /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.VLGen.parse_bounded_vlgen vmin
vmax
pk
s)
h
input
pos
x
(FStar.UInt32.add pos1 len)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.unit",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold_aux",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Low.Base.Spec.valid",
"Prims.op_Addition",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.valid_content_pos",
"FStar.UInt32.add",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel
#rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1)))
(ensures
(valid pk h input pos /\
(let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\
(let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s)
h
input
pos
x
(pos1 `U32.add` len))))) =
| valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1 | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_no_lookahead_1 | val gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) | val gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) | let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 603,
"start_col": 0,
"start_line": 578
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind sk k) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min
max
pk
s)
sl
sl')
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) =
| parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl';
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl';
parse_injective pk sl sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.finalize_vlgen | val finalize_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) | val finalize_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) | let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 424,
"start_col": 0,
"start_line": 382
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sz32: FStar.UInt32.t ->
wk: LowParse.Low.Base.leaf_writer_strong ssk ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.UInt32.t",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.VLGen.finalize_vlgen_exact",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_pos_valid_exact",
"FStar.UInt32.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt32.sub",
"FStar.UInt32.uint_to_t",
"FStar.UInt.uint_t",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen"
] | [] | false | true | false | false | false | let finalize_vlgen
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond (min) (max) k})
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` (U32.uint_to_t sz) in
valid_pos p h input pos_payload pos' /\ k.parser_kind_subkind == Some ParserStrong /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos')) =
| let h = HST.get () in
[@@ inline_let ]let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_vlgen_payload_injective_2 | val gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) | val gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) | let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 83,
"end_line": 749,
"start_col": 0,
"start_line": 726
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer
inline_for_extraction
let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos
let gaccessor_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (gaccessor' (parse_vlgen min max pk s) p (clens_id _))
= fun input ->
parse_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_injective (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_vlgen min max pk s) sl sl' ==>
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_vlgen min max pk s) sl sl' /\
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Bytes.bytes",
"FStar.Classical.move_requires",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.VLGen.gaccessor_vlgen_payload'",
"LowParse.Low.VLGen.gaccessor_vlgen_payload_injective_1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(ensures
((k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl') ==>
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'))) =
| Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl' | false |
C.String.fst | C.String.v | val v (s: t) : GTot (s:Seq.seq C.char{well_formed s}) | val v (s: t) : GTot (s:Seq.seq C.char{well_formed s}) | let v s = s.s | {
"file_name": "krmllib/C.String.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 13,
"end_line": 14,
"start_col": 0,
"start_line": 14
} | module C.String
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module B = LowStar.Buffer
module M = LowStar.Modifies
open FStar.HyperStack.ST
[@@ no_auto_projectors]
type t = | S: s:Seq.seq C.char { well_formed s } -> t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"C.fst.checked"
],
"interface_file": true,
"source_file": "C.String.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "C",
"short_module": null
},
{
"abbrev": false,
"full_module": "C",
"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 | s: C.String.t -> Prims.GTot (s: FStar.Seq.Base.seq C.char {C.String.well_formed s}) | Prims.GTot | [
"sometrivial"
] | [] | [
"C.String.t",
"C.String.__proj__S__item__s",
"FStar.Seq.Base.seq",
"C.char",
"C.String.well_formed"
] | [] | false | false | false | false | false | let v s =
| s.s | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.finalize_bounded_vlgen_exact | val finalize_bounded_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) | val finalize_bounded_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) | let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 218,
"start_col": 0,
"start_line": 171
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sz32: FStar.UInt32.t ->
wk: LowParse.Low.Base.leaf_writer_strong ssk ->
s: LowParse.Spec.Base.serializer p ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.UInt32.t",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.VLGen.valid_bounded_vlgen",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.Spec.contents_exact",
"FStar.UInt32.sub",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"FStar.UInt.uint_t",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Slice.loc_slice_from_to",
"Prims.op_Subtraction",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_pred",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen"
] | [] | false | true | false | false | false | let finalize_bounded_vlgen_exact
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires
(fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\ sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\
(let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\
(let len_payload = pos' `U32.sub` pos_payload in
let len_ser =
Seq.length (serialize s (contents_exact p h input pos_payload pos'))
in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/
(min <= len_ser /\ len_ser <= max))))))
(ensures
(fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos')) =
| [@@ inline_let ]let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@@ inline_let ]let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_vlgen_payload_no_lookahead_1 | val gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl')) | val gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl')) | let gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 776,
"start_col": 0,
"start_line": 751
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer
inline_for_extraction
let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos
let gaccessor_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (gaccessor' (parse_vlgen min max pk s) p (clens_id _))
= fun input ->
parse_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_injective (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind sk k) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_vlgen min max pk s)
p
(LowParse.Low.Base.Spec.clens_id t)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.VLGen.parse_vlgen min max pk s)
sl
sl')
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Spec.VLGen.parse_vlgen_unfold",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"LowParse.Low.VLGen.gaccessor_vlgen_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl')) =
| parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl';
parse_strong_prefix (parse_vlgen min max pk s) sl sl';
parse_injective pk sl sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload_injective_1 | val gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) | val gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) | let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl' | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 551,
"start_col": 0,
"start_line": 524
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
sl
sl')
(ensures
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
p
(LowParse.Low.VLData.clens_bounded_vldata_strong_payload min max s)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s)
sl
sl' /\
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl ==
LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload' min max pk s sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.VLData.clens_bounded_vldata_strong_payload",
"LowParse.Spec.Base.injective_precond",
"Prims.squash",
"LowParse.Low.VLGen.gaccessor_bounded_vlgen_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (min) (max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl': bytes)
: Lemma
(requires
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl'))
(ensures
(k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s)
p
(clens_bounded_vldata_strong_payload min max s)
sl' /\ injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl ==
gaccessor_bounded_vlgen_payload' min max pk s sl')) =
| parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl';
parse_injective (parse_bounded_vlgen min max pk s) sl sl';
parse_injective pk sl sl' | false |
LowParse.Low.VLGen.fst | LowParse.Low.VLGen.accessor_vlgen_payload | val accessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (accessor (gaccessor_vlgen_payload min max pk s)) | val accessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (accessor (gaccessor_vlgen_payload min max pk s)) | let accessor_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (accessor (gaccessor_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_vlgen_payload min max pk s) input pos;
valid_facts (parse_vlgen min max pk s) h input pos;
parse_vlgen_unfold min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos | {
"file_name": "src/lowparse/LowParse.Low.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 837,
"start_col": 0,
"start_line": 817
} | module LowParse.Low.VLGen
include LowParse.Spec.VLGen
include LowParse.Low.VLData
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false"
let valid_bounded_vlgen'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
let x = contents_exact p h input pos1 pos2 in
valid_fldata_gen p (U32.v len) input pos1 h;
serialized_length_eq s x;
valid_exact_serialize s h input pos1 pos2
let valid_bounded_vlgen_elim'
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid (parse_fldata_strong s (U32.v len)) h input pos1 /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents (parse_fldata_strong s (U32.v len)) h input pos1 in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold_aux (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
valid_facts (parse_fldata_strong s (U32.v len)) h input pos1
let valid_bounded_vlgen_elim
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos
))
(ensures (
valid (parse_bounded_vlgen vmin vmax pk s) h input pos /\
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len) /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_bounded_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))))
= valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos;
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let pos2 = pos1 `U32.add` len in
valid_facts (parse_fldata p (U32.v len)) h input pos1;
valid_fldata_gen_elim p (U32.v len) input pos1 h;
valid_exact_serialize s h input pos1 pos2
inline_for_extraction
let finalize_bounded_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_bounded_vlgen min max pk s input pos h
inline_for_extraction
let finalize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_bounded_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_bounded_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_bounded_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(v: validator p)
: Tot (validator (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.move_requires (valid_bounded_vlgen' vmin vmax pk s input (uint64_to_uint32 pos)) h;
Classical.move_requires (valid_bounded_vlgen_elim' vmin vmax pk s input (uint64_to_uint32 pos)) h
in
let n = vk input pos in
if is_error n
then n
else begin
let len = rk input (uint64_to_uint32 pos) in
validate_fldata_strong s v (U32.v len) len input n
end
let valid_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 (vmin) (vmax)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
(h: HS.mem)
: Lemma
(requires (
valid pk h input pos /\ (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
U32.v pos1 + U32.v len < 4294967296 /\
valid_exact p h input pos1 (pos1 `U32.add` len)
)))
(ensures (
let pos1 = get_valid_pos pk h input pos in
let len = contents pk h input pos in
let x = contents_exact p h input pos1 (pos1 `U32.add` len) in
Seq.length (serialize s x) == U32.v len /\
valid_content_pos (parse_vlgen vmin vmax pk s) h input pos x (pos1 `U32.add` len)
))
= valid_bounded_vlgen vmin vmax pk s input pos h;
valid_synth
h
(parse_bounded_vlgen vmin vmax pk s)
(synth_vlgen (vmin) (vmax) s)
input
pos
inline_for_extraction
let finalize_vlgen_exact
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` sz32 in
valid_exact p h input pos_payload pos' /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents_exact p h input pos_payload pos')) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let sz = U32.v sz32 in
let x = contents_exact p h input (pos `U32.add` sz32) pos' in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
Seq.length (serialize s x) == U32.v pos' - (U32.v pos + sz) /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= [@inline_let]
let len_payload = pos' `U32.sub` (pos `U32.add` sz32) in
let h = HST.get () in
[@inline_let]
let _ =
serialized_length_eq s (contents_exact p h input (pos `U32.add` sz32) pos');
valid_exact_serialize s h input (pos `U32.add` sz32) pos'
in
let _ = wk len_payload input pos in
let h = HST.get () in
valid_vlgen min max pk s input pos h
inline_for_extraction
let finalize_vlgen
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(sz32: U32.t)
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(#ssk: serializer pk)
(wk: leaf_writer_strong ssk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (min) (max) k })
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
let sz = U32.v sz32 in
sk.parser_kind_low == sz /\
sk.parser_kind_high == Some sz /\
U32.v pos + sz <= U32.v input.len /\ (
let pos_payload = pos `U32.add` U32.uint_to_t sz in
valid_pos p h input pos_payload pos' /\
k.parser_kind_subkind == Some ParserStrong /\ (
let len_payload = pos' `U32.sub` pos_payload in
let len_ser = Seq.length (serialize s (contents p h input pos_payload)) in
writable input.base (U32.v pos) (U32.v pos + sz) h /\
((min <= U32.v len_payload /\ U32.v len_payload <= max) \/ (min <= len_ser /\ len_ser <= max))
))))
(ensures (fun h _ h' ->
let x = contents p h input (pos `U32.add` sz32) in
B.modifies (loc_slice_from_to input pos (pos `U32.add` sz32)) h h' /\
parse_bounded_vldata_strong_pred min max s x /\
valid_content_pos (parse_vlgen min max pk s) h' input pos x pos'
))
= let h = HST.get () in
[@inline_let]
let _ =
let pos_payload = pos `U32.add` sz32 in
valid_pos_valid_exact p h input pos_payload pos'
in
finalize_vlgen_exact min max sz32 wk s input pos pos'
inline_for_extraction
let validate_vlgen
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: validator pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k })
(v: validator p)
: Tot (validator (parse_vlgen (vmin) (vmax) pk s))
= validate_synth
(validate_bounded_vlgen vmin min vmax max vk rk s v)
(synth_vlgen (U32.v min) (U32.v max) s)
()
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_bounded_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (jumper (parse_bounded_vlgen (vmin) (vmax) pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_bounded_vlgen (vmin) (vmax) pk s) h input pos;
parse_bounded_vlgen_unfold (vmin) (vmax) pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
let n = vk input pos in
let len = rk input pos in
[@inline_let]
let _ = valid_facts (parse_fldata_strong s (U32.v len)) h input n in
jump_fldata_strong s (U32.v len) len input n
#pop-options
inline_for_extraction
let jump_vlgen
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (vmin) (vmax)))
(vk: jumper pk)
(rk: leaf_reader pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond (vmin) (vmax) k })
: Tot (jumper (parse_vlgen (vmin) (vmax) pk s))
= jump_synth
(jump_bounded_vlgen vmin vmax vk rk s)
(synth_vlgen (vmin) (vmax) s)
()
let gaccessor_bounded_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor' (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= fun input ->
parse_bounded_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_bounded_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_injective (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
injective_precond (parse_bounded_vlgen min max pk s) sl sl' /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
))
= parse_bounded_vlgen_unfold min max pk s sl;
parse_bounded_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_bounded_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_bounded_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl /\
gaccessor_pre (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) sl' /\
no_lookahead_on_precond (parse_bounded_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_bounded_vlgen_payload' min max pk s sl == gaccessor_bounded_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_bounded_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s))
= Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_bounded_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_bounded_vlgen min max pk s) p (clens_bounded_vldata_strong_payload min max s) (gaccessor_bounded_vlgen_payload' min max pk s);
gaccessor_bounded_vlgen_payload' min max pk s
module B = LowStar.Buffer
inline_for_extraction
let accessor_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 ( min) ( max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
: Tot (accessor (gaccessor_bounded_vlgen_payload min max pk s))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_bounded_vlgen_payload min max pk s) input pos;
valid_facts (parse_bounded_vlgen min max pk s) h input pos;
parse_bounded_vlgen_unfold_aux min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos
let gaccessor_vlgen_payload'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong } )
: Tot (gaccessor' (parse_vlgen min max pk s) p (clens_id _))
= fun input ->
parse_vlgen_unfold min max pk s input;
let res =
match parse pk input with
| None -> (0) // dummy
| Some (len, sz) ->
if sz + U32.v len <= Seq.length input
then
let input' = Seq.slice input sz (sz + U32.v len) in
let _ = match parse p input' with
| None -> ()
| Some _ ->
parse_strong_prefix p input' (Seq.slice input sz (Seq.length input))
in
sz
else 0
in
res
let gaccessor_vlgen_payload_injective_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_injective (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_injective_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
injective_precond (parse_vlgen min max pk s) sl sl' /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_injective_1 min max pk s sl) sl'
let gaccessor_vlgen_payload_no_lookahead_1
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(requires (
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
))
(ensures (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
))
= parse_vlgen_unfold min max pk s sl;
parse_vlgen_unfold min max pk s sl' ;
parse_strong_prefix (parse_vlgen min max pk s) sl sl' ;
parse_injective pk sl sl'
let gaccessor_vlgen_payload_no_lookahead_2
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(sl sl' : bytes)
: Lemma
(ensures ((
k.parser_kind_subkind == Some ParserStrong /\
(and_then_kind sk k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl /\
gaccessor_pre (parse_vlgen min max pk s) p (clens_id _) sl' /\
no_lookahead_on_precond (parse_vlgen min max pk s) sl sl'
) ==> (
k.parser_kind_subkind == Some ParserStrong /\
gaccessor_vlgen_payload' min max pk s sl == gaccessor_vlgen_payload' min max pk s sl'
)))
= Classical.move_requires (gaccessor_vlgen_payload_no_lookahead_1 min max pk s sl) sl'
let gaccessor_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 ( min) ( max)))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong})
: Tot (gaccessor (parse_vlgen min max pk s) p (clens_id _))
= Classical.forall_intro_2 (gaccessor_vlgen_payload_no_lookahead_2 min max pk s);
Classical.forall_intro_2 (gaccessor_vlgen_payload_injective_2 min max pk s);
gaccessor_prop_equiv (parse_vlgen min max pk s) p (clens_id _) (gaccessor_vlgen_payload' min max pk s);
gaccessor_vlgen_payload' min max pk s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLGen",
"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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
jk: LowParse.Low.Base.jumper pk ->
s:
LowParse.Spec.Base.serializer p
{ LowParse.Spec.VLGen.parse_vlgen_precond min max k /\
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Low.Base.accessor (LowParse.Low.VLGen.gaccessor_vlgen_payload min max pk s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.VLGen.parse_vlgen_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_vlgen",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Low.Base.Spec.clens_id",
"LowParse.Low.VLGen.gaccessor_vlgen_payload",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | false | false | false | false | false | let accessor_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 (min) (max)))
(jk: jumper pk)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s:
serializer p {parse_vlgen_precond min max k /\ k.parser_kind_subkind == Some ParserStrong}
)
: Tot (accessor (gaccessor_vlgen_payload min max pk s)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_vlgen_payload min max pk s) input pos;
valid_facts (parse_vlgen min max pk s) h input pos;
parse_vlgen_unfold min max pk s (bytes_of_slice_from h input pos);
valid_facts pk h input pos
in
jk input pos | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.